Feature: User knowledge graph for relational memory queries
Motivation
The current memory system (memory.json + ChromaDB) stores facts as atomic text blobs. It does this well — automatic extraction, dedup, semantic recall, periodic audit. But because facts are unstructured strings, the assistant can't answer relational questions:
- "Who do I know in Paris?"
- "What companies do my friends work at?"
- "What projects is John involved in?"
These require typed entities and relationships between them, not just fuzzy text retrieval. Today the only path is to hope the right substrings appear in the same memory entry, which they often don't.
Proposal
Add a typed knowledge graph as a secondary index alongside the existing flat memory store. The graph is populated by an LLM extraction pass that runs in parallel with the existing flat extractor — same chat slice, same trigger cadence — so there's no extra chat-loop overhead and the JSON store remains the source of truth.
Stack
- Kuzu — embedded, file-based, openCypher. Persists to
data/graph/next todata/chroma/. No server process, no JVM, MIT-licensed. - Rejected alternatives:
- Neo4j — needs a Java server daemon; too heavy for a self-hosted personal app.
- NetworkX — in-memory only, no persistence, no query language.
- SQLite + recursive CTEs — works but verbose for multi-hop traversal; happy to discuss if maintainers prefer one less dependency.
Schema
Nodes (every node carries owner for multi-user isolation):
| Label | Purpose |
|---|---|
User |
Root node — one per owner |
Person |
People the user knows |
Place |
Cities, countries, neighborhoods |
Organization |
Companies, schools, groups |
Concept |
Interests, topics |
Goal |
Aspirations, with optional deadline |
Project |
Things the user is working on |
Relationships (typed, with source_memory_id provenance on every edge):
KNOWS User|Person -> Person
LIVES_IN User|Person -> Place
WORKS_AT User|Person -> Organization
INTERESTED_IN User -> Concept
HAS_GOAL User -> Goal
WORKING_ON User|Person -> Project
RELATED_TO Person -> PersonSchema is deliberately small for Phase 1. Open to opening a generic RELATES { label: STRING } edge if maintainers want more flexibility.
Pipeline
- After each chat turn (same
extract_and_storehook that runs today, every 4th message pair), the existing flat extractor runs unchanged. - A new triple-extraction LLM pass runs on the same message slice and emits validated typed triples.
- Triples are ingested into Kuzu. Each edge records the originating memory id so:
DELETE /api/memory/{id}cascades to graph edges.- Future audits can re-evaluate edges against their source.
Degradation
Every layer is a no-op when kuzu is missing or the DB is unhealthy:
GraphStorecatchesImportErrorat init, reportshealthy=False.- Triple extraction is skipped if
graph_store is None— flat-memory pipeline is untouched. /api/graph/*returns503instead of crashing.
Existing users with no kuzu installed see zero behavior change.
API surface
GET /api/graph/stats— per-label node counts, per-relation edge countsGET /api/graph/entities?label=Person&limit=200— list known entitiesGET /api/graph/neighborhood?depth=2&limit=50— triples around the User node- New script:
python -m scripts.bootstrap_graph— one-shot import of existingmemory.json(supports--dry-run,--owner,--batch-size) - New dep:
kuzuinrequirements.txt
Phased roadmap
Splitting into reviewable chunks. Only Phase 1 is on the table now; later phases are scoped here so the design choices in Phase 1 are obviously load-bearing rather than over-engineered.
| Phase | Scope |
|---|---|
| 1 (this issue) | Storage + extraction + write-side API + bootstrap script |
| 2 | Embedding-based entity disambiguation (two distinct "John"s currently merge by normalized name) |
| 3 | Graph-aware retrieval — inject a 1–2 hop subgraph into chat context, gated by a per-user setting |
| 4 | UI: force-directed graph view under Memory → Graph, manual edit/merge |
| 5 | Audit & decay: re-evaluate edges on the existing audit cadence, flag contradictions |
Phase 3 is where the feature actually starts paying off — Phase 1+2 build the foundation.
Open questions for maintainers
- Kuzu acceptable as a dependency? If you'd prefer no graph engine, I can rework Phase 1 on SQLite with recursive CTEs — slower for deep traversal, but no new dep.
- Schema rigidity — keep the 7-relation typed set, or open a generic
RELATES { label }for free-form edges? - Provenance granularity — currently one
source_memory_idper edge. Should we move to aMemorynode withMENTIONSedges for true many-to-many provenance, or wait until a use case appears?
Status
Implementation is already drafted in #1954 (opened before I caught the issue-first rule — apologies, will follow the flow going forward). Happy to close that PR and reopen against this issue once the approach gets a thumbs-up, or revise in place.
Source: odysseus-dev/odysseus