Skip to content

Latest commit

 

History

History

Connectors.Memory.Redis

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Microsoft.SemanticKernel.Connectors.Redis

This connector uses Redis to implement Semantic Memory. It requires the RediSearch module to be enabled on Redis to implement vector similarity search.

What is RediSearch?

RediSearch is a source-available Redis module that enables querying, secondary indexing, and full-text search for Redis. These features enable multi-field queries, aggregation, exact phrase matching, numeric filtering, geo filtering and vector similarity semantic search on top of text queries.

Ways to get RediSearch:

  1. You can create an Azure Cache for Redis Enterpise instance and enable RediSearch module.

  2. Set up the RediSearch on your self-managed Redis, please refer to its documentation.

  3. Use the Redis Enterprise, see Azure Marketplace, AWS Marketplace, or Google Marketplace.

Quick start

  1. Run with Docker:
docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
  1. To use Redis as a semantic memory store:

    See Example 14 and Example 15 for more memory usage examples with the kernel.

// ConnectionMultiplexer should be a singleton instance in your application, please consider to dispose of it when your application shuts down.
// See https://stackexchange.github.io/StackExchange.Redis/Basics#basic-usage
ConnectionMultiplexer connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
IDatabase database = connectionMultiplexer.GetDatabase();
RedisMemoryStore memoryStore = new RedisMemoryStore(database, vectorSize: 1536);

var embeddingGenerator = new OpenAITextEmbeddingGenerationService("text-embedding-ada-002", apiKey);

SemanticTextMemory textMemory = new(memoryStore, embeddingGenerator);

var memoryPlugin = kernel.ImportPluginFromObject(new TextMemoryPlugin(textMemory));