Agent & Knowledge¶
Higher-level building blocks for retrieval-augmented agents.
Agent¶
Agent
¶
Agent(model: str = 'gpt-4o-mini', system_prompt: str | None = None, redis_url: str = 'redis://localhost:6379', redis_client: Redis | None = None, config: AgentConfig | None = None)
Framework-agnostic agent with LiteLLM backend.
Example
agent = Agent( model="gpt-4o-mini", # Or "anthropic/claude-3-5-sonnet" redis_url="redis://localhost:6379", )
Ingest knowledge¶
await agent.knowledge.ingest("Redis uses RDB for persistence...")
Add custom tools¶
agent.tools.add_provider(MyProvider())
Chat¶
response = await agent.chat("How does Redis persistence work?")
Initialize agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
LiteLLM model name (e.g., "gpt-4o-mini", "anthropic/claude-3-5-sonnet"). |
'gpt-4o-mini'
|
system_prompt
|
str | None
|
Optional system prompt. |
None
|
redis_url
|
str
|
Redis connection URL. |
'redis://localhost:6379'
|
redis_client
|
Redis | None
|
Optional existing Redis client. |
None
|
config
|
AgentConfig | None
|
Optional full configuration. |
None
|
Source code in redis_agent_kit/agent.py
add_provider
¶
add_provider(provider: ToolProvider) -> None
Add a tool provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
ToolProvider
|
ToolProvider instance. |
required |
clear_history
¶
chat
async
¶
Send a message and get a response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
User message. |
required |
use_knowledge
|
bool | None
|
Override config to enable/disable knowledge context. |
None
|
use_tools
|
bool | None
|
Override config to enable/disable tools. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Assistant response. |
Source code in redis_agent_kit/agent.py
AgentConfig¶
AgentConfig
dataclass
¶
AgentConfig(model: str = 'gpt-4o-mini', system_prompt: str | None = None, temperature: float = 0.7, max_tokens: int | None = None, max_tool_iterations: int = 10, use_knowledge: bool = True, use_tools: bool = True, knowledge_context_limit: int = 5)
Configuration for Agent.
KnowledgeStore¶
KnowledgeStore
¶
KnowledgeStore(client: Redis, vectorizer: Vectorizer | None = None, prefix: str = 'rak', embedding_model: str = 'text-embedding-3-small', dimensions: int | None = None)
High-level knowledge store combining vectorization and search.
Example
from redis_agent_kit import KnowledgeStore
ks = KnowledgeStore.from_url("redis://localhost:6379")
Ingest content¶
await ks.ingest("Redis uses RDB for persistence...", title="Redis Persistence")
Search¶
results = await ks.search("How does Redis save data?") for r in results: print(f"{r.content[:100]}... (score: {r.score:.2f})")
Initialize knowledge store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
Async Redis client. |
required |
vectorizer
|
Vectorizer | None
|
Custom vectorizer (created with model if None). |
None
|
prefix
|
str
|
Key prefix for storage. |
'rak'
|
embedding_model
|
str
|
Model name for embeddings (used if no vectorizer). |
'text-embedding-3-small'
|
dimensions
|
int | None
|
Vector dimensions (auto-detected if None). |
None
|
Source code in redis_agent_kit/knowledge.py
from_url
classmethod
¶
from_url(redis_url: str = 'redis://localhost:6379', embedding_model: str = 'text-embedding-3-small', prefix: str = 'rak', **kwargs: Any) -> KnowledgeStore
Create KnowledgeStore from Redis URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redis_url
|
str
|
Redis connection URL. |
'redis://localhost:6379'
|
embedding_model
|
str
|
Model for generating embeddings. |
'text-embedding-3-small'
|
prefix
|
str
|
Key prefix for storage. |
'rak'
|
**kwargs
|
Any
|
Additional arguments for KnowledgeStore. |
{}
|
Returns:
| Type | Description |
|---|---|
KnowledgeStore
|
Configured KnowledgeStore instance. |
Source code in redis_agent_kit/knowledge.py
search
async
¶
Search for relevant content using semantic similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query text. |
required |
limit
|
int
|
Maximum number of results. |
10
|
distance_threshold
|
float | None
|
Optional max distance filter. |
None
|
Returns:
| Type | Description |
|---|---|
list[SearchResult]
|
List of SearchResult objects sorted by relevance. |
Source code in redis_agent_kit/knowledge.py
ingest
async
¶
ingest(content: str, title: str | None = None, doc_id: str | None = None, metadata: dict[str, Any] | None = None) -> str
Ingest a single piece of content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The text content to ingest. |
required |
title
|
str | None
|
Optional title for the content. |
None
|
doc_id
|
str | None
|
Optional document ID (auto-generated if None). |
None
|
metadata
|
dict[str, Any] | None
|
Optional metadata dict. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The document ID. |
Source code in redis_agent_kit/knowledge.py
ingest_many
async
¶
Ingest multiple documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
list[tuple[str, str | None, dict[str, Any] | None]]
|
List of (content, title, metadata) tuples. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of document IDs. |
Source code in redis_agent_kit/knowledge.py
delete
async
¶
Delete a document from the knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_id
|
str
|
Document ID to delete. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of chunks deleted. |
Source code in redis_agent_kit/knowledge.py
count
async
¶
Vectorizer¶
Vectorizer
¶
Vectorizer(model: str = 'text-embedding-3-small', vectorizer: BaseVectorizer | None = None, api_config: dict[str, Any] | None = None, cache: EmbeddingsCache | None = None)
Wrapper around RedisVL vectorizers with a simplified interface.
By default uses OpenAI's text-embedding-3-small model. Can be configured to use any RedisVL vectorizer or a custom LiteLLM-based vectorizer.
Examples:
Default OpenAI vectorizer¶
vectorizer = Vectorizer()
Custom model¶
vectorizer = Vectorizer(model="text-embedding-ada-002")
Use LiteLLM for broader provider support¶
vectorizer = Vectorizer.from_litellm(model="cohere/embed-english-v3.0")
Use any RedisVL vectorizer directly¶
from redisvl.utils.vectorize import CohereTextVectorizer vectorizer = Vectorizer(vectorizer=CohereTextVectorizer())
Initialize vectorizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
OpenAI embedding model name (ignored if vectorizer provided). |
'text-embedding-3-small'
|
vectorizer
|
BaseVectorizer | None
|
Optional RedisVL vectorizer instance to use directly. |
None
|
api_config
|
dict[str, Any] | None
|
Optional API configuration for the vectorizer. |
None
|
cache
|
EmbeddingsCache | None
|
Optional RedisVL EmbeddingsCache for caching. |
None
|
Source code in redis_agent_kit/vectorizer.py
from_litellm
classmethod
¶
from_litellm(model: str = 'text-embedding-3-small', dimensions: int | None = None, cache: EmbeddingsCache | None = None) -> Vectorizer
Create a vectorizer using LiteLLM for broader provider support.
LiteLLM supports many providers beyond what RedisVL offers natively: - OpenAI: text-embedding-3-small, text-embedding-ada-002 - Cohere: cohere/embed-english-v3.0 - Azure: azure/text-embedding-ada-002 - Voyage: voyage/voyage-2 - And many more...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
LiteLLM model name. |
'text-embedding-3-small'
|
dimensions
|
int | None
|
Output dimensions (if supported by model). |
None
|
cache
|
EmbeddingsCache | None
|
Optional RedisVL EmbeddingsCache. |
None
|
Returns:
| Type | Description |
|---|---|
Vectorizer
|
Vectorizer instance using LiteLLM. |
Source code in redis_agent_kit/vectorizer.py
embed
async
¶
embed_sync
¶
embed_many
async
¶
Generate embeddings for multiple texts (async).
embed_many_sync
¶
Generate embeddings for multiple texts (synchronous).
LiteLLMVectorizerAdapter¶
LiteLLMVectorizerAdapter
¶
LiteLLMVectorizerAdapter(model: str = 'text-embedding-3-small', dimensions: int | None = None, batch_size: int = 100)
Adapter to use LiteLLM with RedisVL's CustomTextVectorizer.
Provides sync and async embedding methods compatible with RedisVL.
Initialize adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
LiteLLM model name. |
'text-embedding-3-small'
|
dimensions
|
int | None
|
Output dimensions (if supported). |
None
|
batch_size
|
int
|
Maximum texts per API call. |
100
|
Source code in redis_agent_kit/vectorizer.py
embed
¶
embed_many
¶
Embed multiple texts synchronously.
Source code in redis_agent_kit/vectorizer.py
aembed
async
¶
aembed_many
async
¶
Embed multiple texts asynchronously.