Add filter support for VSIM vector search#1570
Conversation
Implement JSON-path-based filter expressions that are evaluated against vector element attributes after similarity search. The filter engine includes a tokenizer, expression parser, and evaluator supporting comparison operators, logical operators (and/or/not), arithmetic, string equality, containment (in), and parenthesized grouping. Integrate post-filtering into VectorManager for both VSIM code paths, rejecting requests that specify a filter without WITHATTRIBS.
There was a problem hiding this comment.
Pull request overview
Adds post-filter support for VSIM vector search results by introducing a JSON-attribute filter expression engine and integrating it into VectorManager after similarity search.
Changes:
- Introduces a tokenizer/parser/evaluator for filter expressions over JSON attributes (
and/or/not, comparisons, arithmetic,in, grouping). - Integrates post-filtering into
VectorManagerfor both value-based and element-based similarity search paths. - Adds unit tests for the filter engine and RESP integration tests for
VSIM ... FILTER ....
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
libs/server/Resp/Vector/VectorManager.cs |
Applies post-filtering to VSIM results and evaluates expressions against per-element attributes. |
libs/server/Resp/Vector/Filter/VectorFilterTokenizer.cs |
Tokenizes filter expressions into numbers/strings/identifiers/operators/keywords. |
libs/server/Resp/Vector/Filter/VectorFilterParser.cs |
Parses tokens into an expression AST with operator precedence. |
libs/server/Resp/Vector/Filter/VectorFilterExpression.cs |
Defines AST node types for literals, member access, unary, and binary ops. |
libs/server/Resp/Vector/Filter/VectorFilterEvaluator.cs |
Evaluates the AST against JsonElement attribute data. |
test/Garnet.test/VectorFilterTests.cs |
Unit tests for tokenizer/parser/evaluator behavior. |
test/Garnet.test/RespVectorSetTests.cs |
Adds RESP-level tests verifying VSIM filtering behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan * Avoid per-result allocation in EvaluateFilter by using Utf8JsonReader with ParseValue Co-authored-by: hailangx <3389245+hailangx@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hailangx <3389245+hailangx@users.noreply.github.com>
…ly (#1572) * Initial plan * Fetch attributes internally for filtering when not returning them Co-authored-by: hailangx <3389245+hailangx@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hailangx <3389245+hailangx@users.noreply.github.com>
|
CAn you link the specification of expression syntax you are implementing here |
|
@microsoft-github-policy-service agree company="Microsoft" |
|
kevin-montrose
left a comment
There was a problem hiding this comment.
I think some fundamental reworking is needed here, exceptions and allocations need to go - I've left a bunch of guideline comments to get us pointed in the right direction. It's not quite an exhaustive review - there are minor optimizations and style things we can revisit latter when we're closer to mergeable.
Resetting to unblock after discussion.
|
For future reference, a slightly cleaned up version of the plan we discussed offline:
While generally we do not want early-exits in this code (batching and SIMD want very little control flow to be beneficial), it makes sense to check after every Minor thoughts after a quick glance before vacaction:
|
|
Haiyang, let us plan to paginate diskann when the first round of post processing does not generate enough results, to mitigate low recall for selective predicates. |
…om/microsoft/garnet into haixu/vector-filter-postprocessing
…om/microsoft/garnet into haixu/vector-filter-postprocessing
Adds post-filter support for VSIM vector search results by introducing a JSON-attribute filter expression engine and integrating it into VectorManager after similarity search.
Changes:
Supported syntax documented at Vector Filter Expressions (
VSIM ... FILTER)website/docs/dev/vector-sets.md
Key design constraint: Zero heap allocation in the per-candidate evaluation loop. All buffers are borrowed from the session-local ScratchBufferBuilder (~9 KB), a pinned byte[] that persists for the session's lifetime. After the first VSIM FILTER query, the buffer is already large enough — subsequent calls have zero allocation cost and zero GC pressure.
design doc website/docs/dev/post_filter_design.md
Follow ups: