Skip to content

fix: evaluate values_count query condition on missing fields - #9592

Closed
onlyarnav wants to merge 1 commit into
qdrant:devfrom
onlyarnav:fix-values-count-missing-fields-dev
Closed

onlyarnav wants to merge 1 commit into
qdrant:devfrom
onlyarnav:fix-values-count-missing-fields-dev

Conversation

@onlyarnav

@onlyarnav onlyarnav commented Jun 27, 2026 •

Copy link
Copy Markdown

Summary

Fixes a bug where values_count filter queries returned incorrect results when evaluating points that were missing the target payload field.

Issue: #9586 & #9065

Problem

Previously, when a query condition evaluated a payload field that did not exist on a point (e.g. tags on a point with no tags field), the query engine fell back to calling check_empty() on the FieldCondition.

In FieldCondition::check_empty(), the values_count check was completely ignored (using a wildcard pattern values_count: _), causing it to default to false. This meant conditions like values_count with lt: 1, lte: 0, or gte: 0 (which should match a point missing the field since its value count is 0) incorrectly returned false.

Solution

  1. Updated FieldCondition::check_empty() in lib/segment/src/payload_storage/condition_checker.rs to evaluate the values_count check (if present) by calling values_count.check_empty(). This successfully checks conditions against a count of 0.
  2. Added unit tests in lib/segment/src/payload_storage/query_checker.rs to cover these scenarios:
    • values_count check with lt: 1 matching a missing field (value count of 0).
    • values_count check with gte: 0 matching a missing field.
    • values_count check with lte: 0 matching a missing field.

[Drafted by Claude Code (Opus 4.8)]

@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 9f95920b-bec9-4592-9fa7-5f144b8d8a6e

📥 Commits

Reviewing files that changed from the base of the PR and between 8f169f6 and e55250a.

📒 Files selected for processing (3)
  • lib/segment/src/payload_storage/condition_checker.rs
  • lib/segment/src/payload_storage/query_checker.rs
  • tests/openapi/test_filter_values_count.py
✅ Files skipped from review due to trivial changes (1)
  • lib/segment/src/payload_storage/query_checker.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/openapi/test_filter_values_count.py
  • lib/segment/src/payload_storage/condition_checker.rs

📝 Walkthrough

Walkthrough

FieldCondition::check_empty now treats values_count as zero for missing fields and delegates empty checks through ValuesCount. Unit coverage in query_checker adds missing-field assertions for lt: 1, gte: 0, and lte: 0, and the OpenAPI test verifies values_count.lte: 0 against scroll results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny peeks where payloads hide 🐰
Zero counts now trot outside
Missing keys still pass the gate
Hop-hop, the filters validate!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: evaluating values_count conditions for missing fields.
Description check ✅ Passed The description is directly related and accurately explains the bug fix, implementation, and tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
lib/segment/src/payload_storage/query_checker.rs (1)

494-533: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add one falsy missing-field case.

These assertions only cover matches. A regression that made missing fields satisfy every values_count filter would still pass, so please add one negative case like gt: 0 or lt: 0.

Suggested test addition
         let missing_value_count_condition_lte =
             Filter::new_must(Condition::Field(FieldCondition::new_values_count(
                 JsonPath::new("non_existent_field"),
                 ValuesCount {
                     lt: None,
                     gt: None,
                     gte: None,
                     lte: Some(0),
                 },
             )));
         assert!(payload_checker.check(0, &missing_value_count_condition_lte));
+
+        let missing_value_count_condition_gt =
+            Filter::new_must(Condition::Field(FieldCondition::new_values_count(
+                JsonPath::new("non_existent_field"),
+                ValuesCount {
+                    lt: None,
+                    gt: Some(0),
+                    gte: None,
+                    lte: None,
+                },
+            )));
+        assert!(!payload_checker.check(0, &missing_value_count_condition_gt));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/payload_storage/query_checker.rs` around lines 494 - 533, The
new missing-field values_count tests in query_checker should include at least
one negative assertion, not just matching cases. Add a falsy case in the
existing payload_checker check coverage around missing_value_count_condition so
a non-existent field with an impossible constraint like gt: 0 or lt: 0 is
asserted to fail, using the same FieldCondition::new_values_count and
Filter::new_must pattern to keep the test aligned with the current setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/segment/src/payload_storage/query_checker.rs`:
- Around line 494-533: The new missing-field values_count tests in query_checker
should include at least one negative assertion, not just matching cases. Add a
falsy case in the existing payload_checker check coverage around
missing_value_count_condition so a non-existent field with an impossible
constraint like gt: 0 or lt: 0 is asserted to fail, using the same
FieldCondition::new_values_count and Filter::new_must pattern to keep the test
aligned with the current setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: a01b9dfd-e6cb-4cb7-a245-86f83acfcc0f

📥 Commits

Reviewing files that changed from the base of the PR and between 99b730f and 898592d.

📒 Files selected for processing (2)
  • lib/segment/src/payload_storage/condition_checker.rs
  • lib/segment/src/payload_storage/query_checker.rs

@onlyarnav

Copy link
Copy Markdown
Author

Requesting a review or a suggestion!

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@generall

Copy link
Copy Markdown
Member

Hey @onlyarnav, thanks for the contrinution. I think the approach and implementation is correct, but there are some conflicts due to rebase. I will proceed with alrternative PR:

#9606
#9607

@generall generall closed this Jun 29, 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.

2 participants