export_graph silently ignored page/page_size/memory_type/status/filter
(they were swallowed by **kwargs), so callers always received the full
node list with total_nodes equal to the page length. This broke
pagination and tag filtering for every consumer of POST /get_memory
when the graph backend is postgres.
- translate page/page_size into LIMIT/OFFSET (normalized like neo4j)
- filter memory_type via properties->>'memory_type' = ANY(...)
- default status filter excludes 'deleted'; explicit status list uses ANY
- reuse _build_filter_where_clause so and/or/contains filter DSL works
- count total_nodes with a separate COUNT query before pagination
- resolve edges via subqueries over the full filtered node set (not
page-local ids) so the edge set is complete and consistent across pages
Description
PostgresGraphDB.export_graphacceptedpage,page_size,memory_type,statusandfilteronly through**kwargsand silently ignored them. Its SQL had noLIMIT/OFFSETand no filtering beyonduser_name, andtotal_nodeswas set to the length of the returned page.As a result, when the graph backend is postgres, every consumer of
POST /get_memory(which passes pagination and tag filters down totext_mem.get_all→export_graph) received the full memory list on every page, with an incorrect total — pagination and tag filtering were both broken.This aligns the Postgres implementation with the existing Neo4j implementation (
Neo4jGraphDB.export_graph):page/page_sizeintoLIMIT/OFFSET(invalid values normalized like neo4j:page < 1 → 1,page_size < 1 → 10)memory_typeviaproperties->>'memory_type' = ANY(...)deleted; an explicit status list usesANY(...)_build_filter_where_clauseso theand/or/containsfilter DSL workstotal_nodeswith a separateCOUNT(*)query using the same filters, before paginationEdges: resolved via subqueries over the full filtered node set (not page-local ids), so the edge set is complete and consistent across pages. Edges are deliberately not paginated; every response includes all edges connected to any node matching the filters. This is what
/get_memoryconsumers rely on (nodes+total_nodes); documented in the docstring.Related Issue (Required): Fixes #2271
Type of change
How Has This Been Tested?
New unit tests in
tests/graph_dbs/test_postgres_export_graph.pymock the connection/cursor and verify:page=2&page_size=6producesLIMIT 6 OFFSET 6andtotal_nodescomes from the COUNT query (9), not from the returned rows (3)LIMIT/OFFSETmemory_type=[...]and default deleted-status exclusion appear in the WHERE clause{"tags": {"contains": ...}}reaches SQL asproperties->'tags' @> %s::jsonbReproduce with:
All 37 tests in
tests/graph_dbspass (3 skipped, unrelated).Checklist