Skip to content

Conversation

coszio
Copy link
Contributor

@coszio coszio commented Apr 9, 2025

One overlooked quirk when developing prefetches is that we should not propagate the main query offset into them.

In general terms, offsets are not compatible with prefetches. Let's look at one example:

Imagine we have a vector search prefetch (limit=5), and an order_by main query (limit=3). For simplicity, let's assume letters are point IDs, and numbers are the order_by values

with offset 0
prefetch candidates: [a: 5, b: 8, c: 3, d: 9, e: 2]

main query ordering: [e: 2, c: 3, a: 5, b: 8, d: 9]
main query results:  [e: 2, c: 3, a: 5]

----------------------------------------
with offset 3 (propagated)
prefetch candidates: [a: 5, b: 8, c: 3, d: 9, e: 2, f: 6, g: 1, h: 4]

main query ordering: [g: 1, e: 2, c: 3, h: 4, a: 5, f: 6, b: 8, d: 9]
main query results:  [h: 4, a: 5, f: 6] 

As you can see, the second query, with an offset is not consistent with the first one. Result g will never appear.

With this PR, offset is not propagated anymore, so the limit in the prefetch is the total amount of offsetting that can happen for the request. If the user keeps paginating with offset and a fixed limit, results will be stable, but will eventually lead to an empty result.

@coszio coszio requested a review from generall April 9, 2025 23:10
Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

📝 Walkthrough

Walkthrough

The changes update the query handling and memory management modules. In the query processing logic, the adjustment of the limit by adding the offset has been removed from the main query code when prefetches are involved. A comment now clarifies that the limit should only be increased by the offset in specific cases without prefetches. Additionally, the recursive prefetch function has been modified by removing the redundant parameter used to pass offset adjustments, simplifying its signature and internal logic. In the memory management module, an unused import for handling file-related operations has been removed and re-scoped to be used only within the clear_disk_cache function. In the testing module, assertions and comments regarding the offset parameter and prefetch functionality have been updated for clarity. These changes streamline the code by reducing unnecessary computations and dependencies while maintaining its overall structure and functionality.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5fbbad and 58c26fa.

📒 Files selected for processing (1)
  • lib/collection/src/operations/universal_query/planned_query.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/collection/src/operations/universal_query/planned_query.rs
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-low-resources
  • GitHub Check: test-consistency
  • GitHub Check: test-consensus-compose
  • GitHub Check: test (macos-latest)
  • GitHub Check: test-consensus
  • GitHub Check: test (windows-latest)
  • GitHub Check: lint
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -1,7 +1,6 @@
//! Platform-independent abstractions over [`memmap2::Mmap::advise`]/[`memmap2::MmapMut::advise`]
//! and [`memmap2::Advice`].

use std::fs::File;
Copy link
Member

@agourlay agourlay Apr 10, 2025

Choose a reason for hiding this comment

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

maybe unnecessary on Mac but breaks the build for everyone else :)

Copy link
Member

Choose a reason for hiding this comment

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

It was indeed 'unused' on macOS because it's only usage is gated in

    #[cfg(any(
        target_os = "linux",
        target_os = "freebsd",
        target_os = "android",
        target_os = "fuchsia",
        target_os = "emscripten",
        target_os = "wasi",
        target_env = "uclibc",
    ))]

I've moved the import into that scope to resolve the problem.

72cbf76

Copy link
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Could you add a test that asserts this behavior?

Prefetch with and without an offset, and assert that we eventually run out of results. That'll ensure the behavior we document actually happens in practice.

@coszio
Copy link
Contributor Author

coszio commented Apr 10, 2025

@timvisee There was actually a failing test (c5fbbad) that I have now edited to assert the new behavior.

@timvisee timvisee merged commit 634e506 into dev Apr 11, 2025
18 checks passed
@timvisee timvisee deleted the don't-propagate-offset-into-prefetches branch April 11, 2025 12:11
@agourlay
Copy link
Member

This may break the local mode congruence tests 🔮

pull bot pushed a commit to kp-forks/qdrant that referenced this pull request Apr 21, 2025
* don't propagate offset into prefetches

* I want to see CI with that change

* Move import into platform specific scope

* edit test to make sure offset is not propagated

* fix planned query test

---------

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>
Co-authored-by: timvisee <tim@visee.me>
timvisee added a commit that referenced this pull request Apr 23, 2025
Asserts fixed behavior in <#6412>,
which broke before in <#6357>.
timvisee added a commit that referenced this pull request Apr 23, 2025
* Add test for limit and offset in query with prefetch

Asserts fixed behavior in <#6412>,
which broke before in <#6357>.

* Fix typo

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
generall pushed a commit that referenced this pull request May 22, 2025
* Add test for limit and offset in query with prefetch

Asserts fixed behavior in <#6412>,
which broke before in <#6357>.

* Fix typo

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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