Skip to content

Add rabitq inner product distance computation support - #476

Merged
MaggieQi merged 16 commits into
users/qiazh/pre-merge-tikv-bugfixfrom
users/zhangt/rabitq_ipd
Nov 25, 2026
Merged

MaggieQi merged 16 commits into
users/qiazh/pre-merge-tikv-bugfixfrom
users/zhangt/rabitq_ipd

Conversation

@TerrenceZhangX

@TerrenceZhangX Terrence (TerrenceZhangX) commented Nov 23, 2026 •

Copy link
Copy Markdown

Changes

  • Add RaBitQ InnerProduct support and align its IP estimator with upstream.
  • Fix PQ/OPQ stored encoding to select the nearest codeword by L2, matching FAISS. Query scoring remains InnerProduct.
  • Preserve the original input data type in OPQ training arguments while converting training vectors to float32 for FAISS.
  • Add reproducible GloVe-100 IP benchmark scripts and results.

Benchmark results

GloVe-100: 1,183,514 base vectors, 10,000 queries, normalized inputs. Single-threaded IP search, MaxCheck=4000, SearchInternalResultNum=64, no reranking. Recall uses strict ground-truth ID matching.

Representation Recall10@10 Recall10@40 Search10 QPS Search40 QPS
Float32 83.389% 83.390% 319.57 318.78
RaBitQ4 75.780% 83.061% 346.32 343.53
OPQ50 72.843% 82.967% 353.45 327.56

OPQ was rebuilt and rerun after the encoding fix; Float32 and RaBitQ results are unchanged. Both quantized indexes have full ID coverage. Float32 has 10 missing IDs, which remain in the recall denominator.

Tao Zhang and others added 6 commits November 19, 2026 14:04
Store the centroid-corrected IP additive factor alongside unchanged L2 factors. Use six-factor codes with global/local model versions 6/7 and reject older formats instead of retaining legacy compatibility.

Cover upstream estimator equivalence, ADC/SDC persistence and unsupported model rejection; update encoded-width examples and format documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Comment thread AnnService/inc/Core/Common/BKTree.h Resolved
Comment thread AnnService/inc/Core/Common/BKTree.h Resolved
Comment thread AnnService/inc/Core/Common/BKTree.h Resolved
Tao Zhang and others added 7 commits November 24, 2026 09:50
Restore the tracked tree to c1c8f39 without rewriting branch history. Remove later normalization, head-maintenance, PQ/OPQ encoding and evaluation changes before rerunning matched GloVe IP experiments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Use L2 nearest-codeword assignment while retaining IP search scoring. Record the corrected OPQ-only rerun, preserve Float32 and RaBitQ baselines, and include the reproducible protocol and source fingerprints.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Use versions 5/6 for new IP models while retaining legacy 2/3/4 layouts. Clarify query-factor counts and single-cluster comments. Restore existing posting truncation and remove out-of-scope documentation, configuration, and added tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
Merge users/qiazh/pre-merge-tikv-bugfix through 220605b while preserving the RaBitQ IP changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 556e2fce-e45f-43c5-ae5a-77dd20b2f549
}
ret = std::make_shared<RaBitQQuantizer>();
if (ret->LoadQuantizer(raw_bytes) != ErrorCode::Success) {
if (std::static_pointer_cast<RaBitQQuantizer>(ret)->LoadQuantizer(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need cast? It is already shared_ptr?

Comment thread AnnService/inc/Core/Common/BKTree.h Outdated
return m_pQuantizer->L2DistanceSDC((const uint8_t*)pX, (const uint8_t*)pY);
};
else
else if (distMethod == DistCalcMethod::InnerProduct)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need a specific InnerProductDistanceSDC and InnerProductDistance? I think they are the same as CosineDistanceSDC and CosineDistance? In fact, without quantizer, the calculation of CosineDistance is the same as InnerProductDistance since we already do normalization for CosineDistance.

Comment thread AnnService/inc/Core/VectorIndex.h Resolved
// IP scores may be negative for distinct vectors and cannot test identity.
const bool innerProduct = m_headIndex->GetDistCalcMethod() == DistCalcMethod::InnerProduct;
const bool sameHead = !theSameHead && (innerProduct ? clusterHeadVID == headID :
m_headIndex->ComputeDistanceBetweenStoredVectors(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use L2Distance to judge whether it is the same or not?

@MaggieQi
MaggieQi merged commit 62deacc into users/qiazh/pre-merge-tikv-bugfix Nov 25, 2026
4 of 6 checks passed
@TerrenceZhangX
Terrence (TerrenceZhangX) deleted the users/zhangt/rabitq_ipd branch November 25, 2026 05:56
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.

2 participants