lightrag-memgraph: log GC-lag under-return in vector query()#228
Merged
Conversation
Memgraph's vector index is garbage-collected on a delay after a node delete, so vector_search.search() can hand back stale candidates for already-deleted nodes. query() silently excluded these with no signal that fewer than top_k live results were found. Now it logs a warning with the raw hit count vs live count, and the README documents the behavior as a known Memgraph limitation. Fixes #225
…vior Memgraph's vector index isn't garbage-collected on a delay -- per the docs it operates at READ_UNCOMMITTED isolation, so stale candidates surface specifically while a concurrent delete transaction is still in flight and disappear once it commits. Reword the docstring, inline comments, warning message, and README section accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MemgraphVectorStorage.query()silently dropped vector-search candidates whose backing node had already been deleted (e.g. by a concurrent, not-yet-committed transaction — Memgraph's native vector index runs atREAD_UNCOMMITTEDisolation by design, see the vector search docs), with no signal to callers that a shortfall could be caused by this rather than a genuine lack of matches.OPTIONAL MATCH(instead ofMATCH), so a candidate caught mid-delete comes back as a row withid IS NULLrather than being silently excluded, letting us count it.query()now logs a warning with both the rawvector_search.search()hit count and the live-candidate count whenever they differ.query()docstring) as expectedREAD_UNCOMMITTEDbehavior under concurrent deletes, not a general "GC lag" limitation.Test plan
test_vector_roundtrip_and_nearest_neighbour,test_vector_respects_threshold)test_vector_query_logs_and_excludes_stale_candidates: deletes a node directly (bypassingstore.delete(), which nulls the embedding first) to leave a stale vector-index entry, then assertsquery()excludes it and logs the expected warningpytest tests/) passes against a live Memgraph instance: 19 passedruff check/ruff format --checkpassFixes #225