nat.plugins.redis.redis_editor#
Attributes#
Classes#
Wrapper class that implements NAT interfaces for Redis memory storage. |
Module Contents#
- logger#
- INDEX_NAME = 'memory_idx'#
- class RedisEditor(
- redis_client: redis.asyncio.Redis,
- key_prefix: str,
- embedder: langchain_core.embeddings.Embeddings,
Bases:
nat.memory.interfaces.MemoryEditorWrapper class that implements NAT interfaces for Redis memory storage.
Initialize Redis client for memory storage.
- Args:
redis_client: (redis.Redis) Redis client key_prefix: (str) Redis key prefix embedder: (Embeddings) Embedder for semantic search functionality
- _client: redis.asyncio.Redis#
- _embedder: langchain_core.embeddings.Embeddings#
- async add_items(items: list[nat.memory.models.MemoryItem]) None#
Insert Multiple MemoryItems into Redis. Each MemoryItem is stored with its metadata and tags.
- async search(
- query: str,
- top_k: int = 5,
- \*\*kwargs,
Retrieve items relevant to the given query.
- Args:
query (str): The query string to match. top_k (int): Maximum number of items to return. kwargs (dict): Keyword arguments to pass to the search method.
user_id (str): User ID for filtering results.
similarity_threshold (float, optional): Maximum similarity score threshold based on L2 (Euclidean) distance metric. Results with scores above this threshold are filtered out; if not specified, all top_k results are returned. Lower scores indicate higher similarity (0.0 = identical). Typical ranges: 0.0-0.5 (very similar), 0.5-1.0 (moderately similar), >1.0 (loosely related).
- Returns:
list[MemoryItem]: The most relevant MemoryItems for the given query.
- _create_memory_item( ) nat.memory.models.MemoryItem#
Helper method to create a MemoryItem from Redis data.
- async remove_items(\*\*kwargs)#
Remove memory items based on provided criteria.