Skip to content

Implement a metric space variant of geofilter#134

Open
aneubeck wants to merge 4 commits into
mainfrom
aneubeck/fast_diff
Open

Implement a metric space variant of geofilter#134
aneubeck wants to merge 4 commits into
mainfrom
aneubeck/fast_diff

Conversation

@aneubeck

@aneubeck aneubeck commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI review requested due to automatic review settings July 3, 2026 14:43
@aneubeck aneubeck requested a review from a team as a code owner July 3, 2026 14:43

Copilot AI 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.

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 / MetricSpace traits to model comparable, additive distance values and “measurable + comparable” spaces for NN search.
  • Implemented GeoDiffMetric + OnesMetric for GeoDiffCount, 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

Comment thread crates/geo_filters/src/diff_count/config.rs Outdated
Comment thread crates/geo_filters/evaluation/nearest_neighbor.rs Outdated
aneubeck and others added 2 commits July 6, 2026 08:15
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>
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