Implement a metric space variant of geofilter#134
Open
aneubeck wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a metric-space-friendly similarity API for GeoDiffCount to enable nearest-neighbor search optimizations that rely on the triangle inequality (and reverse-triangle lower bounds), using exact Hamming distance over the filter bit representation.
Changes:
- Added
Metric/MetricSpacetraits to model comparable, additive distance values and “measurable + comparable” spaces for NN search. - Implemented
GeoDiffMetric+OnesMetricforGeoDiffCount, including early-abandon distance computation with an O(1) reverse-triangle lower bound. - Added documentation and a Criterion benchmark (
nearest_neighbor) to compare calibrated estimates vs exact/capped one-bit distance.
Show a summary per file
| File | Description |
|---|---|
| crates/geo_filters/src/lib.rs | Adds public Metric / MetricSpace traits used by nearest-neighbor search code. |
| crates/geo_filters/src/diff_count/metric.rs | Implements OnesMetric and GeoDiffMetric with early-abandon Hamming-distance computation + tests. |
| crates/geo_filters/src/diff_count/config.rs | Exposes expected_diff_buckets for reuse by the metric implementation. |
| crates/geo_filters/src/diff_count/bitvec.rs | Adds helpers (count_ones, blocks) to support faster distance computation. |
| crates/geo_filters/src/diff_count.rs | Wires in the new metric module and re-exports metric types. |
| crates/geo_filters/README.md | Documents the new nearest-neighbor metric approach and provides usage + benchmark numbers. |
| crates/geo_filters/evaluation/nearest_neighbor.rs | Adds Criterion benchmark for NN-style candidate scanning and pruning. |
| crates/geo_filters/Cargo.toml | Registers the new nearest_neighbor benchmark target. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 8/8 changed files
- Comments generated: 2
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This version was created in order to take advantage of the triangle inequality during nearest neighbor searches.
With the existing approach, the triangle inequality is not guaranteed and using it would lead to potentially "incorrect" results.
This new version is trivially satisfying the triangle inequality, since it equals to hamming distance computations in the geometric space. Another advantage of this new version is that it doesn't map into the final set metric space which is not needed in case of nearest neighbor search.
This new version can be significantly faster when distance computations are the bottleneck.