Skip to content

Conversation

timvisee
Copy link
Member

@timvisee timvisee commented Mar 31, 2025

Implements this which we have in search, also for our query API.

If having a large number of shards or a large offset, prevent transferring a huge amount of payloads across the network within the cluster. Instead, defer reading vectors and payloads to a second step to greatly improve search performance.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

@timvisee timvisee changed the title Defer fetching vectors/payloads to separate step in large query batches Optimize vector/payload reads in large query batches, defer reads Mar 31, 2025
@timvisee timvisee requested a review from Copilot March 31, 2025 14:06
Copilot

This comment was marked as resolved.

@timvisee timvisee force-pushed the collection-query-two-stage-payload branch from 4047618 to 7ecd085 Compare March 31, 2025 14:09
@timvisee timvisee marked this pull request as ready for review March 31, 2025 14:15
@timvisee timvisee requested review from generall and coszio March 31, 2025 14:15
Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

📝 Walkthrough

Walkthrough

The changes modify query handling in the Collection struct. In the do_query_batch method, a new constant PAYLOAD_TRANSFERS_FACTOR_THRESHOLD is introduced to decide when to perform a two-step search. The method now verifies if all batched requests require payloads and vectors, computes the limits and offsets, and assesses whether the amount of data to transfer exceeds the defined threshold. When this threshold is met, a revised batch excluding payloads and vectors is created to perform an initial query followed by a secondary query to obtain the necessary metadata. Additionally, the parameter passing for shard_selection has been adjusted. In the core_search_batch method within the search.rs file, changes include the use of conditional compilation for testing, streamlined logic by replacing cloning with direct references using as_ref(), a refactoring to reference the centralized constant, and minor optimizations in request handling to reduce memory overhead.

Suggested reviewers

  • generall
  • coszio
  • KShivendu
  • ffuugoo
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
lib/collection/src/collection/query.rs (2)

33-35: Consider making the threshold configurable.
Allowing this threshold to be adjusted dynamically (e.g., via configuration or environment variables) could be beneficial to avoid redeploying just for changing it.


208-281: Improve handling of partial metadata requirements.
Currently, the two-step search is triggered only if all requests in the batch require payloads and vectors. For large mixed-batch queries where only some requests need payloads or vectors, consider applying the two-step approach to those specific requests only. This finer-grained strategy could yield better performance for batches with diverse metadata needs.

lib/collection/src/collection/search.rs (2)

67-71: Consider partial metadata logic.
The code checks if all searches require payloads or vectors before enabling the two-step flow. For mixed queries (some with and some without payload/vector), a more selective approach could optimize large or varied requests.


94-99: Selective replacement approach.
Using replace() for with_payload and with_vector clarifies the intention to set them to false. If partial results are needed, a more targeted replacement strategy might better serve mixed queries.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fbf1ce4 and 7ecd085.

📒 Files selected for processing (2)
  • lib/collection/src/collection/query.rs (4 hunks)
  • lib/collection/src/collection/search.rs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • 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 (macos-latest)
  • GitHub Check: test-consensus-compose
  • GitHub Check: test (windows-latest)
  • GitHub Check: test-consensus
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (4)
lib/collection/src/collection/query.rs (1)

12-12: No concerns regarding the new imports.
The additional import statements look appropriate for the introduced functionality.

lib/collection/src/collection/search.rs (3)

22-22: Conditional compilation looks fine.
Restricting this method to the “testing” feature flag poses no obvious issues.


83-85: Shared threshold reference.
Referencing the threshold from query.rs promotes consistency across the codebase.


118-118: Straightforward zip usage.
Zipping the results with the original requests is a concise way to pair up final data.

@timvisee timvisee mentioned this pull request Mar 31, 2025
@timvisee timvisee merged commit 00e2436 into dev Mar 31, 2025
17 checks passed
@timvisee timvisee deleted the collection-query-two-stage-payload branch March 31, 2025 15:00
timvisee added a commit that referenced this pull request Mar 31, 2025
)

* On large query batches, defer fetching vectors/payloads to a second stap

* Improve same logic in search

* Remove unnecessary clone

* Use more references

* Deduplicate and use shared constant

* Function is only used in testing
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