Skip to content

[score boosting] Value retrievers return multivalues#6195

Merged
coszio merged 4 commits intodevfrom
retriever-can-output-array
Mar 19, 2025
Merged

[score boosting] Value retrievers return multivalues#6195
coszio merged 4 commits intodevfrom
retriever-can-output-array

Conversation

@coszio
Copy link
Copy Markdown
Contributor

@coszio coszio commented Mar 18, 2025

This changes the behavior of retrievers from extracting always the first value of a multivalue, to returning the multivalue itself.

After retrieving, the evaluation will translate single value as value ([x] as x), and more than one value as array ([x, y] as [x, y])

This table exemplifies the change:

payload value retrieved multivalue evaluated before evaluated now
0.5 [0.5] 0.5 0.5
[0.5] [0.5] 0.5 0.5
[0.5, 0.6] [0.5, 0.6] 0.5 [0.5, 0.6]

@coszio coszio requested review from generall and timvisee March 18, 2025 17:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

The pull request updates the logic for retrieving and processing payload values in the query optimization component. In the formula_scorer.rs file, the get_payload_value method now distinguishes between zero, one, or multiple retrieved values, returning either None, a single value, or an array wrapped in a Some, respectively. Additionally, the initialization in make_formula_scorer now uses smallvec! for vector creation. In the value_retriever.rs file, the return type for variable retrievers has been changed from an optional single value to a MultiValue<Value>, and the retrieval logic now aggregates all values using a flattening approach. Lastly, a new method get_value_cloned has been added to the PayloadContainer trait to facilitate cloning of retrieved values, ensuring that the payload handling supports multiple values consistently.

Suggested reviewers

  • timvisee

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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
Copy Markdown
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: 1

🧹 Nitpick comments (3)
lib/segment/src/types.rs (1)

1453-1456: Well implemented new get_value_cloned method.

This method extends the PayloadContainer trait with a convenient way to obtain owned values rather than references, efficiently transforming the collection by cloning each value. This aligns with the PR objective of enhancing value retrieval to support multiple values.

Consider adding documentation comments to explain the purpose and behavior of this method:

+    /// Returns a collection of cloned values from the payload at the specified path.
+    /// 
+    /// Unlike `get_value` which returns references, this method clones each value,
+    /// allowing for ownership of the values when needed.
     fn get_value_cloned(&self, path: &JsonPath) -> MultiValue<Value> {
         self.get_value(path).into_iter().cloned().collect()
     }
lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs (1)

246-253: Consider adding brief doc comments for clarity.

This logic correctly returns None when there are no values, returns a single value unwrapped, or wraps multiple values in an array. A short doc comment explaining that behavior (single vs. multiple) could make this more discoverable.

 fn get_payload_value(&self, json_path: &JsonPath, point_id: PointOffsetType) -> Option<Value> {
+    // Returns None if no values exist;
+    // returns the single value directly if exactly one value exists;
+    // returns an array of values if multiple exist.
     self.payload_retrievers
         .get(json_path)
         .and_then(|retriever| {
             let mut multi_value = retriever(point_id);
             match multi_value.len() {
                 0 => None,
                 1 => Some(multi_value.pop().unwrap()),
                 _ => Some(Value::Array(multi_value.into_iter().collect())),
             }
         })
 }
lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (1)

77-95: Consider extracting flattening logic into a standalone helper.

Flattening arrays for non-wildcard keys is correct, but factoring this out into a small utility (e.g., flatten_one_level) may keep the code succinct and reusable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4149e6d and 7362bfe.

📒 Files selected for processing (3)
  • lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs (3 hunks)
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (7 hunks)
  • lib/segment/src/types.rs (1 hunks)
🔇 Additional comments (17)
lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (17)

8-8: Import usage looks good.


15-15: Good update to return multiple values.


103-103: Doc comment is helpful.


109-116: Integer index retrieval logic looks good.


120-127: Integer map index retrieval logic looks good.


142-150: DateTime index handling looks good.


155-162: Keyword index retrieval logic is consistent.


166-173: Geo index retrieval logic is consistent.


178-184: Boolean index retrieval logic looks straightforward.


188-195: UUID map index retrieval logic is correct.


199-206: UUID index retrieval logic is correct.


221-221: New import is needed for JSON manipulations.


223-223: Confirmed usage of MultiValue import.


292-294: Tests for numeric arrays in payload are accurate.


310-312: Tests for geo fields in payload are accurate.


363-365: Index-based numeric array tests look correct.


380-382: Index-based geo field tests look correct.

Copy link
Copy Markdown
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 (1)
lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (1)

136-137: Consider adding documentation for the multivalue filtering behavior.

While the implementation correctly filters out non-finite float values, adding a brief comment explaining this behavior would improve code readability and make the intent clearer for future maintainers.

    .filter_map(|v| Some(Value::Number(Number::from_f64(v)?)))
+   // filter_map with ? operator silently skips NaN and infinite values
    .collect()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7362bfe and 4891536.

📒 Files selected for processing (1)
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • 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: Basic TLS/HTTPS tests
  • GitHub Check: test-consensus-compose
  • GitHub Check: test (macos-latest)
  • GitHub Check: test-consensus
  • GitHub Check: test (windows-latest)
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (5)
lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs (5)

8-8: Well-implemented type change to support multivalues.

The change from returning a single optional value to returning MultiValue<Value> aligns well with the PR objective to return entire multivalue sets rather than just the first value.

Also applies to: 15-15


77-95: Good implementation of multivalue handling in payload retriever.

The updated logic appropriately handles both direct wildcard paths and regular paths with array values by flattening them into a single MultiValue collection. This ensures consistent behavior when retrieving multiple values from payloads.


130-140: Nicely handled potential non-finite float values.

The implementation now uses filter_map with optional unwrapping (Number::from_f64(v)?) which elegantly skips NaN or infinite values instead of panicking. This addresses the previous review comment about handling non-finite floats gracefully.


103-212: Well-structured retriever functions with consistent multivalue handling.

All indexed variable retrievers have been consistently updated to return MultiValue<Value> using the pattern of into_iter().flatten() to collect all values. This provides a unified approach across different index types.


292-295: Test assertions correctly updated for multivalue returns.

The test assertions have been properly updated to check for MultiValue instances instead of single optional values, which validates the changes in implementation.

Also applies to: 309-312, 363-366, 380-383

@coszio coszio added this to the score boosting milestone Mar 18, 2025
@coszio coszio merged commit c9f673e into dev Mar 19, 2025
@coszio coszio deleted the retriever-can-output-array branch March 19, 2025 15:56
timvisee pushed a commit that referenced this pull request Mar 21, 2025
* retrievers return multivalues

* adjust integration

* fix payload retriever

* graceful conversion
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