The Truth-Aware Memory Engine for AI Agents
Memory Thread (MT) is an event-sourced memory system that gives AI agents the ability to remember facts, handle contradictions, and know when to say "I don't know."
Not a vector database. Not a chatbot. A Truth Maintenance System.
| Feature | Typical AI Memory | Memory Thread |
|---|---|---|
| Data Model | Key-value / Vectors | Events β States |
| Uncertainty | Hidden or none | Explicit (Truth Vectors) |
| Contradictions | Last-write-wins | Higher authority wins |
| "I don't know" | Empty response | Formal None with reason |
| Audit Trail | Logs (maybe) | Immutable event log |
- π Deterministic Replay β Reconstruct any entity's state at any point in time
- π Truth Vectors β 4D truth scoring: (Confidence, Authority, Freshness, Corroboration)
- β±οΈ Memory Decay β Facts fade naturally based on configurable decay curves
- π Contradiction Resolution β Mathematical resolution based on authority
- β‘ High Performance β ~3,600 EPS full pipeline, ~40,000+ transport layer
- Python 3.10+
- PostgreSQL 14+ (event store)
- Qdrant (optional, for vector search)
git clone https://github.com/badalraj9/MemoryThread.git
cd MemoryThread
pip install -r requirements.txt# Create database
psql -U postgres -c "CREATE DATABASE memory_thread_db;"
# Apply schema
psql -U postgres -d memory_thread_db -f memory_thread/db/schema_phase_3_4.sqlexport POSTGRES_USER=postgres
export POSTGRES_PASSWORD=your_password
export POSTGRES_DB=memory_thread_db
export POSTGRES_HOST=localhostuvicorn memory_thread.api.main:app --host 0.0.0.0 --port 8000# Health check
curl http://localhost:8000/health
# Ingest a memory
curl -X POST http://localhost:8000/ingest \
-H "Content-Type: application/json" \
-d '{
"producer_id": "agent-001",
"events": [{
"content": "User prefers dark mode",
"timestamp": "2025-01-01T10:00:00Z"
}]
}'| Endpoint | Method | Description |
|---|---|---|
GET / |
GET | Quick health check |
GET /health |
GET | Detailed health with service statuses |
GET /health/ready |
GET | Kubernetes readiness probe |
GET /health/live |
GET | Kubernetes liveness probe |
GET /metrics |
GET | Prometheus-compatible metrics |
GET /version |
GET | Version and build info |
| Endpoint | Method | Description |
|---|---|---|
POST /register |
POST | Register a producer |
POST /ingest |
POST | Ingest a batch of events |
GET /control/throttle |
GET | Get current system pressure |
| Endpoint | Method | Description |
|---|---|---|
GET /maintenance/proposals |
GET | Get duplicate merge proposals |
POST /maintenance/approve/merge |
POST | Approve a merge proposal |
GET /maintenance/health/stats |
GET | Dashboard metrics |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MEMORY THREAD β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β FastAPI β β ZMQ Fabric β β Slab β β
β β Gateway ββ β (Transport) ββ β Allocator β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β
β βΌ βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β TRUTH MANAGEMENT SYSTEM (TMS) β β
β β β’ Truth Vector Scoring β β
β β β’ State Derivation β β
β β β’ Freshness Decay β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββ β
β β PostgreSQL β β Qdrant β β
β β (Events) β β (Vectors) β β
β ββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Document | Description |
|---|---|
| Unified System Overview | Philosophy and high-level concepts |
| Architectural Layers | Deep dive into system layers |
| Mathematical Specifications | Truth Vector algebra |
| End-to-End Workflow | Data flow from API to storage |
# All tests
pytest tests/ -v
# Specific test suites
pytest tests/test_tms_complete.py -v # TMS logic
pytest tests/test_realworld_scenarios.py -v # AI agent simulation
pytest tests/test_persistence_roundtrip.py -v # Database persistence# Full pipeline benchmark
python benchmarks/benchmark_realworld.py
# Expected results (i5-12450H):
# β’ Event Creation: ~50,000 EPS
# β’ State Derivation: ~30,000 EPS
# β’ Full Pipeline: ~3,600 EPSWe welcome contributions! Please read CONTRIBUTING.md before submitting.
MIT License β see LICENSE for details.
Built for AI that needs to remember. π