A distributed hybrid vector and graph database designed as an LLM long-term memory backend with human visibility layers. Built in Zig with Raft consensus for reliability, MCP integration for LLM access, and Cypher-like queries for human exploration.
Memora serves as a dual-purpose memory architecture:
π€ For LLMs: High-performance semantic memory store via Model Context Protocol (MCP)
π¨βπ» For Humans: Transparent, queryable knowledge graph with web UI and audit capabilities
Feature | Description |
---|---|
π Feedback Loop | LLMs read/write memories with purpose; humans inspect, audit, and correct |
π Visibility + Explainability | Trace answers back to source paragraphs, events, relationships |
π Shared World Model | Graph shows how concepts connect (not just stored) |
π§ Long-Term Memory API | LLM stores observations, experiences, decisions |
π Memory Audit | Devs and users can query what the LLM "knows" |
π§© Cross-Session Coherence | Persistent memory survives across prompts/sessions |
π Traceable Retrieval | Responses tied to graph+vector provenance |
π§βπ» Human/LLM Co-curation | Humans can shape or clean memory alongside the model |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Memora System β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Access Layer β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
β β MCP Server β β Web UI β β Cypher-like QL β β
β β (LLM Interface) β β (Human Insight) β β (Dev Queries) β β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Consensus Layer (Raft Protocol) β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
β β Leader Election β β Log Replication β β Fault Tolerance β β
β β (150-300ms) β β (TCP + CRC32) β β (Majority) β β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Memory Layer β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
β β Concept Graph β β Semantic Vectors β β Memory Cache β β
β β (Knowledge Web) β β (Similarity) β β (LRU + LFU) β β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Storage Layer β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
β β Graph Index β β Vector Index β β Experience Log β β
β β (Memory-Mapped) β β (HNSW Structure) β β (Replicated) β β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Persistence Layer β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
β β Memory Snapshotsβ β Network Protocol β β S3 Sync β β
β β (Event Sourcing)β β (Binary + CRC32) β β (Snapshots) β β
β βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Method | Endpoint | Description |
---|---|---|
GET |
/api/v1/health |
Health check and cluster status |
GET |
/api/v1/metrics |
Database metrics and statistics |
POST |
/api/v1/nodes |
Insert a new node |
GET |
/api/v1/nodes/:id |
Get node information |
GET |
/api/v1/nodes/:id/related |
Get related nodes (graph traversal) |
POST |
/api/v1/edges |
Insert a new edge |
POST |
/api/v1/vectors |
Insert a new vector |
GET |
/api/v1/vectors/:id/similar |
Get similar vectors |
POST |
/api/v1/batch |
Batch insert nodes, edges, and vectors |
POST |
/api/v1/query/hybrid |
Execute hybrid graph+vector queries |
POST |
/api/v1/snapshot |
Create a database snapshot |
# Health check and memory stats
curl http://localhost:8080/api/v1/health
# Store data
curl -X POST http://localhost:8080/api/v1/nodes \
-H "Content-Type: application/json" \
-d '{"id": 100, "label": "UserPreference"}'
# Query relationships
curl http://localhost:8080/api/v1/nodes/1/related
# Vector similarity
curl http://localhost:8080/api/v1/vectors/1/similar
# Hybrid queries
curl -X POST http://localhost:8080/api/v1/query/hybrid \
-H "Content-Type: application/json" \
-d '{"node_id": 1, "depth": 2, "top_k": 5}'
# Start MCP server
zig build mcp-server --port 9090
# LLMs connect via MCP protocol
# Supports all MCP v1.0 capabilities:
# - Resource discovery
# - Tool invocation
# - Streaming responses
# - Bidirectional communication
- Zig 0.14+ - Install Zig
- MCP-compatible LLM - Claude, GPT-4, or custom implementation
# Clone Memora
git clone <repo-url> memora
cd memora
# Build and start HTTP server
zig build http-server
# Or start MCP server for LLM integration
zig build mcp-server
# Servers run on localhost:8080 (HTTP) and localhost:9090 (MCP)
const std = @import("std");
const Memora = @import("src/main.zig").Memora;
const types = @import("src/types.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const config = Memora.MemoraConfig{
.data_path = "memora_data",
.enable_persistent_indexes = true,
};
var db = try Memora.init(allocator, config);
defer db.deinit();
// Store knowledge as nodes, edges, vectors
try db.insertNode(types.Node.init(1, "UserPreference"));
try db.insertEdge(types.Edge.init(1, 2, types.EdgeKind.related));
const related = try db.queryRelated(1, 2);
defer related.deinit();
}
// Node: Graph vertex with ID and label
const Node = packed struct {
id: u64,
label: [32]u8,
};
// Edge: Graph connection with relationship type
const Edge = packed struct {
from: u64,
to: u64,
kind: u8, // EdgeKind enum value
};
// Vector: 128-dimensional embedding
const Vector = packed struct {
id: u64,
dims: [128]f32,
};
const EdgeKind = enum(u8) {
owns = 0,
links = 1,
related = 2,
child_of = 3,
similar_to = 4,
};
// Find nodes within N hops
const related = try db.queryRelated(start_node_id, depth);
// Hybrid graph+vector queries
const hybrid_result = try db.queryHybrid(start_node_id, depth, top_k);
defer hybrid_result.deinit();
// Find K most similar vectors
const similar = try db.querySimilar(vector_id, top_k);
memora/
βββ metadata/
β βββ snapshot-000001.json
β βββ snapshot-000002.json
β βββ snapshot-000003.json
βββ vectors/
β βββ vec-000001.blob # Binary vector data
β βββ vec-000002.blob
β βββ vec-000003.blob
βββ nodes/
β βββ node-000001.json # JSON node data
β βββ node-000002.json
β βββ node-000003.json
βββ edges/
β βββ edge-000001.json # JSON edge data
β βββ edge-000002.json
β βββ edge-000003.json
βββ memora.log # Append-only binary log
# Start 3-node cluster
# Node 1 (Leader)
zig build run-distributed -- --node-id=1 --port=8001
# Node 2 (Follower)
zig build run-distributed -- --node-id=2 --port=8001
# Node 3 (Follower)
zig build run-distributed -- --node-id=3 --port=8001
- Strong Consistency: All writes replicated via Raft consensus
- Read Scaling: Can read from any node for performance
- Partition Tolerance: Continues operating with majority of nodes
- Automatic Recovery: Failed nodes catch up automatically when rejoining
# Run all tests
zig build test-all
# Test specific components
zig build test-raft # Distributed consensus tests
zig build test-partitioning # Data partitioning and consistent hashing tests
zig build test # Core database tests
zig build test-http-api # HTTP REST API tests
# Fuzzing campaigns
zig build fuzz-quick # Quick fuzzing (50 iterations)
zig build fuzz-stress # Stress testing with large datasets
# Run distributed demo
zig build demo-distributed # Interactive cluster demonstration
zig build gossip-demo # Automatic node discovery demo
Operation | Single Node | 3-Node Cluster |
---|---|---|
Node Insert | ~200ΞΌs | ~2ms |
Vector Query | ~500ΞΌs | ~500ΞΌs |
Graph Traversal | ~1ms | ~1ms |
Hybrid Query | ~2ms | ~2ms |
- Nodes/Vectors: Tested with 100K+ items
- Concurrent Connections: HTTP server handles 1000+ connections
- Memory Usage: Efficient memory-mapped indexes
- Storage: Compressed snapshots with S3 sync
Core database infrastructure with deterministic, append-only architecture
- β Graph Database Core - Node/edge storage with adjacency lists and HNSW vector indexing
- β Vector Search Engine - 128-dimensional embeddings with cosine similarity and O(log n) performance
- β Deterministic Database - Append-only WAL, atomic transactions, snapshot consistency
- β Query Optimization Engine - Intelligent query planning and caching
- β Caching System - High-performance memory access with LRU/LFU policies
- β Parallel Processing System - Multi-threaded operations with load balancing
- β Memory-Mapped Persistent Indexes - Instant startup via disk-backed indexes
- β HTTP REST API - Production-ready web API for programmatic access
- β Monitoring & Metrics - Comprehensive operation observability
- β Advanced Configuration System - Production-ready configuration management
Semantic memory types optimized for LLM workflows instead of generic nodes
- β LLM Memory Data Models - 10 semantic types: experience, concept, fact, decision, observation, preference, context, skill, intention, emotion
- β Confidence & Importance Tracking - 5-level granular metadata for memory relevance and reliability
- β Memory Sources & Provenance - Track origin: user_input, llm_inference, system_observation, external_api, computed
- β Semantic Relationships - 8 relationship types: similar_to, caused_by, supports, contradicts, co_occurred, sequence, contains, derives_from
- β LLM Session Management - Group memories by conversation/context with metadata tracking
- β Advanced Memory Querying - Filter by type, confidence, importance, session, time ranges
- β Model Context Protocol (MCP) Server - Native MCP v2.0 implementation with semantic memory tools
- β Memory Statistics & Analytics - Distribution tracking and usage patterns
Demo: Run zig build llm-memory-demo
to see semantic memory storage and retrieval
Automatic node discovery and cluster formation without manual configuration
- β Gossip Protocol Implementation - Epidemic-style node discovery with failure detection
- β Automatic Bootstrap - Zero-configuration cluster formation using seed nodes
- β Node Health Monitoring - Heartbeat-based failure detection and recovery
- β Dynamic Membership - Nodes can join/leave clusters automatically
- β Raft Integration - Discovered nodes automatically form Raft consensus clusters
- β Raft Protocol Implementation - Leader election, log replication, membership changes
- β Node Discovery - Automatic cluster formation and health monitoring
- β Data Partitioning - Consistent hashing for horizontal scaling with virtual nodes, load balancing, and automatic rebalancing
- β Failover & Recovery - Automatic leader failover, node recovery, state synchronization, and data repair
- β Conflict Resolution - Split-brain protection, vector clock conflict detection, and network partition handling
Tools for humans to understand and manage LLM memory systems
- MemQL Query Language - Cypher-like syntax for memory exploration and debugging
- Web UI Memory Dashboard - Visual memory timeline, concept graphs, decision audit trails
- Memory Audit & Curation Tools - Human interfaces for inspecting and correcting LLM memories
- LLM Decision Provenance Tracking - Trace responses back to specific memory evidence
Enterprise-grade memory management and monitoring
- Structured Memory Logging - Professional debugging and audit trails for memory operations
- Memory Lifecycle Management - Automatic cleanup, archival, and importance-based retention
- Multi-Tenant Memory - Isolated memory spaces for different LLMs/users/projects
- Memory Analytics & Insights - Understanding LLM learning patterns and memory utilization
Next-generation semantic memory capabilities
- Memory Compression & Summarization - Intelligent memory consolidation for long-term storage
- Cross-Model Memory Sharing - Secure memory exchange between different LLM instances
- Temporal Memory Reasoning - Time-aware memory retrieval and concept evolution tracking
- Memory Contradiction Detection - Identify and resolve conflicting memories automatically
Massive scale deployment and bulletproof reliability
- Horizontal Memory Sharding - Distribute massive memory datasets across nodes
- Real-time Memory Replication - Writer-reader replication with memory consistency guarantees
- Memory Backup & Recovery - Point-in-time memory restoration and disaster recovery
- Advanced Memory Security - Encryption, access control, and memory privacy protection
- π Long-term Conversational Memory - Remember user preferences, context, and history across sessions
- π§ Knowledge Accumulation - Build persistent knowledge from multiple interactions and sources
- π Contextual Decision Making - Access relevant past experiences for better current responses
- π Learning & Adaptation - Track what works, what doesn't, and evolve interaction patterns
- π Cross-Domain Knowledge Transfer - Apply insights from one domain to related problems
- π― Personalization - Adapt communication style and content based on stored user models
- Fork the Memora repository
- Create a feature branch focused on LLM memory capabilities
- Add comprehensive tests including integration scenarios
- Run
zig build test-all
- Submit a pull request with performance benchmarks
- Memory First: All features should enhance LLM memory capabilities
- Human Debuggable: Ensure human developers can inspect and understand stored data
- Deterministic: Memory operations must be reproducible for testing
- Performance Critical: Memory retrieval should be sub-millisecond
- Privacy Aware: Design with multi-tenant memory isolation in mind
This project is licensed under the MIT License - see the LICENSE file for details.
- TigerBeetle: Inspiration for deterministic, high-performance memory backend design
- Model Context Protocol (MCP): Standard for LLM tool integration and memory access
- Apache Iceberg: Inspiration for immutable, time-travel capable memory snapshots
- Zig Community: For the amazing language perfect for system-level LLM infrastructure
Memora: Building the memory layer for the age of AI π§ β¨
Vibe-coded with β€οΈ by AIs and humans, for AIs and humans.