Hexis implements a multi-layered memory system modeled after cognitive science research.
Five memory types (working, episodic, semantic, procedural, strategic) with vector embeddings for similarity search, graph relationships for reasoning, and precomputed neighborhoods for fast retrieval.
Simple RAG systems store text chunks with embeddings and retrieve by similarity. This works for knowledge retrieval but fails to capture:
- Temporal relationships -- what happened before/after
- Causal chains -- what caused what
- Contradictions -- when new information conflicts with existing beliefs
- Importance decay -- not all memories are equally important over time
- Associative recall -- remembering one thing triggers related memories
graph TD
Input[New Information] --> WM[Working Memory]
WM --> |Consolidation| LTM[Long-Term Memory]
subgraph "Long-Term Memory"
LTM --> EM[Episodic Memory]
LTM --> SM[Semantic Memory]
LTM --> PM[Procedural Memory]
LTM --> STM[Strategic Memory]
end
Query[Query/Retrieval] --> |Vector Search| LTM
Query --> |Graph Traversal| LTM
EM ---|Relationships| SM
SM ---|Relationships| PM
PM ---|Relationships| STM
LTM --> |Decay| Archive[Archive/Removal]
WM --> |Cleanup| Archive
-
Working Memory -- temporary buffer (UNLOGGED table for fast writes). Information enters here first. Expires automatically; important items are promoted.
-
Episodic Memory -- events with temporal context, actions, results, and emotional valence. Forms the agent's autobiographical timeline.
-
Semantic Memory -- facts with confidence scores, source tracking, and contradiction management. The agent's knowledge base.
-
Procedural Memory -- step-by-step procedures with success rate tracking. How the agent knows how to do things.
-
Strategic Memory -- patterns with adaptation history. High-level strategies learned from experience.
Vector embeddings (pgvector) provide similarity-based retrieval via HNSW indexes. The get_embedding() function handles generation and caching.
Graph relationships (Apache AGE) enable multi-hop traversal: TEMPORAL_NEXT for narrative sequence, CAUSES for causal reasoning, CONTRADICTS for dialectical tension, SUPPORTS for evidence chains.
Automatic clustering groups memories into thematic clusters with emotional signatures and centroid embeddings.
Precomputed neighborhoods store associative neighbor data for each memory, enabling spreading activation without real-time graph traversal.
Memory decay reduces importance over time with importance-weighted persistence. Permanent memories (from important ingestion) are exempt.
Three performance tiers:
| Path | Method | Speed | Use Case |
|---|---|---|---|
| Hot | fast_recall + neighborhoods + temporal |
Fast | Primary retrieval |
| Warm | Cluster/episode lookups | Medium | Thematic search |
| Cold | Graph traversal (Apache AGE) | Slow | Multi-hop reasoning |
fast_recall() combines:
- Vector similarity -- cosine distance on embeddings
- Neighborhood expansion -- precomputed associative neighbors
- Temporal context -- memories in the same episode get a boost
Beliefs (stored as worldview memories) filter and weight other memories. When new information contradicts existing beliefs, CONTRADICTS graph edges are created and the coherence drive is nudged upward to surface the tension.
- Single
memoriestable -- all memory types share one table with JSONB metadata for type-specific fields. Simpler than a table-per-type approach. - Neighborhoods over real-time graph traversal -- precomputed during maintenance for hot-path speed
- Embeddings as DB implementation detail -- application code never sees vectors
- UNLOGGED working memory -- fast writes since we can afford data loss (it's temporary)
- Tables:
db/*_tables_memory.sql - Functions:
db/*_functions_memory.sql - Neighborhoods:
db/*_functions_maintenance.sql - Python client:
core/cognitive_memory_api.py
- Memory Types -- field-level reference
- Memory Operations -- practical usage
- Database Is the Brain -- why memory is in Postgres