| .github/workflows | ||
| docker | ||
| docs | ||
| helm | ||
| memora | ||
| memora-cli | ||
| memora-clients | ||
| memora-control-plane | ||
| memora-dev | ||
| memora-langmem | ||
| memora-openai | ||
| scripts | ||
| .env.example | ||
| .gitignore | ||
| .python-version | ||
| .sesskey | ||
| CLAUDE.md | ||
| openapi.json | ||
| PAPER_PERSONALITY.md | ||
| PAPER_RETRIEVAL.md | ||
| pyproject.toml | ||
| README.md | ||
| RELEASE.md | ||
| uv.lock | ||
Memora - Entity-Aware Memory System for AI Agents
A temporal-semantic-entity memory system that enables AI agents to store, retrieve, and reason over memories using graph-based spreading activation search.
Architecture
See architecture.md for comprehensive technical documentation.
The system provides:
- Three Memory Networks: Separate world knowledge, agent experiences, and formed opinions
- Multi-Strategy Retrieval: 4-way parallel search (semantic, keyword, graph, temporal-graph)
- Entity Resolution: Automatic entity disambiguation and linking
- Personality Framework: Big Five traits influencing opinion formation
- Neural Reranking: Optional cross-encoder for precision refinement
Quick Architecture Overview
Three Memory Networks:
- World Network: General knowledge ("Alice works at Google")
- Agent Network: Agent's own actions ("I recommended Yosemite to Alice")
- Opinion Network: Formed opinions with confidence scores ("Python is better for data science [0.85]")
Retrieval Pipeline:
Query → [Semantic + Keyword + Graph + Temporal] → RRF Merge → Cross-Encoder Reranking → MMR → Results
- 4-way parallel retrieval for high recall
- Neural cross-encoder reranking for precision
- MMR diversification to avoid redundancy
Key Features:
- Entity resolution links memories through shared people/places/things
- Graph spreading activation discovers indirect connections
- Temporal queries: "What did Alice do last spring?"
- Personality traits (Big Five model) influence opinion formation
Quick Start
Prerequisites
- Install dependencies:
uv sync
- Configure environment file:
Create .env file:
cat > .env << 'EOF'
# API Service Configuration
MEMORA_API_DATABASE_URL=postgresql://memora:memora_dev@localhost:5432/memora
# LLM Provider: "openai", "groq", or "ollama"
MEMORA_API_LLM_PROVIDER=groq
# API Key (not needed for ollama)
MEMORA_API_LLM_API_KEY=your_api_key_here
# LLM Model
MEMORA_API_LLM_MODEL=openai/gpt-oss-120b
# Optional: Custom base URL (for ollama or custom endpoints)
# MEMORA_API_LLM_BASE_URL=http://localhost:11434/v1
# Control Plane Configuration
MEMORA_CP_DATAPLANE_API_URL=http://localhost:8080
EOF
LLM Provider Configuration
The system supports multiple LLM providers with separate configuration for main operations and benchmark evaluation:
Main LLM (for memory operations)
Groq (default, fast inference):
LLM_PROVIDER=groq
LLM_API_KEY=your_groq_api_key
OpenAI:
LLM_PROVIDER=openai
LLM_API_KEY=your_openai_api_key
Ollama (local, no API key needed):
LLM_PROVIDER=ollama
LLM_BASE_URL=http://localhost:11434/v1 # Default, can be customized
Judge LLM (for benchmark evaluation)
Benchmarks can use a separate LLM for evaluation (e.g., using Groq for fast answer generation but OpenAI GPT-4 for accurate judging):
# If not set, falls back to main LLM configuration
JUDGE_LLM_PROVIDER=openai
JUDGE_LLM_API_KEY=your_openai_api_key
# JUDGE_LLM_BASE_URL=https://api.custom.com/v1 # Optional
Example: Fast generation, accurate judging:
# Main LLM - Groq for speed
LLM_PROVIDER=groq
LLM_API_KEY=your_groq_key
# Judge LLM - OpenAI GPT-4 for accuracy
JUDGE_LLM_PROVIDER=openai
JUDGE_LLM_API_KEY=your_openai_key
Local Development
# Start all services with Docker (PostgreSQL, API, Control Plane)
cd ../docker
./start.sh
# Or start services individually:
# 1. Start PostgreSQL only
# (then migrations run automatically when API starts)
# 2. Start the server with local environment
./scripts/start-server.sh --env local
# Stop all Docker services
cd ../docker
./stop.sh
# Erase all data and containers
cd ../docker
./clean.sh
The server will start at http://localhost:8080
API Endpoints:
GET /- Interactive visualization UIPOST /api/memories/batch- Store memoriesPOST /api/search- Search all networksPOST /api/world_search- Search world facts onlyPOST /api/agent_search- Search agent facts onlyPOST /api/opinion_search- Search opinions onlyPOST /api/think- Think and generate contextual answersGET /api/graph- Get graph data for visualizationGET /api/agents- List all agentsPUT /api/agents/{agent_id}- Create/update agent with personalityGET /api/agents/{agent_id}/profile- Get agent profilePUT /api/agents/{agent_id}/profile- Update personality traitsPOST /api/agents/{agent_id}/background- Merge agent background
API Examples (curl)
Create/Update Agent
# Create or update an agent with personality and background
curl -X PUT http://localhost:8080/api/agents/alice_agent \
-H "Content-Type: application/json" \
-d '{
"personality": {
"openness": 0.8,
"conscientiousness": 0.6,
"extraversion": 0.5,
"agreeableness": 0.7,
"neuroticism": 0.3,
"bias_strength": 0.7
},
"background": "I am a creative software engineer with 10 years of startup experience"
}'
# Create agent with just background (personality defaults to 0.5 for all traits)
curl -X PUT http://localhost:8080/api/agents/bob_agent \
-H "Content-Type: application/json" \
-d '{
"background": "I am a data scientist interested in machine learning"
}'
Response:
{
"agent_id": "alice_agent",
"personality": {
"openness": 0.8,
"conscientiousness": 0.6,
"extraversion": 0.5,
"agreeableness": 0.7,
"neuroticism": 0.3,
"bias_strength": 0.7
},
"background": "I am a creative software engineer with 10 years of startup experience"
}
Store Memories
# Store memories for an agent
curl -X POST http://localhost:8080/api/memories/batch \
-H "Content-Type: application/json" \
-d '{
"agent_id": "alice_agent",
"items": [
{
"content": "Alice works at Google as a software engineer. She joined last year and focuses on machine learning infrastructure.",
"context": "career discussion",
"event_date": "2024-01-15T10:00:00Z"
},
{
"content": "Alice loves hiking in Yosemite National Park. She goes every weekend and has climbed Half Dome three times.",
"context": "hobby conversation"
}
],
"document_id": "conversation_001"
}'
Response:
{
"success": true,
"message": "Successfully stored 2 memory items",
"agent_id": "alice_agent",
"document_id": "conversation_001",
"items_count": 2
}
Search Memories
# Search across all networks
curl -X POST http://localhost:8080/api/search \
-H "Content-Type: application/json" \
-d '{
"agent_id": "alice_agent",
"query": "What does Alice do?",
"thinking_budget": 100,
"top_k": 10,
"trace": false
}'
Response:
{
"results": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"text": "Alice works at Google as a software engineer",
"context": "career discussion",
"event_date": "2024-01-15T10:00:00Z",
"weight": 0.95,
"fact_type": "world"
},
{
"id": "550e8400-e29b-41d4-a716-446655440001",
"text": "Alice joined Google last year",
"weight": 0.87,
"fact_type": "world"
}
],
"trace": null
}
Temporal Queries
The system automatically detects temporal constraints and activates temporal graph retrieval:
# Temporal query - automatically uses 4-way retrieval with temporal graph
curl -X POST http://localhost:8080/api/search \
-H "Content-Type: application/json" \
-d '{
"agent_id": "alice_agent",
"query": "What did Alice do last spring?",
"thinking_budget": 100,
"top_k": 10
}'
Supported temporal expressions:
- Seasons: "last spring", "this summer", "winter 2024"
- Months: "in June", "last March", "this November"
- Relative: "last year", "last month", "last week"
- Ranges: "between March and May"
Think and Generate Answer
# Think operation: combines agent identity, world knowledge, and opinions
curl -X POST http://localhost:8080/api/think \
-H "Content-Type: application/json" \
-d '{
"agent_id": "alice_agent",
"query": "What do you know about Alice?",
"thinking_budget": 50,
"top_k": 10
}'
Response:
{
"text": "Alice is a software engineer at Google who joined last year. She specializes in machine learning infrastructure. In her free time, she's an avid hiker who frequents Yosemite National Park on weekends and has climbed Half Dome three times.",
"based_on": {
"world": [
{
"text": "Alice works at Google as a software engineer",
"weight": 0.95,
"id": "550e8400-e29b-41d4-a716-446655440000"
},
{
"text": "Alice loves hiking in Yosemite National Park",
"weight": 0.89,
"id": "550e8400-e29b-41d4-a716-446655440002"
}
],
"agent": [],
"opinion": []
},
"new_opinions": []
}
CLI Usage
The Memora CLI provides command-line access to memory operations and agent management:
Memory Operations:
# Store a memory
memora put <agent_id> "Alice works at Google"
# Search memories
memora search <agent_id> "What does Alice do?" --budget 100
# Think (reasoning with opinions)
memora think <agent_id> "What do you think about remote work?" -v
Agent Management:
# View agent profile
memora profile <agent_id>
# Update personality traits (all required)
memora set-personality <agent_id> \
--openness 0.8 \
--conscientiousness 0.6 \
--extraversion 0.5 \
--agreeableness 0.7 \
--neuroticism 0.3 \
--bias-strength 0.7
# Add/merge background
memora background <agent_id> "I was born in Texas"
# List all agents
memora agents
Output Formats:
# Pretty output (default)
memora search <agent_id> "query"
# JSON output
memora search <agent_id> "query" -o json
# YAML output
memora search <agent_id> "query" -o yaml
# Verbose mode (show requests/responses)
memora search <agent_id> "query" -v
OpenAI Client Wrapper (memora-openai)
The memora-openai package provides a drop-in replacement for the OpenAI Python client that automatically integrates with Memora. It transparently stores conversations and injects relevant memories into prompts.
Installation
cd memora-openai
uv pip install -e .
Usage
from memora_openai import configure, OpenAI
# Configure Memora integration once
configure(
memora_api_url="http://localhost:8000",
agent_id="my-agent",
store_conversations=True, # Store conversations to Memora
inject_memories=True, # Inject relevant memories into prompts
)
# Use OpenAI client as normal - Memora integration happens automatically
client = OpenAI(api_key="sk-...")
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "What did we discuss about AI?"}]
)
Async Support
from memora_openai import configure, AsyncOpenAI
configure(
memora_api_url="http://localhost:8000",
agent_id="my-agent",
)
client = AsyncOpenAI(api_key="sk-...")
response = await client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Tell me about my preferences"}]
)
Features
- Automatic Memory Injection: Relevant memories are automatically retrieved and injected as system messages before each API call
- Conversation Storage: All conversations are automatically stored to Memora for future retrieval
- Zero Code Changes: Works as a drop-in replacement for
openai.OpenAIandopenai.AsyncOpenAI - Configurable: Control memory search budget, context window, and enable/disable features
- Transparent: Original OpenAI API responses are returned unchanged
Configuration Options
configure(
memora_api_url="http://localhost:8000", # Memora API URL
agent_id="my-agent", # Agent identifier (required)
store_conversations=True, # Store conversations
inject_memories=True, # Inject memories
document_id="session-123", # Optional: Group conversations by document ID
enabled=True, # Master switch
)
See memora-openai/README.md for full documentation and examples.
Running Benchmarks
The system includes two benchmarks for evaluating memory retrieval quality:
LoComo Benchmark
Long-term Conversational Memory benchmark - evaluates multi-turn conversation understanding:
# Run full benchmark with think API (uses local env by default)
./scripts/benchmarks/run-locomo.sh --use-think
# Run with dev environment
./scripts/benchmarks/run-locomo.sh --use-think --env dev
# Run with limits for quick testing
./scripts/benchmarks/run-locomo.sh --use-think --max-conversations 5 --max-questions 3
# Skip ingestion (use existing data)
./scripts/benchmarks/run-locomo.sh --use-think --skip-ingestion
LongMemEval Benchmark
Long-term Memory Evaluation benchmark - tests memory retention and retrieval:
# Run full benchmark (uses local env by default)
./scripts/benchmarks/run-longmemeval.sh
# Run with dev environment
./scripts/benchmarks/run-longmemeval.sh --env dev
# Run with arguments (pass any args directly)
./scripts/benchmarks/run-longmemeval.sh --max-instances 10 --max-questions 5
# Skip ingestion
./scripts/benchmarks/run-longmemeval.sh --skip-ingestion
Visualizer
View benchmark results in an interactive web interface:
# Start the visualizer server
./scripts/benchmarks/start-visualizer.sh
The visualizer will be available at http://localhost:8001
Benchmark Results: Results are saved to benchmark_results.json in each benchmark directory with metrics including accuracy, F1 score, and per-question performance.
License
MIT