← Back to Pull requests

Add Jaccard distance support in CAGRA #2997

Closed
unknown closed this pull request without merging on Nov 24, 2026 21:41 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 00:19 UTC
Author

<!--

Thank you for contributing to cuvs :)

Here are some guidelines to help the review process go smoothly.

1. Please write a description in this text box of the changes that are being
made.

2. Please ensure that you have written units tests for the changes made/features
added.

3. If you are closing an issue please use one of the automatic closing words as
noted here: https://help.github.com/articles/closing-issues-using-keywords/

4. If your pull request is not ready for review but you want to make use of the
continuous integration testing facilities please label it with [WIP].

5. If your pull request is ready to be reviewed without requiring additional
work on top of it, then remove the [WIP] label (if present) and replace
it with [REVIEW]. If assistance is required to complete the functionality,
for example when the C/C++ code of a feature is complete but Python bindings
are still required, then add the label [HELP-REQ] so that others can triage
and assist. The additional changes then can be implemented on top of the
same PR. If the assistance is done by members of the cuVS team, then no
additional actions are required by the creator of the original PR for this,
otherwise the original author of the PR needs to give permission to the
person(s) assisting to commit to their personal fork of the project. If that
doesn't happen then a new PR based on the code of the original PR can be
opened by the person assisting, which then will be the PR that will be
merged.

6. Once all work has been done and review has taken place please do not add
features or make changes out of the scope of those requested by the reviewer
(doing this just add delays as already reviewed code ends up having to be
re-reviewed/it is hard to tell what is new etc!). Further, please do not
rebase your branch on master/force push/rewrite history, doing any of these
causes the context of any comments made by reviewers to be lost. If
conflicts occur against master they should be resolved by merging master
into the branch used for making the pull request.

Many thanks in advance for your cooperation!

-->

Summary

This PR adds BitwiseJaccard support to CAGRA and NN-descent for packed binary vectors

The distance is calculated directly from packed bytes:

differing = sum(popcount(a XOR b))
union = sum(popcount(a OR b))
distance = differing / union

Two empty vectors have distance zero. NN-descent, graph sorting, and CAGRA search use the same calculation.

The JIT implementation adds a defaulted compile-time IsJaccard template parameter to select a specialized worker in compute_distance_impl.cuh. The worker follows the existing vector-loading and query-layout conventions while accumulating and reducing both counts before division.

Closes #1158

Benchmarks

Datasets

Datasets need transformation to binary first. Using MNIST, Fashion-MNIST, and SIFT datasets here. MNIST and Fashion-MNIST use x > 127.5. SIFT uses per-dimension median thresholds fitted on the base dataset. Ground truth is recomputed using exhaustive binary Jaccard search.

A100-PCIE-40GB

Configs: k=10, batch_size=10000, intermediate_degree=128, graph_degree=[32, 64], max_iteration=20, itopk=[32, 64, 128, 256, 512]

Dataset | Build (s) | Search / 10,000 queries (ms) | QPS | Recall@10
-- | -- | -- | -- | --
MNIST · 60K × 784 | 0.720 | 63.477 | 157,536 | 99.571%
Fashion-MNIST · 60K × 784 | 0.733 | 63.120 | 158,429 | 99.461%
SIFT · 1M × 128 | 10.370 | 18.664 | 535,791 | 94.575%

<br class="Apple-interchange-newline">
<img width="1296" height="403" alt="image" src="https://github.com/user-attachments/assets/4bc8d634-284c-4b39-9c86-e3f92f808b12" />

Tests

Added C++ and Python tests covering:

  • Binary inputs across float32, float16, int8, and uint8.

  • SINGLE_CTA, MULTI_CTA, and MULTI_KERNEL search.

  • NN-descent and iterative graph construction.

  • Distance correctness against independent Jaccard references.

  • Empty vectors, duplicate vectors, and dimensions requiring padding.

  • Dataset replacement and cardinality refresh.

  • Unsupported builder configurations.
  • Diff: 534 lines (+400 / -134) across 6 files Reviewer: KyleFromNVIDIA Review duration: 31521m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 534 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2997"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.7% · Safe to merge
    20.7%
    Repository