Provide a generic memory method for domain-specific agents that must reason over:
- semantic similarity (what text is relevant), and
- relation topology (how engineering concepts connect), and
- temporal scope (when a fact occurred, not just when it was ingested).
The MVP uses a hybrid retrieval pipeline:
- Semantic retrieval via lexical BM25-like scoring (
LexicalSemanticIndex). - Graph retrieval via multi-hop entity relation traversal (
KnowledgeGraph). - Temporal retrieval via inferred or caller-provided occurrence windows.
- Policy ranking to combine semantic + graph + temporal + recency + confidence.
Final score:
score = 0.42 * semantic + 0.25 * graph + 0.15 * temporal + 0.10 * recency + 0.07 * confidence
These are the default weights after normalization (raw defaults: 0.50, 0.30, 0.18, 0.12, 0.08). Weights are always normalized at query time so custom values don't need to sum to 1.0.
Alternative production rankers (planned):
- Weighted RRF style fusion:
S(d)=sum(w_m/(k+rank_m(d))) + wt*temporal + wr*recency + wc*confidence - Calibrated additive fusion:
p(d)=sigmoid(b0 + bv*vec + bl*lex + bg*graph + bt*temporal + br*recency + bc*confidence)
KnowledgeRecord: memory unit (text, source, domain, confidence, tags, metadata, timestamp, optional occurrence window)Relation: directed typed edge (source_entity,relation,target_entity,weight)
- Insert/Update record in semantic index.
- Extract entities from text (capitalized tokens, snake_case, numeric/technical tokens).
- Extract weak relations from co-occurrence and cues (
depends_on,uses,implements,owns). - Infer an occurrence window when the text contains simple temporal cues, or accept caller-provided occurrence fields.
- Attach entities to record and add graph edges.
- Persist validity window (
valid_from, optionalvalid_to) for future as-of queries.
Optional explicit synthesis:
- Combine related facts into a provenance-backed
observationrecord. - Store derived record IDs in metadata so observations remain inspectable and reversible.
- Score prompt against semantic index.
- Extract query entities and traverse graph up to
hops. - Infer a query time range when the prompt is time-scoped.
- Normalize semantic/graph/temporal scores.
- Add recency/confidence priors.
- Apply namespace policy constraints when configured: hops, confidence floor, source allowlist, staged visibility.
- Optionally rerank the top results with a second-stage reranker.
- Filter invalid/superseded memories for current-time queries.
- Return top-k records with rationale tags.
ingest-service: append records, normalize metadata, emit extraction jobsextract-service: entities, relations, contradiction candidatesretrieval-service: lexical/vector retrieval + graph expansion + fusionpolicy-service: trust thresholds, source allowlists, namespace policies, conflict policysynthesis-service: promote repeated facts into observations or patterns with provenancememory-api: write/query/invalidate/as-of query endpoints
This package currently implements the core logic in-process to stay lightweight, but interfaces are shaped to split into services later.
- Works without a specific vector DB or graph DB.
- Can be upgraded to embeddings and persistent graph backends with no API changes.
- Separation of concerns allows environment-specific storage adapters.
The MCP server (context-fabrica-mcp) exposes HybridMemoryStore over JSON-RPC 2.0 via stdio:
Agent (Claude Code, Cursor, etc.)
| stdin/stdout (JSON-RPC 2.0)
context-fabrica-mcp
| in-process calls
HybridMemoryStore (unified engine)
| embedding search | BM25 + graph (in-memory)
SQLite or Postgres (durable) ScoringPipeline (lazy bootstrap)
BM25 and graph indexes bootstrap lazily from the store on first query. Embedding search delegates to the store (SQLite cosine or pgvector HNSW). Every mutation persists immediately — no hydration step needed.
Tools: remember, recall, synthesize, promote, invalidate, supersede, related, history.
- Replace lexical index with embedding store (FAISS/LanceDB/pgvector).
- Replace in-memory graph with Neo4j, Memgraph, or NetworkX-backed persistence.
- Replace deterministic reranking with a cross-encoder or hosted reranker.
- Add richer temporal extraction beyond the current lightweight parser.
- Add source verification and conflict detection for trust calibration.
- Add memory lifecycle policies (decay, consolidation, archival).
- GraphRAG architecture:
https://microsoft.github.io/graphrag/index/architecture/ - Graphiti repository:
https://github.com/getzep/graphiti - Neo4j GraphRAG hybrid retriever:
https://github.com/neo4j/neo4j-graphrag-python - Mem0 graph memory patterns:
https://github.com/mem0ai/mem0 - Elasticsearch RRF docs:
https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion