Repository navigation
feat(#10685): db.index.vector.queryNodes takes an optional {where, filter} pre-filter (#10808) [skip ci] - #10808
Conversation
…lter} pre-filter The Neo4j-compatible three-argument form can only be filtered after its top k, so a tenant whose records are not the nearest got fewer rows than asked, or none. An optional fourth options map now carries the same where/filter pre-filter vector.neighbors takes, tested by the index during the search. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Shared pre-filter parsing engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorAbstract.java, engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorNeighbors.java |
A shared helper combines RID filters with a where predicate. SQL vector neighbors now use this helper. |
Cypher query options and index search engine/src/main/java/com/arcadedb/query/opencypher/procedures/db/DbIndexVectorQueryNodes.java, engine/src/test/java/com/arcadedb/query/opencypher/Issue10685VectorQueryNodesPreFilterTest.java |
queryNodes accepts an optional fourth options map and passes allowed RIDs to vector-index searches. Tests cover pre-filter behavior, three-argument behavior, empty or missing options, and invalid options. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant CypherCaller
participant DbIndexVectorQueryNodes
participant SQLFunctionVectorAbstract
participant VectorIndex
CypherCaller->>DbIndexVectorQueryNodes: call queryNodes with options
DbIndexVectorQueryNodes->>SQLFunctionVectorAbstract: parse where and filter options
SQLFunctionVectorAbstract-->>DbIndexVectorQueryNodes: return allowed RIDs
DbIndexVectorQueryNodes->>VectorIndex: search with allowed RIDs
VectorIndex-->>DbIndexVectorQueryNodes: return matching neighbors
DbIndexVectorQueryNodes-->>CypherCaller: return query rows
Possibly related issues
- ArcadeData/arcadedb#10782 — This change adds pre-filtering to
queryNodes, but does not change theSEARCHlimit behavior described in the issue.
Suggested reviewers: lvca
Merge Risk: 
Minimal · up to 89f65
-
The new vector pre-filter options have no identified merge-blocking issue; the change is ready for normal merge checks.
Pre-merge checks: 
4
-
Check name Status Explanation Description check The description provides the change summary, motivation, related issue, implementation details, test coverage, limitations, and known gaps. It does not use all template headings and does not confirm t… Linked Issues check Issue #10685asks for one of two changes: a Cypher docs note that points users to the pre-filtered form, or an optional fourth argument on db.index.vector.queryNodes that maps to the same pre-filter. …Out of Scope Changes check The diff from merge base 491dfa9 to head 89f6573 touches four production or test areas, all tied to #10685. (1) SQLFunctionVectorAbstract gains public static parsePreFilter(...). It is a thin wr…Title check The title clearly identifies the main change: adding an optional {where, filter} pre-filter to db.index.vector.queryNodes. Full details: Description check
-
Explanation
The description provides the change summary, motivation, related issue, implementation details, test coverage, limitations, and known gaps. It does not use all template headings and does not confirm the mvn clean package checklist item, but it contains the required review information overall.
Full details: Linked Issues check
-
Explanation
Issue
#10685asks for one of two changes: a Cypher docs note that points users to the pre-filtered form, or an optional fourth argument on db.index.vector.queryNodes that maps to the same pre-filter. The issue states that either option would help. This PR implements the second option. At head 89f6573, DbIndexVectorQueryNodes.getMaxArgs() returns 4. The execute path parses args[3] through parseOptions(), which accepts only the keys where and filter (OPTIONS = {where, filter}). It rejects a non-map value with CommandSQLParsingException. It passes filter and where to SQLFunctionVectorAbstract.parsePreFilter(), which wraps RecordPredicateRidSet.of(...) and parseRidFilter(...). A null or empty result from the options returns Stream.empty() when the set is empty, and the set is passed as allowedRIDs to findNeighbors on each index search. The three-argument form still passes null, so its behavior is unchanged. The PR also adds Issue10685VectorQueryNodesPreFilterTest. I did not open the test file, so the test claims rest on the PR description and the summary. The docs follow-up is not filed. The issue does not require it once the code option is implemented.
Full details: Out of Scope Changes check
-
Explanation
The diff from merge base 491dfa9 to head 89f6573 touches four production or test areas, all tied to
#10685. (1) SQLFunctionVectorAbstract gains public static parsePreFilter(...). It is a thin wrapper over the existing RecordPredicateRidSet.of and parseRidFilter, and it is the shared helper that the new queryNodes option needs. (2) SQLFunctionVectorNeighbors.execute now calls parsePreFilter instead of two separate calls. The diff is +1/-4 with the same behavior. The change keeps vector.neighbors and queryNodes on one code path, which the issue's pre-filter goal supports. (3) DbIndexVectorQueryNodes gains the fourth argument, its option parsing, and Javadoc. This is the requested change. (4) Issue10685VectorQueryNodesPreFilterTest adds coverage for the new behavior. No unrelated file or subsystem changes appear in the reviewed evidence.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- 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.
Comment @coderabbitai help to get the list of available commands.
|
Review of #10808 Summary: This is a clean, well-scoped change. The shared Security
Correctness
Minor / style
Performance: There is no overhead on the unfiltered path, because Docs: The follow-up in arcadedb-docs is still needed, as the PR notes. Please file it before merging. Overall: LGTM, with the minor nits above. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 9 |
🟢 Coverage 87.50% diff coverage · -4.69% coverage variation
Metric Results Coverage variation ✅ -4.69% coverage variation Diff coverage ✅ 87.50% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (ff58245) 252708 220311 87.18% Head commit (fe25a74) 285882 (+33174) 235824 (+15513) 82.49% (-4.69%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#10808) 24 21 87.50% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
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.
|
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. |
…lter matching fewer than k Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review of #10808: no blocking issues found. What looks good
Minor points (non-blocking)
Overall this is a clean, focused change. |
…a parent spec with several sub-indexes Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
ReviewOverall this is a clean, well-scoped change. I found no blocking issues and no security hazards. What looks good
Minor suggestions (non-blocking)
LGTM from my side. I didn't run the tests locally. |
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review of #10808 The change is small and well scoped. It reuses the I read the diff only and did not build or run the tests. Minor points, none blocking:
Overall this looks good to merge once CI is green. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10808 +/- ##
============================================
+ Coverage 79.09% 79.12% +0.03%
+ Complexity 4827 4823 -4
============================================
Files 2305 2307 +2
Lines 252708 253055 +347
Branches 55209 55305 +96
============================================
+ Hits 199869 200223 +354
+ Misses 32437 32395 -42
- Partials 20402 20437 +35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Conflict in DbIndexVectorQueryNodes: main (#10776, #10782) moved the k-NN search into the static search(indexSpec, k, vector, Predicate<Document> filter, context, caller) shared with the Cypher 25 SEARCH clause, which turns the predicate into the index allow-list through RecordPredicateRidSet.matching; this branch parsed the optional {where, filter} options map inside execute() into the same kind of allow-list (SQLFunctionVectorAbstract.parsePreFilter). Resolution keeps one search path: the public search(...) signature used by VectorSearchClauseProcedure is unchanged and delegates to a private overload that also takes the options map. The options are still parsed after the index is resolved (a bad index spec stays loud) and an empty filter still answers no rows (#8959). Either pre-filter becomes the allow-list handed to findNeighbors; both together intersect. extractLimit keeps main's caller-aware messages, the imports keep both FunctionOptions and RecordPredicateRidSet, and the allow-list assertion message no longer names only the SEARCH clause. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review of #10808: no blocking issues found. What looks good
Minor suggestions (non-blocking)
No security hazards found. |
Closes #10685
db.index.vector.queryNodes(index, k, vector)(the Neo4j-compatible form) had no filter, so a tenant or property filter could only be applied after its top k: a query whose nearest neighbours belong to another tenant answered fewer rows than asked, or none. The procedure now takes an optional fourth argument, an options map carrying the same pre-filtervector.neighborstakes, tested by the index as it meets each candidate:where: a map of property to value, or a SQL condition with named parametersfilter: a list of nodes / RIDs; both together answer what satisfies bothnullor{}is the three-argument form; an unknown key or a non-map is rejected by name; a filter that resolves to nothing answers no rows (vector.neighbors: afilterthat matches no records is treated as no filter, so the search returns records outside it (a tenant subquery with no rows returns other tenants' records) #8959 contract)The option parsing is shared:
SQLFunctionVectorAbstract.parsePreFilter(filter, where, ...)is now what bothvector.neighborsandqueryNodescall, so the two cannot drift.Finding ledger
queryNodesusers to the pre-filtered form - out of this repo (docs live in ArcadeData/arcadedb-docs); follow-up drafted but not filed (filing in the docs repo was not permitted in this run), see Known gapsCompleteness
Invariant: every Cypher k-NN entry point that answers k rows can restrict its candidates during the search, not only after it.
CALL db.index.vector.queryNodes(idx, k, v, {where})(map)CALL db.index.vector.queryNodes(idx, k, v, {where: 'cond :param'})CALL db.index.vector.queryNodes(idx, k, v, {filter})(collected nodes / RID strings)filter+wheretogetherCALL vector.neighbors(..., {where/filter})db.index.vector.queryRelationshipsTest plan
Issue10685VectorQueryNodesPreFilterTest(12 tests): the issue's data (900 tenant-b vectors all nearer than 100 tenant-a ones, k = 10); the 3-arg post-filter still answers 0 rows; each pre-filter form answers 10 rows, all tenant a; combined filter+where; a parent-type spec with several sub-indexes (sub-type); a pre-filter matching fewer than k (k = 200 answers exactly the 100 of tenant a); an empty filter and a where matching nothing;{}/null; unknown option and non-map options rejected asCommandSQLParsingExceptionallowedRIDsnot passed tofindNeighbors, 4 of the original 9 fail*VectorQueryNodes*,CypherCallVectorNeighborsTest,*VectorNeighbors*,Issue10169*,Issue9858*,Issue10514*,Issue9896*,Issue7862*,CypherProcedureRegistryTest,LSMVectorIndex*ordering/parent-typeCoverage
Entry points covered: see the Completeness table above.
Known gaps
reference/cypher/cypher-clauses.adoc/concepts/vector-search.adoc): say that the 3-argumentqueryNodesfilters after the top-k and show the fourth argument andCALL vector.neighbors(..., {where})as the pre-filtered forms, plus the multi-tenantvector.fuseexample from the issue comment. Unfiled - the docs-repo issue could not be created from this run; needs a manual follow-up.Adversarial pass
Not run: no subagent tool was available in this session to spawn the independent reviewer.
Review cycles
parsePreFilter(private) renamedparseOptions, sub-type/multi-index testDeferred / skipped items
</p>after the<pre>block" (cycles 1, 2, 4): skipped. The paragraph is opened with<p>and closed once after the<pre>, the same shape as the class Javadoc block right above it (the reviewer notes the original has it too); no doclint failure.allowedRIDs... reused across stale top-up iterations ... confirm it carries no per-search state" (cycle 1): no change.RecordPredicateRidSetonly memoizes each RID's verdict (decided), which is deterministic within the statement;vector.neighborsreuses the same set across its top-up passes the same way. Covered bypreFilterMatchingFewerThanKAnswersEveryMatch.searchAndLoadnow takes 8 parameters" (cycle 3): skipped, optional.parseOptionsruns before the query vector is extracted" (cycle 4): skipped. Thewhereside is lazy (tested per candidate); only afilterlist is materialized, which is the caller's own list, and checking options before the vector matchesvector.neighbors.Final state
clean-approval (cycle 4 of 4: only non-blocking nits, none applied).
🤖 Generated with Claude Code
Summary by CodeRabbit
whereconditions, record filters, or both to limit results before nearest-neighbor selection.whereconditions and record filters together.