A Go client library for VectorX, a high-performance vector database optimized for similarity search and retrieval-augmented generation (RAG) applications.
- 🚀 High Performance: Optimized for large-scale vector operations
- 🔍 Multiple Distance Metrics: Support for cosine, L2, and inner product similarity
- 📊 High Dimensionality: Support for vectors up to 10,000 dimensions
- 🏷️ Metadata & Filtering: Rich metadata support with JSON-based filtering
- 🔒 Security Ready: Built-in support for encryption (coming soon)
- ⚡ Batch Operations: Efficient batch upsert of up to 1,000 vectors
- 🎯 Precision Control: FP16 and FP32 precision support
- 🌐 Cloud & Local: Support for both VectorX Cloud and self-hosted instances
go get github.com/LaunchX-Labs/vecx-gopackage main
import (
"fmt"
"log"
"github.com/LaunchX-Labs/vecx-go"
)
func main() {
// Initialize client with your VectorX token
client := vecx.NewVectorX("your-token-here")
// Create a new index
err := client.CreateIndex("my-index", 768, "cosine", 16, 128, false, nil)
if err != nil {
log.Fatal(err)
}
// Get the index for operations
index, err := client.GetIndex("my-index")
if err != nil {
log.Fatal(err)
}
// Upsert some vectors
vectors := []vecx.VectorItem{
{
ID: "doc1",
Vector: make([]float32, 768), // Your 768-dimensional vector
Meta: map[string]interface{}{
"title": "My Document",
"category": "technology",
},
},
}
err = index.Upsert(vectors)
if err != nil {
log.Fatal(err)
}
// Search for similar vectors
queryVector := make([]float32, 768) // Your query vector
results, err := index.Query(queryVector, 10, nil, 128, false)
if err != nil {
log.Fatal(err)
}
for _, result := range results {
fmt.Printf("ID: %s, Similarity: %.3f\n", result.ID, result.Similarity)
}
}For local development, simply initialize without a token:
client := vecx.NewVectorX("")For VectorX Cloud, use your provided token:
client := vecx.NewVectorX("account:api-key:region")The client automatically detects cloud tokens and configures the appropriate endpoint.
Creates a new VectorX client instance.
Creates a new vector index.
Parameters:
name(string): Index name (alphanumeric + underscores, <48 chars)dimension(int): Vector dimension (1-10,000)spaceType(string): Distance metric ("cosine", "l2", "ip")M(int): HNSW algorithm parameter for connectivityefCon(int): HNSW construction parameteruseFp16(bool): Use 16-bit floating point precisionversion(*int): Optional version number
Example:
err := client.CreateIndex("embeddings", 1536, "cosine", 16, 128, false, nil)Lists all available indexes.
Retrieves an index instance for operations.
Deletes an index and all its data.
Inserts or updates vectors in the index (max 1,000 vectors per batch).
VectorItem Structure:
type VectorItem struct {
ID string `json:"id"`
Vector []float32 `json:"vector"`
Meta map[string]interface{} `json:"meta,omitempty"`
Filter map[string]interface{} `json:"filter,omitempty"`
}Searches for similar vectors.
Parameters:
vector([]float32): Query vectork(int): Number of results to return (max 256)filter(map[string]interface{}): Optional metadata filteref(int): Search quality parameter (max 1,024)includeVectors(bool): Include vector data in results
Returns:
type QueryResult struct {
ID string `json:"id"`
Similarity float32 `json:"similarity"`
Distance float32 `json:"distance"`
Meta map[string]interface{} `json:"meta"`
Filter map[string]interface{} `json:"filter,omitempty"`
Vector []float32 `json:"vector,omitempty"`
}Retrieves a specific vector by ID.
Deletes a vector by ID.
package main
import (
"fmt"
"log"
"github.com/LaunchX-Labs/vecx-go"
)
func main() {
client := vecx.NewVectorX("your-token")
// Create index
err := client.CreateIndex("documents", 384, "cosine", 16, 128, false, nil)
if err != nil {
log.Fatal(err)
}
index, err := client.GetIndex("documents")
if err != nil {
log.Fatal(err)
}
// Prepare sample data
documents := []vecx.VectorItem{
{
ID: "doc_1",
Vector: generateEmbedding("The quick brown fox jumps"),
Meta: map[string]interface{}{
"title": "Sample Document 1",
"author": "John Doe",
"timestamp": "2024-01-15",
},
Filter: map[string]interface{}{
"category": "animals",
"public": true,
},
},
{
ID: "doc_2",
Vector: generateEmbedding("Machine learning advances"),
Meta: map[string]interface{}{
"title": "ML Research Paper",
"author": "Jane Smith",
"timestamp": "2024-01-16",
},
Filter: map[string]interface{}{
"category": "technology",
"public": false,
},
},
}
// Upsert documents
err = index.Upsert(documents)
if err != nil {
log.Fatal(err)
}
fmt.Println("Documents uploaded successfully!")
}
func generateEmbedding(text string) []float32 {
// This is a placeholder - use your actual embedding model
embedding := make([]float32, 384)
for i := range embedding {
embedding[i] = float32(len(text)) * 0.01 * float32(i)
}
return embedding
}func searchDocuments(index *vecx.Index, queryText string) {
// Generate query embedding
queryVector := generateEmbedding(queryText)
// Search without filters
results, err := index.Query(queryVector, 5, nil, 128, false)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d results for '%s':\n", len(results), queryText)
for i, result := range results {
fmt.Printf("%d. %s (similarity: %.3f)\n",
i+1, result.Meta["title"], result.Similarity)
}
// Search with category filter
filter := map[string]interface{}{
"category": "technology",
"public": true,
}
filteredResults, err := index.Query(queryVector, 5, filter, 128, false)
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nFiltered results (%d):\n", len(filteredResults))
for i, result := range filteredResults {
fmt.Printf("%d. %s\n", i+1, result.Meta["title"])
}
}func manageIndexes(client *vecx.VectorX) {
// List all indexes
indexes, err := client.ListIndexes()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Current indexes (%d):\n", len(indexes))
for i, idx := range indexes {
fmt.Printf("%d. %+v\n", i+1, idx)
}
// Create high-precision index
err = client.CreateIndex("high-precision", 1536, "cosine", 32, 256, true, nil)
if err != nil {
log.Printf("Create failed: %v", err)
}
// Get index info
index, err := client.GetIndex("high-precision")
if err == nil {
fmt.Printf("Index info: %s\n", index.GetInfo())
}
// Clean up
err = client.DeleteIndex("high-precision")
if err != nil {
log.Printf("Delete failed: %v", err)
}
}Best for normalized vectors and semantic similarity:
client.CreateIndex("semantic", 768, "cosine", 16, 128, false, nil)Best for spatial data and exact matches:
client.CreateIndex("spatial", 512, "l2", 16, 128, false, nil)Best for recommendation systems:
client.CreateIndex("recommendations", 256, "ip", 16, 128, false, nil)- M: Controls recall vs memory usage (16-64 recommended)
- ef_con: Build-time search quality (128-512 recommended)
- ef: Query-time search quality (k to 512 recommended)
- Batch Operations: Use batch upsert for better performance
- Dimension Choice: Higher dimensions = better accuracy but slower queries
- Precision: Use FP16 for memory savings if precision allows
- Filter Strategy: Apply filters judiciously to maintain performance
// Handle common errors
err := client.CreateIndex("test", 768, "cosine", 16, 128, false, nil)
if err != nil {
switch {
case strings.Contains(err.Error(), "already exists"):
fmt.Println("Index already exists, continuing...")
case strings.Contains(err.Error(), "invalid index name"):
fmt.Println("Invalid index name format")
case strings.Contains(err.Error(), "dimension cannot be greater"):
fmt.Println("Dimension too large")
default:
log.Fatal("Unexpected error:", err)
}
}- Go 1.24.5 or later
github.com/vmihailenco/msgpack/v5- Efficient binary serialization