Skip to content

Add reproducing test for spurious geo index warning on duplicate geo values - #8404

Merged
generall merged 3 commits into
devfrom
fix/geo-index-duplicate-hash-warning
Mar 26, 2026
Merged

generall merged 3 commits into
devfrom
fix/geo-index-duplicate-hash-warning

Conversation

@qdrant-cloud-bot

@qdrant-cloud-bot qdrant-cloud-bot commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a reproducing test for a bug where InMemoryGeoMapIndex::remove_point logs spurious warnings: "Geo index error: no points for hash X was found" when a point has multiple geo values that produce the same max-precision geohash (e.g. duplicate coordinates in a multi-value geo field).
  • The root cause is an asymmetry: point_to_values stores all values including duplicates, but points_map uses a HashSet so duplicates are collapsed into one entry. During removal the loop processes each value individually — the first iteration removes the points_map entry, and the second iteration for the same hash can't find it.
  • Adds a debug_assert! in remove_point (matching the existing pattern in decrement_hash_value_counts) so the issue is caught in debug/test builds.
  • test_remove_point_with_duplicate_geo_values — directly reproduces the bug (currently fails via the debug_assert!).
  • test_frequent_add_remove_geo_points — exercises repeated add/remove cycles to cover the user-reported scenario (passes).

Test plan

  • test_remove_point_with_duplicate_geo_values reproduces the bug (panics on debug_assert!)
  • test_frequent_add_remove_geo_points passes
  • All 33 existing geo index tests pass

Fix for code:

  • During insertions hash values are deduplicated, so we should expect the same on deletions
  • Replace warn with just debug_assert, as releted code branch, even if execured, should not corrupt anything.

…values

When a point has multiple geo values that produce the same max-precision
geohash (e.g. duplicate coordinates in a multi-value geo field),
`InMemoryGeoMapIndex::remove_point` logs a spurious warning:
"Geo index error: no points for hash X was found".

The root cause is an asymmetry between `point_to_values` (stores all
values including duplicates) and `points_map` (uses a HashSet, so
duplicates are collapsed). During removal the loop processes each value
individually — the first iteration removes the `points_map` entry, and
subsequent iterations for the same hash can't find it.

This commit adds:
- A `debug_assert!` in `remove_point` (matching the existing pattern in
  `decrement_hash_value_counts`) to make the issue detectable in tests.
- `test_remove_point_with_duplicate_geo_values` — reproduces the bug by
  adding a point with `[BERLIN, BERLIN]` then removing it.
- `test_frequent_add_remove_geo_points` — exercises repeated add/remove
  cycles to cover the user-reported scenario.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaces the removed-geo-hash storage from a Vec to an AHashSet to deduplicate hashes during removal and adjust related call sites and helper signature to accept an iterator (impl IntoIterator<Item = GeoHash>). Removal now skips duplicate hashes early and uses debug_assert when a hash is missing from the points map instead of emitting a warning; behavior still returns false for is_last in that branch. Adds two new tests exercising removal of points with duplicate geo values and repeated add/remove cycles to validate multi-value geo handling and index stability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • timvisee
  • agourlay
  • ffuugoo
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: adding a reproducing test for a spurious geo index warning on duplicate geo values, which matches the changeset focus.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description clearly explains the bug (spurious warnings from duplicate geo values), identifies the root cause (asymmetry between point_to_values and points_map), and describes the changes made (adding tests and a debug_assert).

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/geo-index-duplicate-hash-warning
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

@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 the current code and only fix it if needed.

Inline comments:
In `@lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs`:
- Around line 503-508: The remove_point path in mutable_geo_index::remove_point
currently unconditionally removes the geohash entry from points_map and triggers
debug_assert! when a duplicate value with the same geohash is processed; change
remove_point so it maintains per-value counts and only removes the points_map
entry for a given geohash when the last stored value for that geohash is
removed. Concretely, in remove_point (and any helper like decrement/remove
logic), look up the entry in points_map using the Entry API or get_mut,
decrement the counter for the specific value (or remove the value key) and only
remove the entire geohash key from points_map if the inner map/set becomes
empty; remove the unconditional debug_assert! that assumed the geohash must
exist on second duplicate removal and instead handle the absent-entry case
gracefully (no panic) while preserving correct per-value count semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3572e81c-337f-4cb7-98c7-8ae2a1396415

📥 Commits

Reviewing files that changed from the base of the PR and between 09c0ad6 and b99b865.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/geo_index/mod.rs
  • lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs

@robcaulk

Copy link
Copy Markdown

I've had Claude spending quite a bit of time on this. Here is its assessment of the current PR:

This PR is tests + assertion only — it does not fix the bug. Here's my assessment:

What it does right:

Correctly identifies and reproduces the exact root cause (duplicate geohash collision in multi-value fields)
test_remove_point_with_duplicate_geo_values will fail on the debug_assert! in debug builds, proving the bug
test_frequent_add_remove_geo_points covers the basic add/delete churn scenario
What's missing:

No actual fix. The debug_assert!(false, ...) just panics in debug/test builds. In release builds, nothing changes — you still get the warning and the count corruption in values_per_hash / points_per_hash.
The test test_remove_point_with_duplicate_geo_values will fail as-is (the debug_assert fires during index.remove_point(0)). So this PR can't be merged without either fixing the bug or removing the assert. It's essentially a "red test" PR that demonstrates the problem.
What a fix would look like — in remove_point, deduplicate the hashes before iterating:


// Instead of iterating removed_geo_points directly,
// collect unique hashes first:
let mut hash_counts: HashMap<GeoHash, usize> = HashMap::new();
for geo_hash in &removed_geo_hashes {
    *hash_counts.entry(*geo_hash).or_default() += 1;
}
for (geo_hash, _count) in hash_counts {
    // remove from points_map once per unique hash
    // decrement values_per_hash by count, not 1
}
This looks like a "step 1" PR to get consensus on the diagnosis before submitting the fix. Worth asking the author if the fix is coming in a follow-up.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs (1)

497-521: ⚠️ Potential issue | 🔴 Critical

AHashSet::insert() returns true for newly inserted values, making the condition logic inverted.

At Line 497, insert() returns true when the hash is first seen, but the code continues (skips) on true. This causes the first occurrence to bypass points_map removal and decrement_hash_value_counts(), leaving stale entries and incorrect counts. Only duplicates are processed, which is backwards.

Rename to is_new_hash for clarity and move the processing block inside if is_new_hash to handle only the first occurrence. Always call decrement_hash_value_counts() for every removed value (including duplicates).

Proposed fix
-            let already_seen = removed_geo_hashes.insert(removed_geo_hash);
-
-            if already_seen {
-                continue;
-            }
-
-            let is_last = if let Some(hash_ids) = self.points_map.get_mut(&removed_geo_hash) {
-                hash_ids.remove(&idx);
-                hash_ids.is_empty()
-            } else {
-                debug_assert!(
-                    false,
-                    "Geo index error: no points for hash {removed_geo_hash} was found",
-                );
-                false
-            };
-
-            if is_last {
-                self.points_map.remove(&removed_geo_hash);
-            }
-
-            self.decrement_hash_value_counts(&removed_geo_hash);
+            let is_new_hash = removed_geo_hashes.insert(removed_geo_hash);
+
+            if is_new_hash {
+                let is_last = if let Some(hash_ids) = self.points_map.get_mut(&removed_geo_hash) {
+                    hash_ids.remove(&idx);
+                    hash_ids.is_empty()
+                } else {
+                    debug_assert!(
+                        false,
+                        "Geo index error: no points for hash {removed_geo_hash} was found",
+                    );
+                    false
+                };
+
+                if is_last {
+                    self.points_map.remove(&removed_geo_hash);
+                }
+            }
+
+            self.decrement_hash_value_counts(&removed_geo_hash);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs` around
lines 497 - 521, The logic using removed_geo_hashes.insert(...) is inverted:
AHashSet::insert returns true for a newly-seen hash, so rename the boolean to
is_new_hash = removed_geo_hashes.insert(removed_geo_hash) and move the
points_map removal/cleanup (the block that gets &mut hash_ids, removes idx,
checks is_empty and possibly self.points_map.remove) inside if is_new_hash so
the first occurrence does the map cleanup; additionally ensure
self.decrement_hash_value_counts(&removed_geo_hash) is called for every removed
value (keep it outside the if so duplicates also decrement), and leave the final
self.decrement_hash_point_counts(removed_geo_hashes) call as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs`:
- Around line 497-521: The logic using removed_geo_hashes.insert(...) is
inverted: AHashSet::insert returns true for a newly-seen hash, so rename the
boolean to is_new_hash = removed_geo_hashes.insert(removed_geo_hash) and move
the points_map removal/cleanup (the block that gets &mut hash_ids, removes idx,
checks is_empty and possibly self.points_map.remove) inside if is_new_hash so
the first occurrence does the map cleanup; additionally ensure
self.decrement_hash_value_counts(&removed_geo_hash) is called for every removed
value (keep it outside the if so duplicates also decrement), and leave the final
self.decrement_hash_point_counts(removed_geo_hashes) call as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32f298b7-313c-44d1-b39c-80de4f0c0240

📥 Commits

Reviewing files that changed from the base of the PR and between b99b865 and 2e83520.

📒 Files selected for processing (1)
  • lib/segment/src/index/field_index/geo_index/mutable_geo_index.rs

@generall

Copy link
Copy Markdown
Member

@robcaulk should fix now.

@generall
generall requested a review from IvanPleshkov March 18, 2026 12:00
@generall
generall merged commit 9a14ed7 into dev Mar 26, 2026
15 checks passed
@generall
generall deleted the fix/geo-index-duplicate-hash-warning branch March 26, 2026 10:54
generall added a commit that referenced this pull request Mar 26, 2026
…values (#8404)

* Add reproducing test for spurious geo index warning on duplicate geo values

When a point has multiple geo values that produce the same max-precision
geohash (e.g. duplicate coordinates in a multi-value geo field),
`InMemoryGeoMapIndex::remove_point` logs a spurious warning:
"Geo index error: no points for hash X was found".

The root cause is an asymmetry between `point_to_values` (stores all
values including duplicates) and `points_map` (uses a HashSet, so
duplicates are collapsed). During removal the loop processes each value
individually — the first iteration removes the `points_map` entry, and
subsequent iterations for the same hash can't find it.

This commit adds:
- A `debug_assert!` in `remove_point` (matching the existing pattern in
  `decrement_hash_value_counts`) to make the issue detectable in tests.
- `test_remove_point_with_duplicate_geo_values` — reproduces the bug by
  adding a point with `[BERLIN, BERLIN]` then removing it.
- `test_frequent_add_remove_geo_points` — exercises repeated add/remove
  cycles to cover the user-reported scenario.

Made-with: Cursor

* fix: redulplicate hash IDs, replace warn with debug assertion

* fmt

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: generall <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
…values (#8404)

* Add reproducing test for spurious geo index warning on duplicate geo values

When a point has multiple geo values that produce the same max-precision
geohash (e.g. duplicate coordinates in a multi-value geo field),
`InMemoryGeoMapIndex::remove_point` logs a spurious warning:
"Geo index error: no points for hash X was found".

The root cause is an asymmetry between `point_to_values` (stores all
values including duplicates) and `points_map` (uses a HashSet, so
duplicates are collapsed). During removal the loop processes each value
individually — the first iteration removes the `points_map` entry, and
subsequent iterations for the same hash can't find it.

This commit adds:
- A `debug_assert!` in `remove_point` (matching the existing pattern in
  `decrement_hash_value_counts`) to make the issue detectable in tests.
- `test_remove_point_with_duplicate_geo_values` — reproduces the bug by
  adding a point with `[BERLIN, BERLIN]` then removing it.
- `test_frequent_add_remove_geo_points` — exercises repeated add/remove
  cycles to cover the user-reported scenario.

Made-with: Cursor

* fix: redulplicate hash IDs, replace warn with debug assertion

* fmt

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: generall <[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.

5 participants