Repository navigation
Description
Summary
Neo4jWorldGraphBackend.query_subgraph (added in #823 / #735) does not apply the min_confidence and as_of filters to its node/document traversal — only to the returned edge list. This makes the Neo4j/Memgraph backend return more nodes and documents than InMemoryWorldGraphBackend for confidence-filtered and time-travel (as_of) queries, so the two backends disagree on the same graph.
This is a correctness/parity bug in a production path: time-travel queries on Neo4j leak entities and source documents that are only reachable through edges that are invalid at the requested time.
Where
src/synapsekit/retrieval/world_model.py — Neo4jWorldGraphBackend.query_subgraph.
The node query traverses all edges with no predicate:
MATCH path=(n:WorldModelEntity)-[:WORLD_RELATES*0..{hops}]-(m:WorldModelEntity)
WHERE n.id IN $ids
UNWIND nodes(path) AS node
RETURN DISTINCT nodeThe min_confidence / as_of filter is applied only in the separate edge query. The document query then derives documents from list(nodes), so it inherits the over-broad node set.
Expected (in-memory reference)
InMemoryWorldGraphBackend.query_subgraph (world_model.py:631) prunes the BFS by edge validity — an edge failing confidence >= min_confidence or _edge_active(edge, timestamp) is not traversed, so nodes reachable only through invalid/low-confidence edges (and their documents) are excluded from the result.
Reproduction
Build a graph A --(valid_until=2024-01-01)--> B, then query_subgraph(..., as_of="2025-01-01"):
- In-memory: returns
{A}(edge expired, B unreachable), documents from A only. - Neo4j (buggy): returns
{A, B}with B's documents, because the node/path match ignoresvalid_until.
Same divergence for min_confidence above an edge's confidence.
Fix
Apply the same confidence/temporal predicate to every relationship on the traversed path in both the node and edge queries, e.g. WHERE all(r IN rels WHERE coalesce(r.confidence,1.0) >= $min_confidence AND (... valid_at/valid_until ...)), and pass min_confidence/as_of params to the node query. This restores parity with the in-memory BFS (zero-length path still returns isolated seeds).
Testing
- Regression test with testcontainers (
neo4j:5) asserting Neo4j and in-memory return identical node/document/edge sets for anas_ofquery and amin_confidencequery on the same graph. Skips cleanly without Docker (existing convention), but must pass when Docker is available. - Standards: pytest, no MagicMock (real Neo4j via testcontainers).
Origin
Introduced in #823 (closes #735). Caught in post-merge review; not covered by CI because the Neo4j testcontainers test is skipped without Docker.
Activity
ci(test): run testcontainers integration tests in CI (#827)
fix(retrieval): filter Neo4j subgraph nodes and documents by confiden…