Skip to content

perf: skip external-id resolution in search post-processing - #10312

Merged
timvisee merged 3 commits into
qdrant:devfrom
ivandasch:fix-search-path-id-resolve
Aug 25, 2026
Merged

timvisee merged 3 commits into
qdrant:devfrom
ivandasch:fix-search-path-id-resolve

Conversation

@ivandasch

@ivandasch ivandasch commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

perf: skip external-id resolution in search post-processing

Part of #10311.

What

process_search_result hands its scored points to retrieve(), which resolves
every external id back into an internal offset. The offsets are already known
at that point — they come straight from the vector index as
ScoredPointOffset — so each request performs top_k * segments redundant
external -> internal lookups.

retrieve() is split into resolution + retrieve_resolved(); the search path
calls the latter with the offsets it already holds, and applies the deferred
cutoff by offset instead of resolving ids just to filter them.

Why it survived this long

The cost depends on the id tracker being mutable: a freshly optimized segment
resolves through a BTree, a restarted node maps an immutable tracker and
resolves in constant time. The effect appears right after ingestion or
optimization and disappears after a restart — so a benchmark that loads data,
restarts, and only then measures never sees it.

Compatibility

retrieve() keeps its deferred_behavior parameter and applies it during
resolution exactly as before, so behaviour is unchanged for every other
caller
. retrieve_resolved() is private and its doc states that deferred
filtering is the caller's responsibility; the only caller that skips resolution
applies the cutoff itself, by offset. There is no double filtering.

Measurements

Measured on current dev: glove-100-angular, 1.18M points, dim=100, 21
segments, m=16, ef=128, fixed 800 QPS, search pool pinned to 15 threads,
process CPU time per request, three runs each:

build ms CPU / request
dev 6.82 / 6.83 / 6.82
dev + this patch 6.31 / 6.30 / 6.30

≈8% less CPU per search request on a many-segment collection.

On a 1.18.x cluster the same round trip additionally showed up as ~15-24%
higher median latency right after ingestion, disappearing after a node restart
— the mutable-vs-immutable id tracker effect described above.

Testing

cargo nextest run -p segment over the search and deferred-point suites:
87/87 pass, including test_deferred_point_read_operations,
test_deferred_point_sparse, test_dense_deferred_point_segment_combinations
and test_deferred_point_facets. cargo clippy --all-targets clean.

process_search_result hands its scored points to retrieve(), which resolves
every external id back into an internal offset — although the offsets are
already known there: they come straight from the vector index as
ScoredPointOffset. Every request therefore performs top_k x segments
redundant external->internal lookups.

Whether that costs anything depends on the id tracker being mutable: a
freshly optimized segment looks ids up through a BTree, while a restarted
node maps an immutable tracker and resolves in constant time. So the effect
shows up right after ingestion or optimization and disappears after a
restart, which is what makes it easy to miss — a benchmark that starts from
a freshly booted node never sees it.

Split retrieve() into resolution + retrieve_resolved() and pass the offsets
from process_search_result directly, applying the deferred cutoff by offset
instead of resolving ids just to filter them. retrieve() behaviour is
unchanged for all other callers; retrieve_resolved() is private and states
that deferred filtering is the caller's responsibility.

Measured on glove-100-angular (1.18M points, 21 segments, top_k=10) at a
fixed request rate, on a node that had just finished ingesting: median
latency ~15-24% lower, ~8% less CPU per request. Both figures come from the
same node before and after the change.
@ivandasch
ivandasch requested a review from generall August 25, 2026 08:02
@ivandasch
ivandasch requested a review from generall August 25, 2026 08:53
@qdrant qdrant deleted a comment from coderabbitai Bot Aug 25, 2026

@timvisee timvisee 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.

Great idea. I confirm I'm seeing similar results locally. I like the limited amount of code changes. Thanks!

@timvisee
timvisee merged commit 6dd3bd3 into qdrant:dev Aug 25, 2026
17 checks passed
@timvisee timvisee mentioned this pull request Aug 25, 2026
9 tasks done
timvisee added a commit that referenced this pull request Aug 28, 2026
A query without prefetches and without rescoring is served by a single
leaf search or scroll whose result is returned as is. The planner still
built that leaf without payload or vectors and filled them in afterwards
through SegmentsSearcher::retrieve, which resolves every result id in
every segment again: the same cost #10312 removed from the search API,
paid once more at the end of each query.

Let the leaf carry the requested payload and vectors instead, so the
segment attaches them to the results it already holds by offset, and
clear the root plan so the fill step is skipped. Prefetch leaves and
rescored roots (MMR) are unchanged. As with the search API, this fetches
payload for each segment's candidates rather than for the merged top
`limit` alone.
timvisee added a commit that referenced this pull request Sep 2, 2026
* perf: skip retrieval in scroll when no payload or vectors are requested

Every scroll variant went through SegmentsSearcher::retrieve to build its
records, even when neither payload nor vectors were asked for. That is a
has_point lookup per id per segment plus a version and id resolution per
hit, only to yield records holding nothing but the id. The universal query
API always scrolls this way and fetches payload separately afterwards.

Build the bare records from the ids directly in that case. The retrieve
could only have dropped ids deleted in between, which the update lock held
across the scroll rules out.

* perf: fetch payload and vectors in the leaf of plain query requests

A query without prefetches and without rescoring is served by a single
leaf search or scroll whose result is returned as is. The planner still
built that leaf without payload or vectors and filled them in afterwards
through SegmentsSearcher::retrieve, which resolves every result id in
every segment again: the same cost #10312 removed from the search API,
paid once more at the end of each query.

Let the leaf carry the requested payload and vectors instead, so the
segment attaches them to the results it already holds by offset, and
clear the root plan so the fill step is skipped. Prefetch leaves and
rescored roots (MMR) are unchanged. As with the search API, this fetches
payload for each segment's candidates rather than for the merged top
`limit` alone.

* Use new_empty function

* fix: fetch payload and vectors in scroll leaves only (#10384)

A search leaf hydrates every segment's local top-k before merging, so
`with_payload` there multiplies payload I/O by the segment count — the
regression #6279 fixed and `test_payload_io_read_is_within_limit[query]`
guards. Scroll leaves retrieve once for the merged page, so they keep
fetching directly; search leaves stay bare and the root plan retrieves
for the final result.


Claude-Session: https://claude.ai/code/session_01SUWh5PqUeSefrUqUwXxU3E

Co-authored-by: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
timvisee pushed a commit that referenced this pull request Sep 3, 2026
* perf: skip external-id resolution in search post-processing

process_search_result hands its scored points to retrieve(), which resolves
every external id back into an internal offset — although the offsets are
already known there: they come straight from the vector index as
ScoredPointOffset. Every request therefore performs top_k x segments
redundant external->internal lookups.

Whether that costs anything depends on the id tracker being mutable: a
freshly optimized segment looks ids up through a BTree, while a restarted
node maps an immutable tracker and resolves in constant time. So the effect
shows up right after ingestion or optimization and disappears after a
restart, which is what makes it easy to miss — a benchmark that starts from
a freshly booted node never sees it.

Split retrieve() into resolution + retrieve_resolved() and pass the offsets
from process_search_result directly, applying the deferred cutoff by offset
instead of resolving ids just to filter them. retrieve() behaviour is
unchanged for all other callers; retrieve_resolved() is private and states
that deferred filtering is the caller's responsibility.

Measured on glove-100-angular (1.18M points, 21 segments, top_k=10) at a
fixed request rate, on a node that had just finished ingesting: median
latency ~15-24% lower, ~8% less CPU per request. Both figures come from the
same node before and after the change.

* review fix

* review fix

---------

Co-authored-by: Ivan Dashchinskiy <[email protected]>
timvisee added a commit that referenced this pull request Sep 3, 2026
* perf: skip retrieval in scroll when no payload or vectors are requested

Every scroll variant went through SegmentsSearcher::retrieve to build its
records, even when neither payload nor vectors were asked for. That is a
has_point lookup per id per segment plus a version and id resolution per
hit, only to yield records holding nothing but the id. The universal query
API always scrolls this way and fetches payload separately afterwards.

Build the bare records from the ids directly in that case. The retrieve
could only have dropped ids deleted in between, which the update lock held
across the scroll rules out.

* perf: fetch payload and vectors in the leaf of plain query requests

A query without prefetches and without rescoring is served by a single
leaf search or scroll whose result is returned as is. The planner still
built that leaf without payload or vectors and filled them in afterwards
through SegmentsSearcher::retrieve, which resolves every result id in
every segment again: the same cost #10312 removed from the search API,
paid once more at the end of each query.

Let the leaf carry the requested payload and vectors instead, so the
segment attaches them to the results it already holds by offset, and
clear the root plan so the fill step is skipped. Prefetch leaves and
rescored roots (MMR) are unchanged. As with the search API, this fetches
payload for each segment's candidates rather than for the merged top
`limit` alone.

* Use new_empty function

* fix: fetch payload and vectors in scroll leaves only (#10384)

A search leaf hydrates every segment's local top-k before merging, so
`with_payload` there multiplies payload I/O by the segment count — the
regression #6279 fixed and `test_payload_io_read_is_within_limit[query]`
guards. Scroll leaves retrieve once for the merged page, so they keep
fetching directly; search leaves stay bare and the root plan retrieves
for the final result.


Claude-Session: https://claude.ai/code/session_01SUWh5PqUeSefrUqUwXxU3E

Co-authored-by: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
@timvisee timvisee mentioned this pull request Sep 3, 2026
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.

3 participants