Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: New Client Implementation #52

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Go CI
name: Go Tests

on:
push:
branches: [ master, dev ]
branches:
- master
pull_request:
branches: [ '**' ]

jobs:
build:
Expand All @@ -19,6 +19,9 @@ jobs:
with:
go-version-file: ./go.mod

- name: Get
run: go get ./...

- name: Build
run: go build ./...

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: golangci-lint
on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
340 changes: 340 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
Anush008 marked this conversation as resolved.
Show resolved Hide resolved
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/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