LangMem - Fact-Based AI Memory System
Revolutionary mem0-inspired memory system that extracts individual facts from conversations, provides intelligent deduplication, memory updates, and delivers precision search results with 0.86+ similarity scores.
Fact-Based Memory Storage
Extracts individual facts from conversations using mem0-inspired approach. Converts "Ondrej has a son named Cyril who is 8 years old" into separate memorable facts for precise retrieval.
Precision Search & Updates
Delivers 0.86+ similarity scores for specific queries with intelligent memory deduplication and UPDATE/DELETE actions based on AI analysis of fact conflicts.
MCP Integration Ready
Complete with MCP server for Claude Code integration, n8n workflows, fact-based API endpoints, and Matrix communication system for seamless AI memory management.
System Architecture Overview
Port 8765] --> |Background Tasks| G F[MCP Server
In Progress] --> |MCP Protocol| E end subgraph "AI Processing" G[Llama3.2 Model] --> |Fact Extraction| H I[nomic-embed-text] --> |Vector Embeddings| J H[Fact Processing] --> |ADD/UPDATE/DELETE| K FF[Deduplication Engine] --> |Conflict Resolution| H end subgraph "Storage Layer" J[PostgreSQL
pgvector] --> |Vector Storage| L[(Vector Database)] K[Neo4j Graph] --> |Graph Storage| M[(Graph Database)] N[Ollama Service] --> |Local LLM| O[Local Models] end subgraph "Docker Network" E -.-> P[Host Network] N -.-> P J -.-> P K -.-> P end style E fill:#2563eb,stroke:#1e40af,stroke-width:2px,color:#fff style G fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff style J fill:#22c55e,stroke:#16a34a,stroke-width:2px,color:#fff style K fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#fff style N fill:#ef4444,stroke:#dc2626,stroke-width:2px,color:#fff
Current Status & Features
Fact-Based API - COMPLETE
Revolutionary fact-based memory API inspired by mem0 approach. Extracts individual facts, handles deduplication, and provides precision search.
- β Individual fact extraction from conversations
- β Memory deduplication and conflict resolution
- β ADD/UPDATE/DELETE memory actions
- β 0.86+ similarity scores for specific queries
Memory Intelligence - COMPLETE
Advanced memory intelligence with AI-powered fact extraction, deduplication, and intelligent memory updates inspired by mem0 research.
- β Fact extraction using Llama3.2
- β Intelligent deduplication
- β Memory conflict resolution
- β Dynamic relationship types (IS_SON_OF, FOUNDED_BY, etc.)
Hybrid Search - COMPLETE
Vector similarity search with pgvector and graph traversal with Neo4j for comprehensive context retrieval.
- β Semantic vector search (0.3-0.9 similarity)
- β Graph relationship traversal
- β Combined hybrid results
- β User-scoped searches
MCP Server - COMPLETE
Model Context Protocol server for Claude Code integration with fact-based memory tools and Matrix communication integration.
- β MCP protocol compliance
- β 6 memory tools available
- β Resource indicators
- β Claude Code integration ready
Fact-Based Memory Examples
π§ Fact Extraction
Input: "Ondrej has a son named Cyril who is 8 years old and loves playing soccer"
AI Extracts 5 Facts:
- "Ondrej's son, Cyril, is 8 years old"
- "Cyril loves playing soccer"
- "Cyril attends elementary school in Prague"
- "Ondrej works as a software engineer"
- "Ondrej lives in the Czech Republic"
π Precision Search
Query: "What does Ondrej do for work?"
Results:
- 0.866 similarity: "Ondrej works as a software engineer"
- Previous approach: 0.702 similarity (full content)
- 24% improvement in precision!
π Memory Updates
New Input: "Cyril is now 9 years old"
AI Action:
- UPDATE: "Cyril is currently 9 years old"
- Keeps: "Cyril loves playing soccer"
- No duplication of existing facts
βοΈ Deduplication
Duplicate Input: "Ondrej has a son named Cyril"
AI Action:
- NO_CHANGE: Information already exists
- Prevents redundant storage
- Maintains clean memory database
Technology Stack
| Component | Technology | Purpose | Status |
|---|---|---|---|
| AI Model | Llama3.2 (Ollama) | Fact extraction and memory intelligence | Production |
| Vector Storage | PostgreSQL + pgvector | Semantic search and embedding storage | Production |
| Graph Database | Neo4j | Dynamic relationship storage | Production |
| Embeddings | nomic-embed-text | 768-dimensional vector generation | Production |
| API Framework | FastAPI | REST API with async support | Production |
| MCP Server | Model Context Protocol | Claude Code integration with 6 memory tools | Production |
| Fact Extraction | mem0-inspired approach | Individual fact storage and deduplication | Production |
| Matrix Integration | Matrix API | Direct communication to Home Assistant room | Production |
Performance Metrics
Fact Search
Individual fact similarity search
Search Precision
Similarity scores for specific queries
Fact Extraction
5+ facts extracted per conversation
Memory Actions
ADD/UPDATE/DELETE decision making
Quick Start
# Start the LangMem system
cd /home/klas/langmem-project
docker compose up -d
# Check system health
curl http://localhost:8765/health
# Store memory with fact-based extraction
curl -X POST http://localhost:8765/v1/memories/store \
-H "Authorization: Bearer langmem_api_key_2025" \
-H "Content-Type: application/json" \
-d '{
"content": "Ondrej has a son named Cyril who is 8 years old and loves soccer",
"user_id": "user123",
"session_id": "session1",
"metadata": {"category": "family"}
}'
# Result: 5 individual facts extracted and stored
# Search with precision fact-based results
curl -X POST http://localhost:8765/v1/memories/search \
-H "Authorization: Bearer langmem_api_key_2025" \
-H "Content-Type: application/json" \
-d '{
"query": "How old is Cyril?",
"user_id": "user123",
"limit": 5,
"threshold": 0.5,
"include_graph": true
}'
# Result: 0.759 similarity for "Ondrej's son, Cyril, is 8 years old"
# View relationships in Neo4j Browser
# Visit: http://localhost:7474
# Username: neo4j
# Password: langmem_neo4j_password
# Query: MATCH (n)-[r]->(m) RETURN n, r, m LIMIT 25
Database Access
π Supabase (PostgreSQL)
Table: langmem_documents
Features: Vector storage, metadata, user management
πΈοΈ Neo4j Browser
Username: neo4j
Password: langmem_neo4j_password
Features: Graph visualization, relationship queries
Ready to Explore?
The AI-powered LangMem system is production-ready with automatic relationship extraction and hybrid search capabilities.