Skip to content
Docs

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.

Terminal window
go get github.com/lookatitude/beluga-ai/rag/vectorstore/providers/redis

Start Redis with RediSearch:

Terminal window
docker run -p 6379:6379 redis/redis-stack
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)
}
}
ParameterTypeDefaultDescription
BaseURLstringlocalhost:6379Redis server address
Options["index"]stringidx:documentsRediSearch index name
Options["prefix"]stringdoc:Key prefix for document hashes
Options["dimension"]float641536Vector dimensionality

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:

  • content as a TEXT field
  • embedding as a VECTOR field using FLAT indexing with COSINE distance

If the index already exists, the call succeeds silently.

store := redisstore.New("localhost:6379",
redisstore.WithIndex("idx:vectors"),
redisstore.WithPrefix("vec:"),
redisstore.WithDimension(1024),
)

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),
)

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}).

Cosine distance is converted to similarity: 1.0 - distance:

results, err := store.Search(ctx, queryVec, 10,
vectorstore.WithThreshold(0.8),
)

Documents are stored as Redis hashes with the following fields:

  • content: Document text content
  • embedding: Binary-encoded float32 vector
  • Custom metadata fields as string values

Keys follow the pattern {prefix}{document_id} (e.g., doc:my-document).