Skip to content

Commit

Permalink
new-client
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Sep 1, 2024
1 parent 6fb15a4 commit cdd9e46
Show file tree
Hide file tree
Showing 38 changed files with 4,940 additions and 2,662 deletions.
347 changes: 347 additions & 0 deletions .golangci.yml

Large diffs are not rendered by default.

76 changes: 2 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
# Golang Qdrant client
# Qdrant-Go V2

Go client for Qdrant vector search engine

## Install

```bash
go get github.com/qdrant/go-client
```

## Usage

Run Qdrant with enabled gRPC interface:

```bash
# With env variable
docker run -p 6333:6333 -p 6334:6334 \
-e QDRANT__SERVICE__GRPC_PORT="6334" \
qdrant/qdrant
```

Or by updating the configuration file:

```yaml
service:
grpc_port: 6334
```
More info about gRPC in [documentation](https://qdrant.tech/documentation/quick-start/#grpc).
### Making requests
```go
package main

import (
"context"
"flag"
"log"
"time"

pb "github.com/qdrant/go-client/qdrant"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

var (
addr = flag.String("addr", "localhost:6334", "the address to connect to")
)

func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

collections_client := pb.NewCollectionsClient(conn)

// Contact the server and print out its response.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := collections_client.List(ctx, &pb.ListCollectionsRequest{})
if err != nil {
log.Fatalf("could not get collections: %v", err)
}
log.Printf("List of collections: %s", r.GetCollections())
}
```

> For authenticated request (using API KEY and TLS) to Qdrant Cloud, please refer to the [authenticated](https://github.com/qdrant/go-client/tree/master/examples/authentication/main.go) example.
A full example for uploading, searching and filtering can be found in the [`examples`](https://github.com/qdrant/go-client/tree/master/examples) directory.
TODO
46 changes: 15 additions & 31 deletions examples/authentication/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,29 @@ package main

import (
"context"
"crypto/tls"
"flag"
"log"
"time"

"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"

pb "github.com/qdrant/go-client/qdrant"
"google.golang.org/grpc"
)

var (
addr = flag.String("addr", "secure.cloud.qdrant.io:6334", "the address to connect to")
"github.com/qdrant/go-client-v2/qdrant"
)

func main() {
flag.Parse()
// Set up a connection to the server.
config := &tls.Config{}
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(credentials.NewTLS(config)), grpc.WithUnaryInterceptor(interceptor))
// Create new client
client, err := qdrant.NewClient(&qdrant.Config{
Host: "xyz-example.eu-central.aws.cloud.qdrant.io",
Port: 6334,
APIKey: "<paste-your-api-key-here>",
UseTLS: true,
// TLSConfig: &tls.Config{...},
// GrpcOptions: []grpc.DialOption{},
})
if err != nil {
log.Fatalf("did not connect: %v", err)
log.Fatalf("could not instantiate: %v", err)
}
defer conn.Close()

collections_client := pb.NewCollectionsClient(conn)

// Contact the server and print out its response.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := collections_client.List(ctx, &pb.ListCollectionsRequest{})
defer client.Close()
// List collections
collections, err := client.ListCollections(context.Background())
if err != nil {
log.Fatalf("could not get collections: %v", err)
}
log.Printf("List of collections: %s", r.GetCollections())
}

func interceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
newCtx := metadata.AppendToOutgoingContext(ctx, "api-key", "secret-key-*******")
return invoker(newCtx, method, req, reply, cc, opts...)
log.Printf("List of collections: %v", collections)
}
Loading

0 comments on commit cdd9e46

Please sign in to comment.