feat: add Apache AGE graph store support#4448
Conversation
Add Apache AGE as a graph store provider for graph memory operations, enabling users to run graph queries on PostgreSQL without a separate graph database. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kartik-mem0
left a comment
There was a problem hiding this comment.
Thanks for this contribution — the test coverage is excellent (62 tests) and the code follows our existing patterns well. A few things to address:
Must fix:
-
get_all()— addLIMITto the Cypher query instead of slicing in Python (results[:limit]). See howgraph_memory.pyandkuzu_memory.pyboth useLIMIT $limitin the query. This matters at scale. -
_delete_entities/_add_entities— fix partial commit risk. Currentlyself.ag.commit()is called inside the loop after each item. If the 2nd of 3 operations fails, the 1st is already committed, leaving the graph in an inconsistent state. Move the commit after the loop completes, or add rollback on failure. -
_merge_node()— combine into a single query. The agent_id and run_id SET clauses (lines 283-292) should be part of the initial MERGE query, not separate round-trips. That's up to 3 queries per node merge when it should be 1.
Nice to have:
- Consider adding a
close()method or__del__to clean up theself.agconnection. - The similarity search logic in
_find_similar_nodeand_search_graph_dbis duplicated — could be extracted into a shared helper.
1. get_all(): use LIMIT in Cypher query instead of Python slicing 2. _delete_entities/_add_entities: single commit after loop with rollback on failure to prevent partial commits 3. _merge_node(): combine agent_id/run_id into single SET query (was up to 3 round-trips, now always 1) 4. Add close() method for connection cleanup 5. Extract _get_similar_nodes() helper to deduplicate similarity logic Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: utkarsh240799 <utkarsh240799@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Description
Add Apache AGE as a graph store provider for mem0's graph memory, providing an open-source PostgreSQL-based alternative to Neo4j. Apache AGE adds graph database capabilities (Cypher queries) to PostgreSQL, letting users run graph + relational + vector operations on a single Postgres instance.
Closes #3292
Type of change
How Has This Been Tested?
62 tests total — 19 unit + 43 end-to-end integration tests, all passing.
Unit tests (
tests/memory/test_apache_age_memory.py— 19 tests)Run without any external dependencies (all mocked):
E2E integration tests (
tests/memory/test_apache_age_e2e.py— 43 tests)Run against a real Apache AGE instance via Docker (
docker run -d -p 15432:5432 apache/age):type(r)queriesget_all, user isolation, limit,delete_all,resetadd()→search()→delete_all()cycle, relationship update (delete old + add new)get_all/delete_allwithagent_idfilter,get_all/delete_allwithrun_idfilteragent_id,_find_similar_nodewithrun_idadd→get_all→search→delete_allcycle scoped by agent_idcreatedtimestamp preserved across mergesTest categories
Files Changed
Usage
Checklist:
Maintainer Checklist