Skip to main content

Redis

Redis provides high-performance in-memory vector storage using RediSearch-compatible APIs, ideal for applications requiring sub-millisecond response times and fast semantic search capabilities. Valkey deployments that expose compatible FT.* commands are supported through the same configuration.

Key Features

  • High Performance: Sub-millisecond cache retrieval with Redis’s in-memory storage
  • Cost Effective: Open-source solution with no licensing costs
  • HNSW Algorithm: Fast vector similarity search with excellent recall rates
  • Connection Pooling: Advanced connection management for high-throughput applications
  • TTL Support: Automatic expiration of cached entries
  • Streaming Support: Full streaming response caching with proper chunk ordering
  • Flexible Filtering: Advanced metadata filtering with exact string matching

Setup & Installation

Redis Cloud:
  • Sign up at cloud.redis.io
  • Create a new database with RediSearch module enabled
  • Get your connection details
Local Redis with RediSearch:
# Using Docker with Redis Stack (includes RediSearch)
docker run -d --name redis-stack -p 6379:6379 redis/redis-stack:latest
Local Valkey Bundle:
# Example Valkey bundle with search/vector support
docker run -d --name valkey-bundle -p 6379:6379 valkey/valkey-bundle:9.0.0

Configuration Options

// Configure Redis-compatible vector store (Redis or Valkey endpoint)
vectorConfig := &vectorstore.Config{
    Enabled: true,
    Type:    vectorstore.VectorStoreTypeRedis, // Keep type as "redis" for Valkey too
    Config: vectorstore.RedisConfig{
        Addr:     "localhost:6379",        // Redis/Valkey server address - REQUIRED
        Username: "",                      // Optional: Redis username
        Password: "",                      // Optional: Redis password
        DB:       0,                       // Optional: Redis database number (default: 0)

        // Optional: Connection pool settings
        PoolSize:        10,               // Maximum socket connections
        MaxActiveConns:  10,               // Maximum active connections
        MinIdleConns:    5,                // Minimum idle connections
        MaxIdleConns:    10,               // Maximum idle connections

        // Optional: Timeout settings
        DialTimeout:     5 * time.Second,  // Connection timeout
        ReadTimeout:     3 * time.Second,  // Read timeout
        WriteTimeout:    3 * time.Second,  // Write timeout
        ContextTimeout:  10 * time.Second, // Operation timeout
    },
}

// Create vector store
store, err := vectorstore.NewVectorStore(context.Background(), vectorConfig, logger)
if err != nil {
    log.Fatal("Failed to create vector store:", err)
}

Redis-Specific Features

Vector Search Algorithm: Redis uses the HNSW (Hierarchical Navigable Small World) algorithm for vector similarity search, which provides:
  • Fast Search: O(log N) search complexity
  • High Accuracy: Excellent recall rates for similarity search
  • Memory Efficient: Optimized for in-memory operations
  • Cosine Similarity: Uses cosine distance metric for semantic similarity
Connection Pool Management: Redis provides extensive connection pool configuration:
config := vectorstore.RedisConfig{
    Addr:            "localhost:6379",
    PoolSize:        20,                    // Max socket connections
    MaxActiveConns:  20,                    // Max active connections
    MinIdleConns:    5,                     // Min idle connections
    MaxIdleConns:    10,                    // Max idle connections
    ConnMaxLifetime: 30 * time.Minute,      // Connection lifetime
    ConnMaxIdleTime: 5 * time.Minute,       // Idle connection timeout
    DialTimeout:     5 * time.Second,       // Connection timeout
    ReadTimeout:     3 * time.Second,       // Read timeout
    WriteTimeout:    3 * time.Second,       // Write timeout
    ContextTimeout:  10 * time.Second,      // Operation timeout
}

Performance Optimization

Connection Pool Tuning: For high-throughput applications, tune the connection pool settings:
{
  "vector_store": {
    "config": {
      "pool_size": 50,           // Increase for high concurrency
      "max_active_conns": 50,    // Match pool_size
      "min_idle_conns": 10,      // Keep connections warm
      "max_idle_conns": 20,      // Allow some idle connections
      "conn_max_lifetime": "1h", // Refresh connections periodically
      "conn_max_idle_time": "10m" // Close idle connections
    }
  }
}
Memory Optimization:
  • TTL: Use appropriate TTL values to prevent memory bloat
  • Namespace Cleanup: Regularly clean up unused namespaces
Batch Operations: Redis supports efficient batch operations:
// Batch retrieval
results, err := store.GetChunks(ctx, namespace, []string{"id1", "id2", "id3"})

// Batch deletion
deleteResults, err := store.DeleteAll(ctx, namespace, queries)

Production Considerations

Search Module Required: Redis/Valkey integration requires a search module/API that supports FT.* commands (index creation and vector search). If FT.INFO or FT.SEARCH is unavailable, semantic caching will not work.
Production Considerations:
  • Use Redis AUTH for production deployments
  • Configure appropriate connection timeouts
  • Monitor memory usage and set appropriate TTL values
For the VectorStore interface API and usage examples, see Vector Store Architecture. For semantic caching setup, see Semantic Caching.