https://github.com/qdrant/go-client
Go client for Qdrant vector search engine
https://github.com/qdrant/go-client
Last synced: 4 days ago
JSON representation
Go client for Qdrant vector search engine
- Host: GitHub
- URL: https://github.com/qdrant/go-client
- Owner: qdrant
- License: apache-2.0
- Created: 2022-06-24T07:19:39.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2025-04-09T10:17:17.000Z (about 1 year ago)
- Last Synced: 2025-04-09T11:25:52.381Z (about 1 year ago)
- Language: Go
- Size: 980 KB
- Stars: 207
- Watchers: 3
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
Go client for the Qdrant vector search engine.
Go client library with handy utilities for interfacing with [Qdrant](https://qdrant.tech/).
## 📥 Installation
```bash
go get -u github.com/qdrant/go-client
```
## 📖 Documentation
- Usage examples are available throughout the [Qdrant documentation](https://qdrant.tech/documentation/quick-start/) and [API Reference](https://api.qdrant.tech/).
- [Godoc Reference](https://pkg.go.dev/github.com/qdrant/go-client)
## 🔌 Getting started
### Creating a client
A client can be instantiated with
```go
import "github.com/qdrant/go-client/qdrant"
client, err := qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
})
```
Which creates a client that will connect to Qdrant on .
Internally, the high-level client uses a low-level gRPC client to interact with
Qdrant. `qdrant.Config` provides additional options to control how the gRPC
client is configured. The following example configures API key authentication with TLS:
```go
import "github.com/qdrant/go-client/qdrant"
client, err := qdrant.NewClient(&qdrant.Config{
Host: "xyz-example.eu-central.aws.cloud.qdrant.io",
Port: 6334,
APIKey: "",
UseTLS: true, // uses default config with minimum TLS version set to 1.3
// PoolSize: 3,
// KeepAliveTime: 10,
// KeepAliveTimeout: 2,
// TLSConfig: &tls.Config{...},
// GrpcOptions: []grpc.DialOption{},
})
```
### Working with collections
Once a client has been created, create a new collection
```go
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "{collection_name}",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
```
Insert vectors into the collection
```go
operationInfo, err := client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "{collection_name}",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.05, 0.61, 0.76, 0.74),
Payload: qdrant.NewValueMap(map[string]any{"city": "London"}),
},
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.19, 0.81, 0.75, 0.11),
Payload: qdrant.NewValueMap(map[string]any{"age": 32}),
},
{
Id: qdrant.NewIDNum(3),
Vectors: qdrant.NewVectors(0.36, 0.55, 0.47, 0.94),
Payload: qdrant.NewValueMap(map[string]any{"vegan": true}),
},
},
})
```
Search for similar vectors
```go
searchResult, err := client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "{collection_name}",
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
})
```
Search for similar vectors with a filtering condition
```go
searchResult, err := client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "{collection_name}",
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
Filter: &qdrant.Filter{
Must: []*qdrant.Condition{
qdrant.NewMatch("city", "London"),
},
},
WithPayload: qdrant.NewWithPayload(true),
})
```
## ⚖️ LICENSE
[Apache 2.0](https://github.com/qdrant/go-client/blob/master/LICENSE)