Use the official Go client libraries for Pinecone, Weaviate, or Milvus to connect, index vectors, and query them. For Weaviate, initialize the client with your endpoint and API key, then use the Batch object to add documents and the Query object to search by vector similarity.
package main
import (
"context"
"log"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/filters"
"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)
func main() {
ctx := context.Background()
client, err := weaviate.New(weaviate.Config{
Scheme: "http",
Host: "localhost:8080",
})
if err != nil {
log.Fatal(err)
}
// Add a document
err = client.Batch().ObjectBatcher().WithObject(
&weaviate.Object{
Class: "Document",
Properties: map[string]any{
"content": "Go is a programming language.",
},
},
).Do(ctx)
if err != nil {
log.Fatal(err)
}
// Query by vector similarity
res, err := client.GraphQL().Get().WithClassName("Document").
WithNearVector(&graphql.NearVector{
Vector: []float32{0.1, 0.2, 0.3},
Certainty: 0.7,
}).
WithFields("content").
Do(ctx)
if err != nil {
log.Fatal(err)
}
log.Printf("Results: %v", res)
}