Skip to content

Expand rank() operator reference: composite conditions, matches(), negations - #4811

Open
zoharsan wants to merge 1 commit into
masterfrom
zoharsan/rank-operator-reference
Open

Expand rank() operator reference: composite conditions, matches(), negations#4811
zoharsan wants to merge 1 commit into
masterfrom
zoharsan/rank-operator-reference

Conversation

@zoharsan

Copy link
Copy Markdown

What

Expands the rank operator section in en/reference/querying/yql.html, which previously only stated the first-argument-matches rule with two examples. Prompted by a customer case about boosting on filter criteria without re-writing the filter logic in rank expressions, where the current documentation left the key questions unanswered.

New content, each with a YQL example and the matching rank profile:

  • Variadic semantics — any number of arguments; arguments after the first never add or exclude documents; any query operator is usable (in, ranges, grouped conditions).
  • Observing ranking-only argumentsmatches(field) as the match indicator; in/ranges are visible to matches() but not to text features like bm25.
  • Several conditions on the same fieldmatches(field, n) with term numbering, including the caveat that indexes follow query structure.
  • Grouped conditions are evaluated as a unit — terms inside a grouped argument expose match information only for documents where the whole condition is true, making a group usable as a single boost rule.
  • Negations are not observable — a negation-only argument matches correctly but produces no match information; documents the invert-in-the-ranking-expression alternative.
  • Note — arguments not read by any rank feature are pruned from execution (no cost, but also no effect).

The hybrid-search/nearestNeighbor example was replaced by a worked boost example, since the section now centers on the boost-without-filtering use case.

Verification

All documented behavior was verified against master (vespaengine/vespa:latest, July 2026) with a minimal test application — every example pattern in the section has a corresponding live query result. Key implementation anchors:

  • Unit evaluation of grouped arguments: searchlib/src/vespa/searchlib/queryeval/multisearch.cpp (doUnpack only unpacks a child that matches the docid)
  • Negations invisible to ranking: searchlib/src/vespa/searchlib/queryeval/andnotsearch.cpp (doUnpack unpacks the positive child only)
  • Pruning of unused arguments: RankBlueprint::createIntermediateSearch in searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
  • Phrase counts as one term for matches(field, n) numbering (verified empirically)

For reviewers

This promotes currently-undocumented implementation behavior (unit evaluation, negation invisibility, pruning) to documented behavior — flagging for search-core owners to confirm these are semantics we want to commit to.

🤖 Generated with Claude Code

…gations

Document behavior of ranking-only arguments verified against master:
- rank() is variadic; arguments after the first never affect matching
- all query operators usable in ranking-only arguments (in, range,
  grouped conditions)
- observing arguments with matches(field) and matches(field, n),
  including several conditions on the same field
- grouped conditions are evaluated as a unit (terms expose match
  information only where the whole condition is true)
- negation-only arguments are not observable by rank features;
  documented the invert-in-the-expression alternative
- note on unused ranking-only arguments being pruned (no cost, no effect)

Replaces the hybrid-search example with a worked boost example, as the
section now focuses on the boost-without-filtering use case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zoharsan
zoharsan requested a review from radu-gheorghe July 30, 2026 19:18

@bratseth bratseth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reference document, the purpose of those is to document every element of the topic in question. Explanation of how to use features should instead go into guide documents (anything outside the reference/ directory). Maybe this belongs in the text matching guide?

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.

2 participants