Skip to content

Latest commit

 

History

History
110 lines (77 loc) · 4.08 KB

File metadata and controls

110 lines (77 loc) · 4.08 KB

Redis Examples

These examples use the redis memory backend.

Table of Contents

Key Features

  • Redis Memory Backend Integration: Demonstrates how to integrate Redis as a memory backend for NeMo Agent toolkit workflows, enabling persistent memory storage and retrieval across agent interactions.
  • Chat Memory Management: Shows implementation of simple chat functionality with the ability to create, store, and recall memories using Redis as the underlying storage system.
  • Embeddings-Based Memory Search: Uses embeddings models to create vector representations of queries and stored memories, implementing HNSW indexing with L2 distance metrics for efficient similarity search.

Prerequisites

Ensure that Docker is installed and the Docker service is running before proceeding.

  • Install Docker: Follow the official installation guide for your platform: Docker Installation Guide
  • Start Docker Service:
    • Linux: Run sudo systemctl start docker (ensure your user has permission to run Docker).
    • Mac & Windows: Docker Desktop should be running in the background.
  • Verify Docker Installation: Run the following command to verify that Docker is installed and running correctly:
docker info

Installation and Setup

If you have not already done so, follow the instructions in the Install Guide to create the development environment and install NeMo Agent toolkit.

To run this example, install the required dependencies by running the following command:

uv sync --extra langchain --extra redis --extra telemetry

Start Services

Run redis on localhost:6379 and Redis Insight on localhost:5540 with:

docker compose -f examples/deploy/docker-compose.redis.yml up

The examples are configured to use the Phoenix observability tool. Start phoenix on localhost:6006 with:

docker compose -f examples/deploy/docker-compose.phoenix.yml up

Run the Workflow

This example shows how to have a simple chat that uses a Redis memory backend for creating and retrieving memories.

An embeddings model is used to create embeddings for queries and for stored memories. Uses HNSW and L2 distance metric.

Create Memory

Here we will add a memory for the workflow to use in following invocations. The memory tool will automatically determine the intent as to whether or not an input should be stored as a "fact" or if the input should be used to query the memory.

nat run --config_file=examples/memory/redis/configs/config.yml --input "my favorite flavor is strawberry"

Expected Workflow Output

<snipped for brevity>

Workflow Result:
['The user's favorite flavor has been stored as strawberry.']

Recall Memory

Once we have established something in the memory, we can use the workflow to give us a response based on its input.

nat run --config_file=examples/memory/redis/configs/config.yml --input "what flavor of ice-cream should I get?"

Expected Workflow Output

<snipped for brevity>

Workflow Result:
['You should get strawberry ice cream, as it is your favorite flavor.']