Skip to content

test: failing test for values_per_hash drift on duplicate geo point removal - #9043

Merged
generall merged 2 commits into
devfrom
fix/geo-index-values-per-hash-decrement-bug
May 14, 2026
Merged

generall merged 2 commits into
devfrom
fix/geo-index-values-per-hash-decrement-bug

Conversation

@qdrant-cloud-bot

Copy link
Copy Markdown
Contributor

Summary

  • Adds a regression test that exposes a bug in InMemoryGeoMapIndex::remove_point: decrement_hash_value_counts is called only once per unique geohash, while add_many_geo_points increments values_per_hash once per value. When a point has duplicate geo coordinates (producing the same geohash), the counters drift upward permanently after deletion.
  • The test inserts a point with 3 identical geo values, removes it, and asserts that values_of_hash returns 0 for the root hash. Currently it returns 2 (3 increments - 1 decrement = 2 leftover).

Context

Identified in review: #9033 (comment)

The fix would be to call decrement_hash_value_counts for every value before the uniqueness check in remove_point, moving it above the if !removed_geo_hashes.insert(...) guard (while keeping points_map cleanup and decrement_hash_point_counts per unique hash only).

Test plan

  • Test compiles and fails on current dev (demonstrates the bug)
  • CI should report this test failure

Made with Cursor

…nt removal

Reproduces the bug where `remove_point` only calls `decrement_hash_value_counts`
once per unique geohash, while `add_many_geo_points` increments it once per value.
When a point has duplicate geo coordinates (same geohash), the counters drift
upward permanently after removal.

Ref: #9033 (comment)
Co-authored-by: Cursor <[email protected]>
@coderabbitai

coderabbitai Bot commented May 14, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5caf9db-289d-4d54-84d6-e3fcc9e0ef85

📥 Commits

Reviewing files that changed from the base of the PR and between 07179e6 and 3258904.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/geo_index/mutable_geo_index/inner.rs
  • lib/segment/src/index/field_index/geo_index/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/index/field_index/geo_index/tests.rs

📝 Walkthrough

Walkthrough

This PR changes InMemoryGeoMapIndex::remove_point to decrement per-hash value counters for every removed geo value (including duplicates sharing the same GeoHash) and adds a regression test that inserts a point with three identical geo coordinates, removes it, and asserts point/value counts, root geohash value counts, and geo-radius cardinality estimation are zero for the empty index.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • generall
  • ffuugoo
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a failing regression test for a specific bug in duplicate geo point removal.
Description check ✅ Passed The description provides clear context about the bug, the test's purpose, expected behavior, and proposed fix.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/geo-index-values-per-hash-decrement-bug

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 and usage tips.

`add_many_geo_points` increments `values_per_hash` once per value, but
`remove_point` deduplicated geohashes with a HashSet + `continue` that
also skipped the per-value decrement. A point with duplicate geo
coordinates (same geohash) therefore left the counters drifted upward
permanently after removal.

Move `decrement_hash_value_counts` above the dedup guard so it runs once
per value, matching the increment side. `points_map` and
`points_per_hash` track points, not values, so they stay deduplicated.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@generall
generall merged commit 666912e into dev May 14, 2026
15 checks passed
@generall
generall deleted the fix/geo-index-values-per-hash-decrement-bug branch May 14, 2026 21:30
generall added a commit that referenced this pull request May 22, 2026
…emoval (#9043)

* test: add failing test for values_per_hash drift on duplicate geo point removal

Reproduces the bug where `remove_point` only calls `decrement_hash_value_counts`
once per unique geohash, while `add_many_geo_points` increments it once per value.
When a point has duplicate geo coordinates (same geohash), the counters drift
upward permanently after removal.

Ref: #9033 (comment)
Co-authored-by: Cursor <[email protected]>

* fix: decrement values_per_hash once per value on geo point removal

`add_many_geo_points` increments `values_per_hash` once per value, but
`remove_point` deduplicated geohashes with a HashSet + `continue` that
also skipped the per-value decrement. A point with duplicate geo
coordinates (same geohash) therefore left the counters drifted upward
permanently after removal.

Move `decrement_hash_value_counts` above the dedup guard so it runs once
per value, matching the increment side. `points_map` and
`points_per_hash` track points, not values, so they stay deduplicated.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: generall <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

3 participants