Skip to content

fix: count an explicit null payload value as 1 in values_count - #10144

Closed
hamodywe wants to merge 1 commit into
qdrant:devfrom
hamodywe:fix/values-count-explicit-null
Closed

hamodywe wants to merge 1 commit into
qdrant:devfrom
hamodywe:fix/values-count-explicit-null

Conversation

@hamodywe

@hamodywe hamodywe commented Aug 9, 2026 •

Copy link
Copy Markdown

check_count_from() treated an explicitly stored JSON null as zero values, so a values_count condition like {"gte": 1} excluded points whose payload contains the field with a null value. The documented contract says a stored non-array value counts as 1, and an explicit null is a stored value -- it is distinct from an absent field, which is the case check_empty() already handles (and which stays at 0).

Fixes #10113

All Submissions:

⚠️ PRs must target the dev branch. If your PR targets master, please change the base branch to dev before requesting a review.

  • My PR targets the dev branch (not master) and my branch was created 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 --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

check_count_from() treated an explicitly stored JSON null as zero
values, so a values_count condition like {"gte": 1} excluded points
whose payload contains the field with a null value. The documented
contract says a stored non-array value counts as 1, and an explicit
null is a stored value -- it is distinct from an absent field, which
is the case check_empty() already handles (and which stays at 0).

Fixes qdrant#10113
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

ValuesCount::check_count_from now counts an explicit JSON null as one stored value. Arrays continue to use their element count, and absent fields remain distinct. Regression tests verify that values_count >= 1 matches explicit null and excludes absent fields.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

  • qdrant/qdrant#9606: Concerns values_count semantics for missing and null payload fields.

Suggested reviewers: generall, xzfc

Poem

I’m a rabbit counting nulls in a row,
One stored value makes the query go.
Missing fields stay at zero ground,
Arrays count each element found.
Hop, test, and ship the fix today! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description clearly explains the bug, expected behavior, distinction from missing fields, tests, and linked issue.
Linked Issues check ✅ Passed The description references issue #10113, and the changes directly address the reported explicit-null counting defect.
Out of Scope Changes check ✅ Passed The changes are confined to values_count behavior and focused test coverage, with no unrelated modifications.
Title check ✅ Passed The title clearly and concisely states that explicit null payload values now count as one in values_count.

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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@lib/segment/src/types.rs`:
- Around line 3395-3399: Update the comment above the Value::Array match arm to
state that absent fields are handled by check_empty, while explicitly stored
empty arrays also produce a count of 0; retain the existing explanation that
explicit null counts as 1.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: c67c1abb-f2e5-4e30-88ab-f6263cf59bfc

📥 Commits

Reviewing files that changed from the base of the PR and between 1d18e46 and 30171a7.

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

Comment thread lib/segment/src/types.rs
Comment on lines +3395 to 3399
// An explicit `null` is a stored non-array value, so it counts as 1
// per the documented contract ("if stored value is not an array, the
// amount of values is assumed to be 1"). Only an *absent* field has
// a count of 0, which is handled by `check_empty`, not here.
Value::Array(array) => array.len(),

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the comment about zero counts.

Value::Array(array) => array.len() returns 0 for an explicitly stored empty array. Therefore, “Only an absent field has a count of 0” is incorrect. State that absent fields are handled by check_empty, while empty arrays also produce zero.

Proposed wording fix
-            // amount of values is assumed to be 1"). Only an *absent* field has
-            // a count of 0, which is handled by `check_empty`, not here.
+            // amount of values is assumed to be 1"). Absent fields are handled
+            // by `check_empty`; an empty array also has a count of 0.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// An explicit `null` is a stored non-array value, so it counts as 1
// per the documented contract ("if stored value is not an array, the
// amount of values is assumed to be 1"). Only an *absent* field has
// a count of 0, which is handled by `check_empty`, not here.
Value::Array(array) => array.len(),
// An explicit `null` is a stored non-array value, so it counts as 1
// per the documented contract ("if stored value is not an array, the
// amount of values is assumed to be 1"). Absent fields are handled
// by `check_empty`; an empty array also has a count of 0.
Value::Array(array) => array.len(),
🤖 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/types.rs` around lines 3395 - 3399, Update the comment above
the Value::Array match arm to state that absent fields are handled by
check_empty, while explicitly stored empty arrays also produce a count of 0;
retain the existing explanation that explicit null counts as 1.

@generall

Copy link
Copy Markdown
Member

Thanks for the report. We won't be changing this: #10113, which this PR fixes, was closed as not planned — an explicit null is treated as no value throughout the payload semantics (is_empty matches it, is_null finds it), so counting it as 1 would make the same point match both is_empty and values_count >= 1. The documentation sentence is what needs correcting, in qdrant/landing_page. Closing as not planned.

@generall generall added area/payload-index payload field indexes and filtering wontfix Out of scope or declined; the closing comment says why labels Aug 30, 2026
@generall generall closed this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/payload-index payload field indexes and filtering wontfix Out of scope or declined; the closing comment says why

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants