Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions python/samples/02-agents/context_providers/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This folder contains an example demonstrating how to use the Redis context provi
|------|-------------|
| [`azure_redis_conversation.py`](azure_redis_conversation.py) | Demonstrates conversation persistence with RedisHistoryProvider and Azure Redis with Azure AD (Entra ID) authentication using credential provider. |
| [`redis_basics.py`](redis_basics.py) | Shows standalone provider usage and agent integration. Demonstrates writing messages to Redis, retrieving context via full‑text or hybrid vector search, and persisting preferences across threads. Also includes a simple tool example whose outputs are remembered. |
| [`redis_conversation.py`](redis_conversation.py) | Simple example showing conversation persistence with RedisContextProvider using traditional connection string authentication. |
| [`redis_conversation.py`](redis_conversation.py) | Shows context retrieval across conversation turns with RedisContextProvider using a Redis connection URL and OpenAI embeddings. For complete conversation history persistence, use RedisHistoryProvider. |
| [`redis_sessions.py`](redis_sessions.py) | Demonstrates memory scoping strategies. Includes: (1) global memory scope with `application_id`, `agent_id`, and `user_id` shared across operations; (2) hybrid vector search using a custom OpenAI vectorizer for richer context retrieval; and (3) multiple agents with isolated memory via different `agent_id` values. |


Expand All @@ -21,7 +21,7 @@ This folder contains an example demonstrating how to use the Redis context provi
1. A running Redis with RediSearch (Redis Stack or a managed service)
2. Python environment with Agent Framework Redis extra installed
3. Microsoft Foundry project endpoint and Azure OpenAI Responses deployment
4. Optional: OpenAI API key if using vector embeddings
4. OpenAI API key for the OpenAI-vectorizer examples (`redis_basics.py`, `redis_conversation.py`, and the hybrid-search and multiple-agents scenarios in `redis_sessions.py`)

### Install the package

Expand Down Expand Up @@ -53,22 +53,22 @@ See quickstart: `https://learn.microsoft.com/azure/redis/quickstart-create-manag

- `FOUNDRY_PROJECT_ENDPOINT` (required): Microsoft Foundry project endpoint for `FoundryChatClient`
- `FOUNDRY_MODEL` (required): Foundry model deployment name
- `OPENAI_API_KEY` (optional): Required only if you set `vectorizer_choice="openai"` to enable hybrid search.
- `OPENAI_API_KEY`: Required by the examples that instantiate `OpenAITextVectorizer` for hybrid search.

### Provider configuration highlights

The provider supports both full‑text only and hybrid vector search:

- Set `vectorizer_choice` to `"openai"` or `"hf"` to enable embeddings and hybrid search.
- When using a vectorizer, also set `vector_field_name` (e.g., `"vector"`).
- Pass a RedisVL vectorizer instance, such as `OpenAITextVectorizer`, through `redis_vectorizer` and set `vector_field_name` (e.g., `"vector"`) to enable hybrid search.
- Omit `redis_vectorizer` and `vector_field_name` for full-text-only retrieval, as in the global-scope scenario in `redis_sessions.py`.
- Partition fields for scoping memory: `application_id`, `agent_id`, `user_id`.
- Index management: `index_name`, `overwrite_redis_index`, `drop_redis_index`.
- Index configuration: `index_name`, `prefix`, and `overwrite_index`.

## What the example does

`redis_basics.py` walks through three scenarios:

1. Standalone provider usage: adds messages and retrieves context via `invoking`.
1. Standalone provider usage: stores messages via `after_run` and retrieves context via `before_run`.
2. Agent integration: teaches the agent a preference and verifies it is remembered across turns.
3. Agent + tool: calls a sample tool (flight search) and then asks the agent to recall details remembered from the tool output.

Expand All @@ -85,7 +85,7 @@ export FOUNDRY_PROJECT_ENDPOINT="https://<resource>.services.ai.azure.com/api/pr
export FOUNDRY_MODEL="<deployment-name>"
```

3) (Optional) Set your OpenAI key if using embeddings:
3) Set your OpenAI key for `redis_basics.py` and the other OpenAI-vectorizer examples:

```bash
export OPENAI_API_KEY="<your key>"
Expand All @@ -108,12 +108,12 @@ You should see the agent responses and, when using embeddings, context retrieved

### Hybrid vector search (optional)

- Enable by setting `vectorizer_choice` to `"openai"` (requires `OPENAI_API_KEY`) or `"hf"` (offline model).
- Provide `vector_field_name` (e.g., `"vector"`); other vector settings have sensible defaults.
- Pass a vectorizer as `redis_vectorizer` and provide `vector_field_name` (e.g., `"vector"`). The examples use `OpenAITextVectorizer`, which requires `OPENAI_API_KEY`.
- `vector_algorithm` and `vector_distance_metric` configure the vector index; the examples use `"hnsw"` and `"cosine"`.

### Index lifecycle controls

- `overwrite_redis_index` and `drop_redis_index` help recreate indexes during iteration.
- Set `overwrite_index=True` to recreate an existing index during initialization. The examples clean up their indexes with `await provider.redis_index.delete()`.

## Troubleshooting

Expand Down
Loading