ChromaDB vector store implementation for Forge AI SDK using ChromaDB's REST API.
- ✅ REST API client (no external SDK dependencies)
- ✅ Collection management (auto-creation)
- ✅ Batch vector operations
- ✅ Metadata filtering
- ✅ Docker-friendly setup
- ✅ Connection pooling and retry logic
- ✅ Production-ready error handling
- ✅ Observability (logging & metrics)
go get github.com/xraph/ai-sdk/integrations/vectorstores/chromapackage main
import (
"context"
"log"
"github.com/xraph/ai-sdk/integrations/vectorstores/chroma"
sdk "github.com/xraph/ai-sdk"
)
func main() {
ctx := context.Background()
// Create ChromaDB store
store, err := chroma.NewChromaVectorStore(ctx, chroma.Config{
BaseURL: "http://localhost:8000",
CollectionName: "my_vectors",
})
if err != nil {
log.Fatal(err)
}
defer store.Close()
// Upsert vectors
vectors := []sdk.Vector{
{
ID: "doc-1",
Values: []float64{0.1, 0.2, 0.3, /* ... */},
Metadata: map[string]any{
"text": "Sample document",
"source": "example",
},
},
}
if err := store.Upsert(ctx, vectors); err != nil {
log.Fatal(err)
}
// Query similar vectors
queryVector := []float64{0.1, 0.2, 0.3, /* ... */}
results, err := store.Query(ctx, queryVector, 10, nil)
if err != nil {
log.Fatal(err)
}
for _, match := range results {
log.Printf("ID: %s, Score: %.4f\n", match.ID, match.Score)
}
}// Query with metadata filters
filter := map[string]any{
"source": "example",
"type": "document",
}
results, err := store.Query(ctx, queryVector, 10, filter)// Upsert 1000 vectors at once
largeVectorSet := make([]sdk.Vector, 1000)
for i := range largeVectorSet {
largeVectorSet[i] = sdk.Vector{
ID: fmt.Sprintf("vec-%d", i),
Values: generateRandomVector(1536),
}
}
if err := store.Upsert(ctx, largeVectorSet); err != nil {
log.Fatal(err)
}type Config struct {
BaseURL string // Required: ChromaDB base URL (e.g., "http://localhost:8000")
CollectionName string // Required: Name of the collection
APIKey string // Optional: API key for authentication
Timeout time.Duration // Optional: Request timeout (default: 30s)
Logger logger.Logger // Optional: Logger for debugging
Metrics metrics.Metrics // Optional: Metrics for monitoring
}docker run -d -p 8000:8000 chromadb/chroma:latestdocker run -d \
-p 8000:8000 \
-v chroma_data:/chroma/chroma \
-e IS_PERSISTENT=TRUE \
chromadb/chroma:latestversion: '3.8'
services:
chromadb:
image: chromadb/chroma:latest
ports:
- "8000:8000"
volumes:
- chroma_data:/chroma/chroma
environment:
- IS_PERSISTENT=TRUE
- ANONYMIZED_TELEMETRY=${ANONYMIZED_TELEMETRY:-TRUE}
volumes:
chroma_data:
driver: local| Operation | Latency (p50) | Latency (p99) | Notes |
|---|---|---|---|
| Upsert | ~15ms | ~60ms | Batch of 100 vectors |
| Query | ~8ms | ~25ms | Top 10 results |
| Delete | ~10ms | ~35ms | Batch of 100 IDs |
Benchmarks performed with 100k vectors (1536 dimensions) on local Docker instance
store, err := chroma.NewChromaVectorStore(ctx, chroma.Config{
BaseURL: "http://localhost:8000",
CollectionName: "my_vectors",
Timeout: 60 * time.Second, // 60 second timeout
})store, err := chroma.NewChromaVectorStore(ctx, chroma.Config{
BaseURL: "https://api.chroma.example.com",
CollectionName: "my_vectors",
APIKey: "your-api-key",
})# Unit tests (uses mock HTTP server)
go test ./...
# Integration tests (requires running ChromaDB)
docker run -d -p 8000:8000 chromadb/chroma:latest
go test -tags=integration ./...import (
"github.com/xraph/ai-sdk"
"github.com/xraph/ai-sdk/integrations/vectorstores/chroma"
"github.com/xraph/ai-sdk/integrations/embeddings/openai"
)
// Create RAG system with ChromaDB
store, _ := chroma.NewChromaVectorStore(ctx, chroma.Config{
BaseURL: "http://localhost:8000",
CollectionName: "documents",
})
embedder, _ := openai.NewOpenAIEmbeddings(openai.OpenAIConfig{
APIKey: "your-api-key",
Model: "text-embedding-3-small",
})
rag := sdk.NewRAG(sdk.RAGConfig{
VectorStore: store,
Embedder: embedder,
TopK: 5,
})- ✅ Open-source and self-hosted
- ✅ Easy Docker deployment
- ✅ Good for development and testing
- ✅ Built-in metadata filtering
- ✅ HTTP/REST API (language agnostic)
- ❌ No official Go SDK (uses REST API)
- ❌ Single-node by default (no built-in replication)
- ❌ Limited high-availability options
- ❌ Performance may vary with very large datasets
- Use ChromaDB for: Development, testing, small to medium deployments
- Consider alternatives for: Large-scale production, high-availability requirements
Production Alternatives:
- Weaviate - Scalable, production-ready
- Qdrant - High performance, official SDK
- Pinecone - Managed, serverless
GET /api/v1/collections/{name}- Get collectionPOST /api/v1/collections- Create collectionPOST /api/v1/collections/{name}/add- Upsert vectorsPOST /api/v1/collections/{name}/query- Query vectorsPOST /api/v1/collections/{name}/delete- Delete vectors
ChromaDB uses L2 (Euclidean) distance by default. The SDK converts distances to similarity scores using the formula: similarity = 1 / (1 + distance)
# Check if ChromaDB is running
curl http://localhost:8000/api/v1/heartbeat
# Check Docker logs
docker logs <container_id>The SDK automatically handles existing collections. If you see this error, it's likely a race condition. The SDK will retry.
Increase the timeout in the config:
Config{
Timeout: 60 * time.Second,
}Contributions welcome! See the main CONTRIBUTING.md.
MIT License - see LICENSE