qdrant / go-client

Go client for Qdrant vector search engine
Apache License 2.0
159 stars 15 forks source link

list collection err #25

Closed pomnb closed 1 year ago

pomnb commented 1 year ago

i meet this err when list collection : connection closed before server preface received , use go-client@v1.2.0 grpc v1.47.0 protobuf v1.28.0 below is the code


addr := "xxxxxx:6334"
    conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        log.Fatalf("did not connect: %v", err)
    }
    fmt.Println("conn:", conn)
    fmt.Println("err:", 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*10)
    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())`
Rendez commented 1 year ago

Anything but a locally running instance of Qdrant uses TLS, so you can't use an insecure channel, and you also need to provide your api-key as metadata in gRPC requests:

grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
md := metadata.New(map[string]string{"api-key": "secret-key-*******"})
ctx = metadata.NewOutgoingContext(ctx, md)

Check out the "authenticated" example in this repo: https://github.com/qdrant/go-client/blob/master/examples/authentication/main.go