-
Notifications
You must be signed in to change notification settings - Fork 780
feat(index): inject globally-trained SQ bounds through the build params #7901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa9d942
dca1acd
3b40a21
06581a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -465,6 +465,7 @@ pub fn get_vector_index_params( | |
| Ok(SQBuildParams { | ||
| num_bits, | ||
| sample_rate, | ||
| bounds: None, | ||
| }) | ||
| }, | ||
| )?; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,18 @@ pub struct SQBuildParams { | |
|
|
||
| /// Sample rate for training. | ||
| pub sample_rate: usize, | ||
|
|
||
| /// User-provided, globally-trained quantization bounds. When set, per-build | ||
| /// training is skipped and these exact bounds are used, so codes are | ||
| /// comparable across independently built shards (mirrors | ||
| /// `PQBuildParams::codebook`). | ||
| /// | ||
| /// Must be the global min/max in the quantizer's **post-transform** space: | ||
| /// cosine indexes L2-normalize first, so cosine bounds cover the normalized | ||
| /// components (`-1.0..=1.0`), not the raw values; L2/dot use the raw | ||
| /// min/max. Bounds that don't cover that space clip every code to 0 and | ||
| /// silently collapse the index. | ||
| pub bounds: Option<std::ops::Range<f64>>, | ||
|
Comment on lines
+14
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Preserve compatibility for existing Adding As per coding guidelines, “Do not break public API signatures; deprecate old APIs with 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
|
|
||
| impl From<&SQBuildParams> for crate::pb::vector_index_details::ScalarQuantization { | ||
|
|
@@ -25,6 +37,30 @@ impl Default for SQBuildParams { | |
| Self { | ||
| num_bits: 8, | ||
| sample_rate: 256, | ||
| bounds: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl SQBuildParams { | ||
| /// Create build params carrying pre-trained bounds, skipping training. | ||
| /// | ||
| /// Use this so independently built shards of a distributed index quantize | ||
| /// on the same scale and their segments stay mergeable (see [`bounds`]). | ||
| /// | ||
| /// ``` | ||
| /// use lance_index::vector::sq::builder::SQBuildParams; | ||
| /// // Every shard builds against the globally-trained min/max: | ||
| /// let params = SQBuildParams::with_bounds(8, 0.0..1.0); | ||
| /// assert_eq!(params.bounds, Some(0.0..1.0)); | ||
| /// ``` | ||
| /// | ||
| /// [`bounds`]: SQBuildParams::bounds | ||
| pub fn with_bounds(num_bits: u16, bounds: std::ops::Range<f64>) -> Self { | ||
| Self { | ||
| num_bits, | ||
| bounds: Some(bounds), | ||
| ..Default::default() | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.