Redis Vector Store Provider
The Redis provider implements the vectorstore.VectorStore interface using Redis hashes with the RediSearch module for vector similarity search. It stores documents as Redis hashes and leverages RediSearch’s KNN vector search capabilities.
Choose Redis when you already have Redis in your infrastructure stack and want to add vector search without introducing a new database. Redis provides low-latency search suitable for real-time applications, and the RediSearch module adds full-text search alongside vector similarity for hybrid queries.
Installation
Section titled “Installation”go get github.com/lookatitude/beluga-ai/rag/vectorstore/providers/redisStart Redis with RediSearch:
docker run -p 6379:6379 redis/redis-stackQuick Start
Section titled “Quick Start”package main
import ( "context" "log"
"github.com/lookatitude/beluga-ai/config" "github.com/lookatitude/beluga-ai/rag/vectorstore" "github.com/lookatitude/beluga-ai/schema" _ "github.com/lookatitude/beluga-ai/rag/vectorstore/providers/redis")
func main() { store, err := vectorstore.New("redis", config.ProviderConfig{ BaseURL: "localhost:6379", Options: map[string]any{ "index": "idx:documents", "prefix": "doc:", "dimension": float64(1536), }, }) if err != nil { log.Fatal(err) }
ctx := context.Background()
docs := []schema.Document{ {ID: "doc1", Content: "Go is a statically typed language", Metadata: map[string]any{"lang": "en"}}, } embeddings := [][]float32{make([]float32, 1536)}
err = store.Add(ctx, docs, embeddings) if err != nil { log.Fatal(err) }}Configuration
Section titled “Configuration”| Parameter | Type | Default | Description |
|---|---|---|---|
BaseURL | string | localhost:6379 | Redis server address |
Options["index"] | string | idx:documents | RediSearch index name |
Options["prefix"] | string | doc: | Key prefix for document hashes |
Options["dimension"] | float64 | 1536 | Vector dimensionality |
Index Setup
Section titled “Index Setup”Use EnsureIndex to create the RediSearch index:
import ( redisstore "github.com/lookatitude/beluga-ai/rag/vectorstore/providers/redis")
store := redisstore.New("localhost:6379", redisstore.WithIndex("idx:my_docs"), redisstore.WithPrefix("mydoc:"), redisstore.WithDimension(768),)
err := store.EnsureIndex(ctx)if err != nil { log.Fatal(err)}This creates a RediSearch index with:
contentas a TEXT fieldembeddingas a VECTOR field using FLAT indexing with COSINE distance
If the index already exists, the call succeeds silently.
Direct Construction
Section titled “Direct Construction”store := redisstore.New("localhost:6379", redisstore.WithIndex("idx:vectors"), redisstore.WithPrefix("vec:"), redisstore.WithDimension(1024),)Custom Redis Client
Section titled “Custom Redis Client”Provide a custom Redis client for advanced connection configuration:
import goredis "github.com/redis/go-redis/v9"
client := goredis.NewClient(&goredis.Options{ Addr: "localhost:6379", Password: os.Getenv("REDIS_PASSWORD"), DB: 0,})
store := redisstore.New("", redisstore.WithClient(client), redisstore.WithIndex("idx:my_docs"), redisstore.WithDimension(1536),)Metadata Filtering
Section titled “Metadata Filtering”Redis supports tag-based filtering in the KNN search query:
results, err := store.Search(ctx, queryVec, 10, vectorstore.WithFilter(map[string]any{ "lang": "en", }),)Filters are translated to RediSearch filter expressions (e.g., @lang:{en}).
Search with Threshold
Section titled “Search with Threshold”Cosine distance is converted to similarity: 1.0 - distance:
results, err := store.Search(ctx, queryVec, 10, vectorstore.WithThreshold(0.8),)Data Storage Format
Section titled “Data Storage Format”Documents are stored as Redis hashes with the following fields:
content: Document text contentembedding: Binary-encoded float32 vector- Custom metadata fields as string values
Keys follow the pattern {prefix}{document_id} (e.g., doc:my-document).