Skip to content
monemie113-cellPublic

About

Zero-LLM cognitive memory architecture for AI agents

Resources

Stars

102 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CogniMem

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.

English | δΈ­ζ–‡


πŸ“– Table of Contents

  • Core Features
  • Architecture Overview
  • Core Innovations
  • Benchmark Results
  • Quick Start
  • Project Structure
  • Key Module Details
  • Comparison with Competitors
  • Design Philosophy
  • Known Limitations
  • Roadmap
  • Contributing

✨ Core Features

  • 🧠 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

πŸ—οΈ Architecture Overview

CogniMem is built on a four-layer cognitive pipeline, backed by three persistent memory stores and a six-path hybrid retrieval system.

Part 1 Β· Data Write Path

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Part 2 Β· Data Retrieval Path

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Part 3 Β· Core Design Principles

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                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                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’‘ Core Innovations

1. Three-Layer Triple Structure

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

2. IDF-Weighted Entity Graph Retrieval

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 triples
  • df(t): number of triples containing keyword t

Effect: Rare words automatically gain high weight; frequent words (such as speaker names) are downweighted.

3. Temporal Normalization

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"

4. Spreading Activation

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)

5. Hybrid Chunking Strategy

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)

6. Lightweight Aggregator (Optional)

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.


πŸ“Š Benchmark Results

Dataset 1: LoCoMo

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%)

Dataset 2: LongMemEval

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.

Reproduction

# 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

πŸš€ Quick Start

Requirements

  • Python 3.10+
  • 4GB+ RAM (CPU only, no GPU required)

Installation

git clone https://github.com/your-username/CogniMem.git
cd CogniMem
pip install -e .

Dependencies

numpy>=1.24.0
pyyaml>=6.0
sentence-transformers>=2.2.0
spacy>=3.7.0
torch>=2.0.0
scikit-learn>=1.3.0

Download the spaCy English model:

python -m spacy download en_core_web_sm

Basic Usage

from 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.

Run Benchmarks

cd benchmarks
python check_recall.py

πŸ“ Project Structure

CogniMem/
β”œβ”€β”€ 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.


πŸ”§ Key Module Details

persistent_memory.py: Memory Core

_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 return

spreading_activation.py: Graph Association

class SpreadingActivation:
    def activate(self, seed_entities):
        # BFS traversal with energy decay
        # Propagation per edge: E(target) = E(source) Γ— 0.5 Γ— confidence
        # Maximum 2 hops

hybrid_encoder.py: Linear Complexity Encoding

class 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

πŸ† Comparison with Competitors

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.


🎯 Design Philosophy

CogniMem's design is inspired by observations of human brain cognitive mechanisms:

1. The brain stores "associations", not raw text

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.

2. The brain has temporal memory and automatically normalizes time

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.

3. The brain has associative ability and can infer by analogy

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.

4. The brain does not rely on brute-force computation

The brain consumes only 20W. CogniMem therefore avoids heavyweight components like Transformer rerankers and BM25, insisting on the simplest statistical methods for optimal results.


⚠️ Known Limitations

CogniMem is a prototype system with the following limitations:

1. COUNT-type aggregation problem

"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.

2. Complex temporal reasoning

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).

3. Cross-paragraph pronoun resolution

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.

4. Embedding model dependency

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.


πŸ—ΊοΈ Roadmap

Completed βœ…

  • β˜‘ Four-layer cognitive pipeline
  • β˜‘ Entity graph + IDF-weighted retrieval
  • β˜‘ Temporal normalization
  • β˜‘ Knowledge-layer triples
  • β˜‘ Spreading activation
  • β˜‘ Curiosity-driven
  • β˜‘ Lightweight aggregator (SUM type)

In Progress 🚧

  • β–‘ Query decomposition (conservative mode)
  • β–‘ Cross-paragraph pronoun resolution
  • β–‘ COUNT-type aggregation optimization

Future Plans πŸ“…

  • β–‘ Memory consolidation (sleep mechanism)
  • β–‘ Weight-learning liquid reasoning engine
  • β–‘ RESTful API service
  • β–‘ Multilingual support
  • β–‘ End-to-end integration evaluation with real LLMs

🀝 Contributing

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.


πŸ“„ License

This project is licensed under the Apache 2.0 License.


πŸ™ Acknowledgements

  • 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."

About

Zero-LLM cognitive memory architecture for AI agents

Resources

Stars

102 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages