Skip to content

fix(#9858): db.index.vector.queryNodes skips candidates a concurrent commit deleted and tops up - #9860

Closed
blaus23 wants to merge 1 commit into
ArcadeData:mainfrom
blaus23:fix-9858-querynodes-stale-candidates
Closed

blaus23 wants to merge 1 commit into
ArcadeData:mainfrom
blaus23:fix-9858-querynodes-stale-candidates

Conversation

@blaus23

@blaus23 blaus23 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

db.index.vector.queryNodes loaded every candidate the index returned with asDocument() and let a RecordNotFoundException escape. A record deleted between the index search and the load therefore failed the whole query: EntityNotFound: Error executing procedure: db.index.vector.querynodes over Bolt.

The procedure now skips a candidate whose record is gone. If skipping leaves the answer short, it asks the indexes again with a doubled candidate budget. This is the same loop vectorNeighbors has run since #9368. It stops when:

  • the answer is full;
  • nothing was skipped, so the shortfall is real;
  • no index filled its budget, so it handed over everything it holds;
  • or the budget reaches 100,000 candidates, the same cap vectorNeighbors uses.

A search with no stale candidates still makes exactly one pass.

Motivation

The SQL vector functions already skip stale candidates: vectorNeighbors, vectorRerank, vectorMmr, vectorDiscover, vectorFuse and vectorSparseNeighbors. The Cypher procedure, which Neo4j-compatible clients use, never got the same treatment. With one writer deleting while four clients search, 90 of 81,375 searches failed on a single server (reproduction in #9858).

Related issues

Fixes #9858. Same pattern as #9368 (dense, SQL) and #9692 / #9698 (sparse).

Additional Notes

Test. Issue9858VectorQueryNodesStaleTopUpTest follows the Issue9368VectorNeighborsStaleTopUpTest setup: it removes records from the bucket only, leaving their index entries behind. It covers three cases:

  • the nearest candidates are stale;
  • the whole first window is stale;
  • the index holds fewer than k live records, where the loop must stop and not spin.

All three fail without the fix (RecordNotFoundException) and pass with it.

Other verification:

Independent of #9857 and its PR; both are based on the same main commit.

Pre-commit: the hooks that apply to Java files (trailing whitespace, final newline, line endings, BOM) were checked on every changed file. pre-commit itself was not run.

Checklist

  • I have run the build using mvn clean package command. Not the full reactor: I built and installed engine and ran the suites listed above.
  • My unit tests cover both failure and success scenarios

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Vector searches now skip deleted records and fetch additional candidates when stale index entries leave too few results.
    • Searches return the available live records when fewer than the requested number remain.
  • Tests
    • Added coverage for vector searches with stale index entries, including cases where initial candidates are deleted and fewer live records remain than requested.

@mergify

mergify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity

Metric Results
Complexity 8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c69d3b8c-9d6a-4b6f-90a8-2f49f4b2bbae

📥 Commits

Reviewing files that changed from the base of the PR and between cb0f720 and 09c938a.


📒 Files selected for processing (2)
  • engine/src/main/java/com/arcadedb/query/opencypher/procedures/db/DbIndexVectorQueryNodes.java
  • engine/src/test/java/com/arcadedb/query/opencypher/Issue9858VectorQueryNodesStaleTopUpTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

The Cypher vector query procedure now skips candidates whose records disappear after index lookup. It increases its candidate fetch size on saturated passes with stale entries, up to 100,000. Regression tests cover top-up behavior and cases with fewer live records than requested.

Changes

Stale candidate handling

Layer / File(s) Summary
Retry behavior and regression coverage
engine/src/main/java/com/arcadedb/query/opencypher/procedures/db/DbIndexVectorQueryNodes.java, engine/src/test/java/com/arcadedb/query/opencypher/Issue9858VectorQueryNodesStaleTopUpTest.java
The procedure skips candidates whose records are missing and retries with a doubled fetch size when results are short and the search pass is saturated. The tests cover stale candidates at the start of the results and cases where fewer than the requested number of records remain live.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Query as DbIndexVectorQueryNodes
  participant Index as Vector index
  participant Store as Record storage
  loop While saturated stale candidates remain below the fetch cap
    Query->>Index: Fetch up to fetchK candidates
    Index-->>Query: Return candidate records
    Query->>Store: Load candidate records
    Store-->>Query: Return live records or missing-record result
    Query->>Query: Skip missing records and evaluate whether to retry
  end
Loading

Suggested reviewers: lvca


Merge Risk: ⚪ Minimal · up to 09c93

The change skips vector candidates whose records were deleted and retries with a larger candidate budget. It is bounded by a cap of 100,000 and covered by regression tests. No concrete merge-blocking risk was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: skipping concurrently deleted vector-query candidates and topping up results.
Description check Passed The description includes all required sections, explains the change and motivation, references related issues, documents testing, and completes the unit-test checklist. It clearly notes that the full …
Linked Issues check Passed The changes satisfy the coding requirements for #9858. DbIndexVectorQueryNodes catches RecordNotFoundException during candidate loading and skips the stale candidate. It retries with a doubled can…
Out of Scope Changes check Passed The pull request changes only the affected Cypher vector procedure and adds a regression test for #9858. The retry logic and test setup directly support stale-candidate handling. No unrelated product …

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…oncurrent commit deleted and tops up

The procedure loaded every candidate the index returned with asDocument() and let a
RecordNotFoundException escape, so a record deleted between the index search and the load
failed the whole query (EntityNotFound over Bolt). It now skips the stale candidate and,
when the answer comes up short because of it, asks the indexes again with a doubled
candidate budget: the loop vectorNeighbors runs since ArcadeData#9368. It stops when the answer is
full, when nothing was skipped, when no index filled its budget, or at 100,000 candidates.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@blaus23
blaus23 force-pushed the fix-9858-querynodes-stale-candidates branch from 1baf04a to 09c938a Compare October 12, 2026 16:18
@robfrank

Copy link
Copy Markdown
Collaborator

@claude review

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Claude finished @robfrank's task in 20s —— View job


Review of PR #9860

The fix is correct and small. I read the diff of DbIndexVectorQueryNodes.java and the surrounding method. I did not build the project or run any tests, and I did not read the new test file. This review rests on the diff and the PR description.

Looks good

  • Stop conditions: the loop ends on a full answer, no stale candidates, an unsaturated pass, or the 100,000 cap. Each one stops the loop, and the budget at least doubles per pass until the cap. A search with no stale candidates still makes one pass.
  • Saturation test: neighbors.size() >= fetchK is set per index. With several indexes, any one of them being full is enough to justify another pass.
  • Dedup and stale handling: the RidHashSet is rebuilt on each pass, so a retry cannot double-emit. The stale RID is added to emitted before the load. That is harmless because a deleted RID stays deleted.
  • Scope of the catch: only RecordNotFoundException around asDocument() is caught, so real errors still surface.
  • Cap: it matches vectorNeighbors (vectorNeighbors answers fewer than limit rows while another thread commits deletes: the SQL function skips records the index still returns and does not top up #9368). The long multiplication guards against overflow.

Minor, non-blocking

  1. searchAndEmit takes two out-parameters, int[] staleSkipped and boolean[] saturated. That is a bit awkward. A small private holder (a record or a tiny class) would read better. It would also let you drop the per-iteration array allocations. This is cosmetic and not on a hot path, so it is optional.
  2. When the first pass is saturated, the rerun repeats the full index search and re-sorts from scratch. That is fine for a rare path and matches vectorNeighbors. A comment saying so would help the next reader.
  3. The cap case returns a short result silently. This is consistent with vectorNeighbors, so I would leave it.

Process notes

  • The PR checklist leaves the mvn clean package box unchecked. The author says they built and installed engine and ran the 1,578 *Vector* and Cypher procedure tests. That seems adequate for an engine-only change. CI will run the broader suite.
  • CodeRabbit's docstring-coverage warning is not relevant to this codebase's style.

No blocking issues found. Approve from my side, subject to green CI.

@blaus23

blaus23 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #9900, which fixes #9858 more broadly (Cypher, SQL and the Select API). Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db.index.vector.queryNodes fails the whole query when a concurrent commit deletes one of its candidate records

3 participants