A human-cognition-inspired, zero-LLM-dependency memory and retrieval architecture for AI agents
CogniMem is an innovative AI memory system that does not rely on any large language model. By simulating the brain's "associative thinking" and "hierarchical memory" mechanisms, it achieves 84.2% keyword hit rate and 26.4% exact match hit rate on the LoCoMo long-term dialogue benchmark, surpassing all publicly available zero-LLM solutions and approaching the performance of production systems that rely on GPT-4-level models.
- Core Features
- Architecture Overview
- Core Innovations
- Benchmark Results
- Quick Start
- Project Structure
- Key Module Details
- Comparison with Competitors
- Design Philosophy
- Known Limitations
- Roadmap
- Contributing
- π§ Zero LLM Dependency: All retrieval and reasoning are pure statistical algorithms + rule-based systems, with no large model involvement
- π Associative Thinking Architecture: Stores structured entity-relation-entity triples instead of raw text
- π IDF-Weighted Retrieval: Automatically identifies rare vs. frequent words and dynamically adjusts retrieval weights
- β° Temporal Normalization: Automatically converts relative time expressions like "yesterday", "last week" into absolute dates
- πΈοΈ Spreading Activation: Starting from seed entities, associates indirectly related memories along the graph structure
- π Three-Layer Triples: Event layer (raw evidence) + Knowledge layer (graph relations) + Temporal layer (absolute dates)
- π± Curiosity-Driven: Actively identifies knowledge gaps and generates exploratory questions
- πΎ Local Persistence: Based on SQLite, zero external dependencies, fully offline capable
- π¬ Reproducible Benchmarks: All performance data can be reproduced via open-source scripts
CogniMem is built on a four-layer cognitive pipeline, backed by three persistent memory stores and a six-path hybrid retrieval system.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Input β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 1 Β· Perception & Input Gate β
β ββ 6-dim scoring: importance / confidence / priority / β
β β timeliness / contradiction / relevance β
β ββ Filters noise; drops input below threshold β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 2 Β· Engram Knowledge Lookup (O(1) cache) β
β ββ Hash key-value cache; repeated queries return instantly β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 3 Β· HySparse Hybrid Encoding (Linear O(n)) β
β ββ Each block: 1 Full Attn + N Sparse Attn β
β ββ Full: generates top-k indices + KV Cache β
β ββ Sparse: reuses KV, computes local window + global sampling β
β β 5Γ faster, 3Γ less memory than full attention @1000 tokens β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 4 Β· Liquid Reasoning Engine (Liquid CfC, O(1)) β
β ββ Liquid time-constant network; no KV Cache growth β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Triple Extraction & Hierarchical Storage β
β ββ β Event (speaker, said, <sentence>) β evidence β
β ββ β‘ Knowledge (subject, predicate, object) β graph edge β
β ββ β’ Temporal (speaker, event_date, date) β abs. time β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Three-Store Persistent Memory β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β Episodic β β Semantic β β Working β β
β β SQLite β β Graph β β LRU Buffer β β
β β (episodes) β β (triples) β β (deque) β β
β β + chunks β β + vec idx β β capacity=10β β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Query β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Query Understanding β
β ββ Entity extraction Β· Temporal signal Β· Intent Β· Expansionβ
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
ββββββββββββββββββ΄βββββββββββββββββ
βΌ βΌ
βββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β Aggregator (optional) β β Six-Path Hybrid Recall β
β ββ SUM / TEMPORAL β β ββ β Entity graph β
β ββ COUNT: disabled β β ββ β‘ Spreading activationβ
β ββ If high-confidence, β β ββ β’ Chunk semantic rank β
β return directly β β ββ β£ Vector semantic β
βββββββββββββββββββββββββββββ β ββ β€ BM25 (optional) β
β ββ β₯ Query decomposition β
ββββββββββββββββ¬βββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β IDF-Weighted Ranking β
β ββ IDF(t) = log((N+1) / (df(t)+1)) + 0.1 β
β Rare words dominate; frequent words downweighted β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RRF Fusion (Reciprocal Rank Fusion) β
β ββ score(d) = Ξ£ weight_i / (k + rank_i(d)) β
β Entity graph 1.2 > Spreading 1.1 > Vector 1.0 > BM25 0.8β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Parent Chunk Replacement / Context Aggregation β
β ββ Fine-grained retrieval β coarse-grained return β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Top-K Memory Segments β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Zero LLM Dependency Β· Pure Stat + Rules β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Memory layer : Associative triples (brain-like) β
β Retrieval layer : IDF statistics + graph spreading β
β Temporal layer : Relative time β absolute date β
β Aggregation layer : Value extraction from segments β
β β
β β CPU only Β· 4GB RAM Β· No GPU required β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
CogniMem does not store raw dialogue text; instead it extracts three types of structured triples:
| Layer | Format | Example | Purpose |
|---|---|---|---|
| Event Layer | (speaker, said, <full sentence>) |
(Caroline, said, "I went to a LGBTQ group yesterday") |
Full-text evidence for retrieval |
| Knowledge Layer | (subject, predicate, object) |
(Caroline, went_to, LGBTQ group) |
Graph edges for spreading activation |
| Temporal Layer | (speaker, event_date, absolute date) |
(Caroline, event_date, "7 May 2023") |
Temporal queries |
Traditional vector retrieval cannot distinguish the importance of "Caroline" (frequent) vs. "LGBTQ" (rare). CogniMem introduces the classic IDF formula from information retrieval:
IDF(t) = log((N + 1) / (df(t) + 1)) + 0.1
N: total number of triplesdf(t): number of triples containing keyword t
Effect: Rare words automatically gain high weight; frequent words (such as speaker names) are downweighted.
Temporal expressions in dialogue are often relative ("yesterday", "last week"), while ground-truth answers require absolute dates. CogniMem uses session timestamps to perform the conversion automatically:
Session time: "1:56 pm on 8 May, 2023" Text: "I went to a LGBTQ support group yesterday" β Normalization Result: "7 May 2023"
Starting from seed entities, activation propagates along the knowledge-layer graph with decay:
Energy propagation formula: E(target) = E(source) Γ decay_factor Γ edge_confidence
decay_factor = 0.5(halves each hop)max_hops = 2(maximum 2 hops)activation_threshold = 0.1(stops propagating below threshold)
| Granularity | Coverage | Purpose |
|---|---|---|
| Turn | 1 dialogue turn | Precise retrieval unit |
| Chunk | 3 dialogue turns (sliding window) | Context-rich unit |
| Parent Chunk | 8 dialogue turns | Large context return (reserved) |
For queries like "how much total X", the aggregator extracts numeric values from multiple retrieved segments and sums them. Pure rule-based, zero LLM dependency.
Current limitation: COUNT-type questions ("how many X") have insufficient accuracy on natural language dialogue, so they are disabled by default.
LoCoMo is a long-term dialogue memory benchmark released at ACL 2024, containing 10 dialogues and 1542 QA pairs, covering single-hop, multi-hop, temporal, and open-domain query types.
Evaluation Metrics:
- Exact Match Hit Rate: The complete string of the ground-truth answer appears in the retrieval results
- Keyword Hit Rate: At least one keyword from the ground-truth answer appears in the retrieval results
Results (zero LLM, CPU-only, no external API calls):
| Version | Exact Match | Keyword Hit |
|---|---|---|
| Pure cognitive baseline (entity graph + vector) | 7.7% | 56.6% |
| + IDF weighting | 13.2% | 65.1% |
| + Temporal normalization | 18.4% | 79.5% |
| + Knowledge layer + spreading activation (current) | 26.4% | 84.2% |
Detailed Data:
- Total QA pairs: 1542
- Exact match hits: 407 (26.4%)
- Keyword hits: 1299 (84.2%)
LongMemEval is a long-term memory benchmark released at ICLR 2025, containing 500 QA pairs covering multi-session reasoning, knowledge updates, temporal reasoning, information extraction, and abstention.
Results (150 samples, zero LLM):
| Category | Exact Match | Keyword Hit |
|---|---|---|
| Overall (150 samples) | 38.0% | 60.7% |
| single-session-user | 48.6% | 67.1% |
| multi-session | 37.1% | 41.9% |
| single-session-preference | 0% | 100% |
Key Finding: The multi-session category requires aggregating values across segments. The retrieval layer can hit 80% of relevant segments but lacks numeric aggregation capability. This issue has been partially alleviated by the aggregator.
# LoCoMo
cd benchmarks
python check_recall.py # full 10 dialogues
# LongMemEval
cd benchmarks/LongMemEval
python cognimem_adapter.py # generate predictions
python eval_retrieval.py # compute metrics- Python 3.10+
- 4GB+ RAM (CPU only, no GPU required)
git clone https://github.com/your-username/CogniMem.git
cd CogniMem
pip install -e .numpy>=1.24.0
pyyaml>=6.0
sentence-transformers>=2.2.0
spacy>=3.7.0
torch>=2.0.0
scikit-learn>=1.3.0Download the spaCy English model:
python -m spacy download en_core_web_smfrom cognimem.core import CogniMemPipeline
import yaml
# Load configuration
with open('config/default_config.yaml', 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
# Initialize pipeline
pipeline = CogniMemPipeline(config)
# Store memory
pipeline.memory.store({
'content': 'I went to a LGBTQ support group yesterday',
'timestamp': 0,
'metadata': {
'speaker': 'Caroline',
'session_time': '1:56 pm on 8 May, 2023'
}
})
# Retrieve
results = pipeline.memory.recall("When did Caroline go to the LGBTQ group?", k=5)
for r in results:
print(f"[{r['source']}] {r['content'][:200]}")Example Output:
[entity_graph] [Date: 7 May 2023] I went to a LGBTQ support group yesterday and it was so powerful.
cd benchmarks
python check_recall.pyCogniMem/
βββ config/
β βββ default_config.yaml # Configuration file
βββ src/
β βββ cognimem/
β βββ core/ # Main pipeline
β β βββ config_manager.py
β β βββ pipeline.py
β βββ layers/ # Four-layer cognitive pipeline
β β βββ engram.py # Knowledge lookup
β β βββ hybrid_encoder.py # Hybrid sparse encoding
β β βββ hybrid_encoder_torch.py # PyTorch version (experimental)
β β βββ input_gate.py # Perception & gate
β β βββ liquid_engine.py # Liquid reasoning engine
β βββ memory/ # Persistent memory system
β β βββ aggregator.py # Lightweight aggregator
β β βββ bm25_retriever.py # BM25 (optional)
β β βββ curiosity.py # Curiosity-driven
β β βββ episodic.py # Episodic memory (hierarchical chunking)
β β βββ fusion.py # RRF fusion
β β βββ persistent_memory.py # Core memory management
β β βββ query_decomposition.py # Query decomposition
β β βββ reranker.py # Reranker (optional)
β β βββ routing.py # Multi-path retrieval routing
β β βββ semantic.py # Semantic memory (graph structure)
β β βββ spreading_activation.py # Spreading activation
β β βββ working_memory.py # Working memory
β βββ models/ # Base models
β β βββ base.py
β β βββ engram_table.py
β β βββ liquid_cell.py
β β βββ small_gate.py
β β βββ sparse_attn.py
β βββ llm/ # LLM integration (optional)
β β βββ base.py
β β βββ huggingface.py
β β βββ ollama.py
β βββ utils/
β β βββ helpers.py
β β βββ logger.py
β β βββ text_processor.py # spaCy wrapper
β βββ demo/
β βββ run_demo.py
βββ benchmarks/ # Benchmark scripts
β βββ check_recall.py # LoCoMo recall benchmark
β βββ evaluate_agent.py # Full agent evaluation
β βββ evaluate_locomo.py
β βββ benchmark_hysparse.py # HySparse performance benchmark
β βββ quality_check.py # HySparse quality check
β βββ diagnose*.py # Diagnostic tools
β βββ test_one_query.py # Single query validation
β βββ LongMemEval/
β βββ cognimem_adapter.py # LongMemEval adapter
β βββ cognimem_adapter_multi.py # multi-session specific
β βββ eval_retrieval.py # Evaluation script
β βββ eval_multi.py
β βββ test_aggregator.py # Aggregator unit tests
β βββ check_predictions.py
βββ tests/ # Unit tests
β βββ test_memory.py
β βββ test_pipeline.py
β βββ test_curiosity.py
β βββ test_engram.py
β βββ test_gate.py
β βββ test_hysparse.py
β βββ test_liquid.py
β βββ test_llm.py
β βββ test_ollama.py
β βββ test_reason.py
β βββ test_torch.py
βββ .gitignore
βββ README.md
βββ requirements.txt
βββ setup.py
Note: benchmarks/locomo/ and benchmarks/LongMemEval/data/ are external datasets that need to be downloaded separately.
_extract_triples is the core method of the system, responsible for decomposing raw dialogue into three types of triples:
def _extract_triples(self, item, episodic_id):
# 1. Temporal normalization β (speaker, event_date, absolute date)
# 2. spaCy dependency parsing + pronoun resolution β (subject, predicate, object)
# 3. Chinese rule extraction β Chinese triples
# 4. Smart fallback β (speaker, said, full sentence)
# 5. Knowledge layer extraction β (subject, verb_lemma, object)_entity_graph_search is the retrieval core:
# 1. Keyword expansion (entities + temporal hint words)
# 2. IDF weighting
# 3. Multi-keyword score accumulation
# 4. Temporal query weighting
# 5. Top-K returnclass SpreadingActivation:
def activate(self, seed_entities):
# BFS traversal with energy decay
# Propagation per edge: E(target) = E(source) Γ 0.5 Γ confidence
# Maximum 2 hopsclass HybridEncoder:
def _hybrid_block_forward(self, seq):
# Each block: 1 Full Attention + N Sparse Attention
# Full: generates top-k token indices and KV Cache
# Sparse: reuses indices and KV, computes only local window + global sampling| System | Keyword Hit Rate | LLM Dependency | Type |
|---|---|---|---|
| Basic vector retrieval | 49.7% | No | Pure vector |
| YourMemory | 59.0% | No | Biological decay memory |
| HippoGraph early | 44.2% | No | Single-turn granularity |
| HippoGraph Hybrid | 65.5% | No | 3-turn chunk |
| CogniMem (this project) | 84.2% | No | Cognitive architecture |
| HippoGraph production | 91.1% | Yes | Full pipeline + LLM |
Key Difference: HippoGraph production relies on LLM for query decomposition and reranking. CogniMem is completely zero-LLM dependent, achieving close to 92% of its performance using only statistics + rules.
CogniMem's design is inspired by observations of human brain cognitive mechanisms:
The brain does not remember conversations verbatim, but extracts "who did what" and "who is related to whom". CogniMem simulates this via knowledge-layer triples.
When hearing "yesterday", the brain automatically computes the absolute date based on the current time. CogniMem simulates this capability via session_time + relative time expressions.
Seeing "Caroline", the brain automatically associates "she recently joined an LGBTQ support group" and "she said she wants to work in psychological counseling". CogniMem simulates this via spreading activation.
The brain consumes only 20W. CogniMem therefore avoids heavyweight components like Transformer rerankers and BM25, insisting on the simplest statistical methods for optimal results.
CogniMem is a prototype system with the following limitations:
"how many X" questions require cross-segment counting. Pure rule-based methods achieve about 40% accuracy on natural language dialogue, so the COUNT aggregator is disabled by default.
SUM aggregator ("how much total X") is effective but narrow in coverage.
Questions requiring calendar calculations such as "what day of the week was before a certain date" or "how many days from today" are currently limited to basic relative time conversion (yesterday/last week).
Current pronoun resolution relies on spaCy's sentence-level analysis; cross-paragraph references (e.g., "she" referring to someone mentioned in a previous paragraph) cannot be handled.
Although the system itself is zero-LLM dependent, the retrieval layer uses sentence-transformers for semantic embeddings. For a purely statistical approach, BM25 could be used instead, but performance would decrease.
- β Four-layer cognitive pipeline
- β Entity graph + IDF-weighted retrieval
- β Temporal normalization
- β Knowledge-layer triples
- β Spreading activation
- β Curiosity-driven
- β Lightweight aggregator (SUM type)
- β‘ Query decomposition (conservative mode)
- β‘ Cross-paragraph pronoun resolution
- β‘ COUNT-type aggregation optimization
- β‘ Memory consolidation (sleep mechanism)
- β‘ Weight-learning liquid reasoning engine
- β‘ RESTful API service
- β‘ Multilingual support
- β‘ End-to-end integration evaluation with real LLMs
All forms of contribution are welcome:
- π Report bugs
- π‘ Propose new features
- π Improve documentation
- π§ͺ Submit benchmark results
- π Add multilingual support
Please open an issue for discussion before submitting a PR.
This project is licensed under the Apache 2.0 License.
- LoCoMo: provided a high-quality long-term dialogue benchmark
- LongMemEval: provided a long-term memory evaluation benchmark
- spaCy: provided reliable NLP foundation
- sentence-transformers: provided semantic embedding support
CogniMem β Using the simplest statistical methods to achieve associative memory closest to the human brain.
"True intelligence lies not in stacking more parameters, but in organizing and using knowledge more intelligently."