File tree Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM golang:1.22-alpine
2
+
3
+ # Set working directory
4
+ WORKDIR /app
5
+
6
+ # Copy go mod files
7
+ COPY go.mod go.sum ./
8
+
9
+ # Download dependencies
10
+ RUN go mod download
11
+
12
+ # Copy source code
13
+ COPY main.go ./
14
+
15
+ # Build and run the application
16
+ CMD ["go" , "run" , "main.go" ]
Original file line number Diff line number Diff line change
1
+ # Simple Qdrant Client Example
2
+
3
+ This is a simple example application that demonstrates how to create a Go application that could interact with a Qdrant vector database server.
4
+
5
+ ## Prerequisites
6
+
7
+ - Docker installed on your system
8
+
9
+ ## Quick Start
10
+
11
+ ### 1. Start Qdrant
12
+
13
+ First, make sure Qdrant is running. You can start it with Docker:
14
+
15
+ ``` bash
16
+ docker run --rm -it -p 6334:6334 -p 6333:6333 qdrant/qdrant
17
+ ```
18
+
19
+ ### 2. Building and Running
20
+
21
+ ``` bash
22
+ bash -x build-and-run.sh
23
+ ```
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ docker build -t qdrant-simple-example .
4
+
5
+ docker run --rm -it --network host qdrant-simple-example
6
+
Original file line number Diff line number Diff line change
1
+ module simple-example
2
+
3
+ go 1.22.2
4
+
5
+ require github.com/qdrant/go-client v1.15.2
6
+
7
+ require (
8
+ golang.org/x/net v0.28.0 // indirect
9
+ golang.org/x/sys v0.28.0 // indirect
10
+ golang.org/x/text v0.21.0 // indirect
11
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
12
+ google.golang.org/grpc v1.66.0 // indirect
13
+ google.golang.org/protobuf v1.34.2 // indirect
14
+ )
Original file line number Diff line number Diff line change
1
+ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI =
2
+ github.com/google/go-cmp v0.6.0 /go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY =
3
+ github.com/qdrant/go-client v1.15.2 h1:3NSyxpHrfQTP6JLDAwqNUShz6V9tuRBKz0G7hSOxrac =
4
+ github.com/qdrant/go-client v1.15.2 /go.mod h1:iO8ts78jL4x6LDHFOViyYWELVtIBDTjOykBmiOTHLnQ =
5
+ golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE =
6
+ golang.org/x/net v0.28.0 /go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg =
7
+ golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA =
8
+ golang.org/x/sys v0.28.0 /go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA =
9
+ golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo =
10
+ golang.org/x/text v0.21.0 /go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ =
11
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg =
12
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed /go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU =
13
+ google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c =
14
+ google.golang.org/grpc v1.66.0 /go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y =
15
+ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg =
16
+ google.golang.org/protobuf v1.34.2 /go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw =
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "log"
6
+
7
+ "github.com/qdrant/go-client/qdrant"
8
+ )
9
+
10
+ const (
11
+ collectionName = "test_collection"
12
+ )
13
+
14
+ func main () {
15
+ // Create context
16
+ ctx := context .Background ()
17
+
18
+ // Create new client
19
+ client , err := qdrant .NewClient (& qdrant.Config {
20
+ Host : "localhost" , // Can be omitted, default is "localhost"
21
+ Port : 6334 , // Can be omitted, default is 6334
22
+ // APIKey: "<API_KEY>",
23
+ // UseTLS: true,
24
+ // TLSConfig: &tls.Config{},
25
+ // GrpcOptions: []grpc.DialOption{},
26
+ })
27
+ if err != nil {
28
+ log .Fatalf ("Failed to create client: %v" , err )
29
+ }
30
+ defer client .Close ()
31
+
32
+ err = client .CreateCollection (ctx , & qdrant.CreateCollection {
33
+ CollectionName : collectionName ,
34
+ VectorsConfig : qdrant .NewVectorsConfig (& qdrant.VectorParams {
35
+ Size : uint64 (128 ),
36
+ Distance : qdrant .Distance_Cosine ,
37
+ }),
38
+ })
39
+
40
+ if err != nil {
41
+ log .Printf ("Could not create collection: %v" , err )
42
+ return
43
+ }
44
+
45
+ collections , err := client .ListCollections (ctx )
46
+ if err != nil {
47
+ log .Printf ("Could not list collections: %v" , err )
48
+ return
49
+ }
50
+ log .Printf ("List of collections: %+v" , collections )
51
+ }
You can’t perform that action at this time.
0 commit comments