Skip to content

Conversation

agourlay
Copy link
Member

Fix strict mode for grouping APIs to make sure unindexed_filtering_retrieve applies to the field grouped on.

@agourlay agourlay added this to the Strict mode milestone Apr 10, 2025
Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new public method payload_key_index_schema in the Collection struct that returns the payload field schema for a given JsonPath key if it exists. A new function check_grouping_field is added to verify that a grouping field used in queries is indexed and supports the match operation when strict mode disallows unindexed filtering on retrieval. This check is integrated into the strict mode verification process by adding calls to check_grouping_field in the check_custom methods of both CollectionQueryGroupsRequest and SearchGroupsRequestInternal. Additionally, a method supports_match is added to the PayloadFieldSchema implementation to indicate which schema types support the match condition. A new test function is added to validate that grouping by an unindexed field fails under strict mode, and that creating an appropriate index enables grouping requests to succeed. These changes enhance strict mode enforcement for group-by queries by ensuring proper indexing.

Suggested reviewers

  • timvisee

📜 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 f5b3360 and d6fbc6d.

📒 Files selected for processing (3)
  • lib/collection/src/operations/verification/mod.rs (2 hunks)
  • lib/collection/src/operations/verification/search.rs (2 hunks)
  • lib/segment/src/types.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/collection/src/operations/verification/mod.rs
  • lib/collection/src/operations/verification/search.rs
  • lib/segment/src/types.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: rust-tests (macos-latest)
  • GitHub Check: integration-tests-consensus
  • GitHub Check: rust-tests (windows-latest)
  • GitHub Check: integration-tests
  • GitHub Check: rust-tests (ubuntu-latest)
  • GitHub Check: lint
  • GitHub Check: storage-compat-test
✨ 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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

{
return Err(CollectionError::strict_mode(
format!("Index required but not found for \"{}\"", self.group_by,),
"Create an index for this key.",
Copy link
Contributor

Choose a reason for hiding this comment

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

not every index should work, we need to make sure that it is one which supports Match conditions, like integer, keyword, uuid or bool.

I wonder if we can reuse the unindexed field extractor logic for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not able to reuse the unindexed field extractor because I don't have a filter to start with.
Instead I made something manually looking up the schema.

@agourlay agourlay force-pushed the strict-mode-group-by-unindexed branch from f501a8d to 26b6b37 Compare April 28, 2025 14:22
@agourlay agourlay requested a review from coszio April 28, 2025 17:56
Copy link
Contributor

@coszio coszio left a comment

Choose a reason for hiding this comment

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

I was not able to reuse the unindexed field extractor because I don't have a filter to start with.
Instead I made something manually looking up the schema.

One solution to reuse the unindexed field infra is to create a synthetic match filter to pass to it :)

Comment on lines 1716 to 1727
pub fn support_match(&self) -> bool {
match self {
Self::Keyword => true,
Self::Integer => true,
Self::Bool => true,
Self::Uuid => true,
Self::Float => false,
Self::Geo => false,
Self::Text => false,
Self::Datetime => false,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

integer and uuid can be parametrized without map index, which would make them not support match conditions

Copy link
Member Author

Choose a reason for hiding this comment

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

I handled the integer the index here d6fbc6d

But I do not think the UUID lookup can be disabled.

@agourlay
Copy link
Member Author

agourlay commented Apr 29, 2025

One solution to reuse the unindexed field infra is to create a synthetic match filter to pass to it :)

I thought about it but decided against it because I felt that coming up with a synthetic match value was too hacky.
Is the type of the synthetic match value irrelevant for this trick?

EDIT: I can't do this trick, the unindexed check only that the index has the the same type as the inferred matched value

@agourlay agourlay requested a review from coszio April 30, 2025 08:55
@coszio
Copy link
Contributor

coszio commented Apr 30, 2025

I can't do this trick, the unindexed check only that the index has the the same type as the inferred matched value

Then we should fix the unindexed extractor, regular filter checking for strict mode depends on this IIRC.

@agourlay
Copy link
Member Author

agourlay commented May 2, 2025

Then we should fix the unindexed extractor, regular filter checking for strict mode depends on this IIRC.

I'd rather look at this in a different PR given that is is orthogonal to my current work.

@agourlay
Copy link
Member Author

agourlay commented May 2, 2025

In a follow up PR I will fix the existing unindexed logic used by strict mode by leveraging the new match support detection.

@agourlay agourlay merged commit b8698cf into dev May 2, 2025
17 checks passed
@agourlay agourlay deleted the strict-mode-group-by-unindexed branch May 2, 2025 13:19
@agourlay
Copy link
Member Author

agourlay commented May 6, 2025

Here is the follow up #6496

generall pushed a commit that referenced this pull request May 22, 2025
* Fix strict mode unindexed group_by path

* check index schema for matching support

* Handle disabled lookup on integer index
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