Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Memory Vault - Hierarchical Memory System for AI Agents

A RAG (Retrieval-Augmented Generation) system that provides AI agents with both short-term conversation memory and long-term knowledge retrieval capabilities.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      User Interaction                        β”‚
β”‚                 (Query / Document Upload)                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       RAG Agent                              β”‚
β”‚            (Dynamic Context Construction)                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                  β”‚                   β”‚
           β–Ό                  β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Redis       β”‚ β”‚     Qdrant      β”‚ β”‚    AWS Bedrock      β”‚
β”‚  (Short-term)    β”‚ β”‚   (Long-term)   β”‚ β”‚  (Embeddings + LLM) β”‚
β”‚                  β”‚ β”‚                 β”‚ β”‚                     β”‚
β”‚ β€’ Chat history   β”‚ β”‚ β€’ Document      β”‚ β”‚ β€’ Titan Embeddings  β”‚
β”‚ β€’ Doc metadata   β”‚ β”‚   vectors       β”‚ β”‚ β€’ Claude LLM        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

  • Short-term Memory (Redis): Maintains conversation history and document metadata within a session
  • Long-term Memory (Qdrant): Vector storage for semantic search over uploaded documents
  • Runtime Document Ingestion: Upload documents during conversation - no pre-processing required
  • Session Scoping: Each session has isolated documents and chat history
  • AWS Bedrock Integration: Uses Titan for embeddings and Claude for responses via LiteLLM

Prerequisites

  • Docker and Docker Compose
  • Python 3.10+
  • AWS Account with Bedrock access (Claude and Titan models enabled)

Quick Start

1. Clone and Setup

cd memory_vault

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Configure Environment

# Copy example environment file
cp .env.example .env

# Edit .env with your AWS credentials

Required environment variables:

AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_SESSION_TOKEN=your_session_token  # Optional, for temporary credentials
AWS_REGION_NAME=us-east-1  # or your preferred region

3. Start Infrastructure

docker-compose up -d

This starts:

  • Qdrant on port 6333 (HTTP) and 6334 (gRPC)
  • Redis on port 6379

4. Run the Demo

python scripts/demo.py

Usage

Interactive Demo Commands

Command Description
/upload <path> Upload and ingest a document
/docs List uploaded documents
/context Toggle showing retrieved context
/clear Clear session (history + documents)
/health Check Redis and Qdrant status
/help Show help message
/quit Exit the demo

Example Session

> /upload ~/docs/poker_rules.txt
πŸ“€ Uploading ~/docs/poker_rules.txt...
βœ… Ingested 'poker_rules.txt' (12 chunks)

> /upload ~/docs/tournament_guide.txt
πŸ“€ Uploading ~/docs/tournament_guide.txt...
βœ… Ingested 'tournament_guide.txt' (8 chunks)

> /docs
πŸ“ Documents in session (2):
  β€’ poker_rules.txt (12 chunks)
  β€’ tournament_guide.txt (8 chunks)

> What is the rake percentage for cash games?

πŸ€– Based on the poker rules document, the rake for cash games is 2.5%
   capped at $5 per hand. For tournaments, there's a flat 10% fee...

> /context
πŸ” Context display: ON

> What are the blind levels in tournaments?

πŸ“š Retrieved Context:
  [1] tournament_guide.txt (score: 0.89)
      Blind levels increase every 15 minutes...
  [2] poker_rules.txt (score: 0.72)
      Tournament blinds start at 25/50...

πŸ€– According to the tournament guide, blind levels increase every 15 minutes.
   The starting blinds are 25/50 as mentioned in the poker rules...

Programmatic Usage

from src.agent import RAGAgent
from src.config import Config

# Initialize
config = Config()
agent = RAGAgent(config=config)

session_id = "user-123"

# Upload documents
result = agent.upload_document(session_id, "path/to/document.txt")
print(f"Ingested {result['chunk_count']} chunks")

# Chat with context
response = agent.chat(session_id, "What does the document say about X?")
print(response["response"])

# List documents
docs = agent.list_documents(session_id)

# Clear session when done
agent.clear_session(session_id)

Project Structure

memory_vault/
β”œβ”€β”€ docker-compose.yml       # Qdrant + Redis infrastructure
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ .env.example            # Environment template
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ config.py           # Configuration management
β”‚   β”œβ”€β”€ embeddings.py       # LiteLLM + Bedrock Titan wrapper
β”‚   β”œβ”€β”€ short_term_memory.py # Redis wrapper
β”‚   β”œβ”€β”€ long_term_memory.py  # Qdrant wrapper
β”‚   └── agent.py            # RAG Agent
β”œβ”€β”€ scripts/
β”‚   └── demo.py             # Interactive CLI demo
└── README.md

Configuration Options

Variable Default Description
REDIS_HOST localhost Redis host
REDIS_PORT 6379 Redis port
QDRANT_HOST localhost Qdrant host
QDRANT_PORT 6333 Qdrant port
EMBEDDING_MODEL amazon.titan-embed-text-v2:0 Bedrock embedding model
LLM_MODEL anthropic.claude-3-haiku-20240307-v1:0 Bedrock LLM model
MAX_CHAT_HISTORY 10 Number of conversation turns to retain
CHUNK_SIZE 500 Max characters per document chunk
TOP_K_RESULTS 3 Number of similar chunks to retrieve

How It Works

Document Ingestion Flow

  1. User uploads a document via /upload
  2. Document is read and split into chunks (by paragraphs, max 500 chars)
  3. Each chunk is embedded using Titan Embeddings
  4. Vectors are stored in Qdrant with session_id and source metadata
  5. Document metadata is saved to Redis for quick lookup

Query Flow

  1. User asks a question
  2. Chat history is retrieved from Redis
  3. Question is embedded and searched against Qdrant (filtered by session_id)
  4. Top 3 relevant chunks are retrieved
  5. System prompt is constructed with chat history + knowledge context
  6. Claude generates a response
  7. Conversation turn is saved to Redis

Troubleshooting

Services not starting

# Check Docker logs
docker-compose logs qdrant
docker-compose logs redis

# Restart services
docker-compose down && docker-compose up -d

AWS Credentials Error

  • Ensure your AWS account has Bedrock access enabled
  • Check that Claude and Titan models are enabled in your region
  • Verify credentials in .env file

Connection Refused

  • Make sure Docker containers are running: docker ps
  • Check ports 6333 (Qdrant) and 6379 (Redis) are not in use

License

MIT

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages