-
Notifications
You must be signed in to change notification settings - Fork 2
feat: GraphMemory — knowledge-graph backend using NetworkX #20
Copy link
Copy link
Open
Labels
area: memory-backendMemory backend implementations (memory/)Memory backend implementations (memory/)difficulty: intermediateRequires familiarity with the codebaseRequires familiarity with the codebasefeatureNew functionalityNew functionalityhacktoberfestEligible for Hacktoberfest contributionsEligible for Hacktoberfest contributionshelp wantedExtra attention needed - community welcomeExtra attention needed - community welcomepriority: p2-highImportant, target next milestoneImportant, target next milestonestatus: open-for-contributionNot assigned - free to claimNot assigned - free to claim
Metadata
Metadata
Assignees
Labels
area: memory-backendMemory backend implementations (memory/)Memory backend implementations (memory/)difficulty: intermediateRequires familiarity with the codebaseRequires familiarity with the codebasefeatureNew functionalityNew functionalityhacktoberfestEligible for Hacktoberfest contributionsEligible for Hacktoberfest contributionshelp wantedExtra attention needed - community welcomeExtra attention needed - community welcomepriority: p2-highImportant, target next milestoneImportant, target next milestonestatus: open-for-contributionNot assigned - free to claimNot assigned - free to claim
Background
MemoryLens currently benchmarks 7 memory backends (naive, rag, rag_chunked, cascading, summary, entity — graph is missing). A graph-based backend models facts as nodes in a directed graph, making fact-update tracking structurally explicit rather than regex-patched. Relationships like "city changed from Bangalore to Mumbai" become first-class graph edges, which enables richer traversal-based retrieval.
Key files to read first:
memory/base.py— the 3-method interface every backend must implementmemory/entity.py— the closest existing example (regex extraction + key-value store)evaluation/benchmark.py—_make_memory()andVALID_BACKENDS(where to register the backend)docs/adding-a-new-backend.md— the full 4-step contributor guideWhat to build
memory/graph.py— new fileadd_message(role, content, turn):(subject, value)pairs via regex matching injection ("my <key> is <value>") and update ("my <key> has changed to <value>") patterns{subject, value, role, turn, valid=True, valid_from=turn}valid=False, valid_until=turnon all existing nodes with the same subject, then add a fresh nodeentity:<subject>→<node_id>withpredicate="has_value"get_context(query, current_turn):[{"role": "system", "content": "[Graph Memory] my X is Y; ..."}]reset():self.graph.clear()evaluation/benchmark.py"graph"toVALID_BACKENDSGraphMemory()case in_make_memory()main.py--backendshelp text to includegraphgraphusage example in the module docstringrequirements.txt+pyproject.tomlnetworkx>=3.0Acceptance criteria
memory/graph.pyexists andfrom memory.graph import GraphMemoryworksGraphMemoryimplementsadd_message,get_context,resetmatchingBaseMemoryvalid=Falsein the graphpython main.py --backends naive graph cascading --turns 50runs without error"graph"present inVALID_BACKENDStests/test_pipeline.py:test_graph_memory_recall_early()— recall ≥ 75% at T=15test_graph_memory_no_stale_after_update()— old node hasvalid=Falsetest_graph_benchmark_registration()—_make_memory("graph")doesn't raisepytest tests/ -v)Technical hints
networkx.DiGraph()— add it explicitly to requirements even if it's a transitive depf"{subject}:{value}:{turn}"(same style asentity.py)get_contextmust not make any LLM calls — pure graph traversal onlyget_contextmust beList[Dict]with"role"and"content"keysGetting started
See
docs/adding-a-new-backend.mdfor the full 4-step checklist.