Repository navigation
TQ variant for QuantizedVectorStorage - #8678
Conversation
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/segment/src/vector_storage/quantized/quantized_vectors.rs (1)
130-168:⚠️ Potential issue | 🟠 MajorThe new TQ variants are not constructible through
QuantizedVectors.This file adds TQ storage cases, but
create_impl/create_multi_implandload_implbelow still exhaustively handle onlyQuantizationConfig::{Scalar, Product, Binary}. As written, the standard create/load flow cannot produce or reload any of these new variants.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/vector_storage/quantized/quantized_vectors.rs` around lines 130 - 168, The new TQ enum variants in QuantizedVectorStorage are never constructed because create_impl, create_multi_impl and load_impl only match QuantizationConfig::{Scalar, Product, Binary}; update those functions to add branches for the TQ quantization config (e.g., QuantizationConfig::TQ) that construct the corresponding TQ variants (TQRam, TQMmap, TQChunkedMmap and the multi variants TQRamMulti/TQMmapMulti/TQChunkedMmapMulti) using EncodedVectorsTQ and the existing Quantized*Storage types so that both single and multi-vector create/load flows can produce and reload TQ storage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/quantization/src/turboquant/mod.rs`:
- Around line 174-176: encode_query currently returns an empty EncodedQueryTQ
and the two TQ scoring code paths are left as todo!(), causing runtime panics
when the scorer stack routes TQ searches; implement encode_query(&self, _query:
&[f32]) to produce a valid EncodedQueryTQ populated from the input float slice
(convert/quantize the query vector into the fields expected by EncodedQueryTQ),
and replace the todo!()s in the TQ scoring paths with calls into the actual TQ
scoring implementation (or return a proper Result/score) so the scorer stack can
execute without panicking; locate and update the encode_query function and the
two scoring blocks referenced in the diff so they return meaningful,
non-panicking results or propagate errors instead of todo!().
- Around line 141-151: The two todo!()s cause panics for any TQ-backed ops;
implement get_quantized_vector_size and encode_vector so layout() and
upsert_vector() can run. In get_quantized_vector_size(VectorParameters, TQBits,
TQMode) compute and return the exact byte length for a quantized vector using
the vector dimension from VectorParameters and the bit-packing for the given
TQBits/TQMode (account for per-component quantization, any headers/metadata and
alignment/padding required by the TQ format). In encode_vector(&[f32], TQBits,
TQMode) perform the quantization and bit-packing of the f32 slice into a Vec<u8>
using the same packing rules used to calculate size (support each TQBits variant
and mode branch), and ensure it returns an empty or zeroed vector only on
zero-length input rather than panicking. Use the function names
get_quantized_vector_size and encode_vector to locate and replace the todo!()s
so callers no longer panic.
---
Outside diff comments:
In `@lib/segment/src/vector_storage/quantized/quantized_vectors.rs`:
- Around line 130-168: The new TQ enum variants in QuantizedVectorStorage are
never constructed because create_impl, create_multi_impl and load_impl only
match QuantizationConfig::{Scalar, Product, Binary}; update those functions to
add branches for the TQ quantization config (e.g., QuantizationConfig::TQ) that
construct the corresponding TQ variants (TQRam, TQMmap, TQChunkedMmap and the
multi variants TQRamMulti/TQMmapMulti/TQChunkedMmapMulti) using EncodedVectorsTQ
and the existing Quantized*Storage types so that both single and multi-vector
create/load flows can produce and reload TQ storage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e698ecac-b72f-4b23-9d9b-7ab919bf51d6
📒 Files selected for processing (5)
lib/quantization/src/lib.rslib/quantization/src/turboquant/mod.rslib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rslib/segment/src/vector_storage/quantized/quantized_scorer_builder.rslib/segment/src/vector_storage/quantized/quantized_vectors.rs
| // Get quantized vector size in bytes | ||
| pub fn get_quantized_vector_size( | ||
| _vector_parameters: &VectorParameters, | ||
| _bits: TQBits, | ||
| _mode: TQMode, | ||
| ) -> usize { | ||
| todo!() | ||
| } | ||
|
|
||
| fn encode_vector(_vector_data: &[f32], _bits: TQBits, _mode: TQMode) -> Vec<u8> { | ||
| todo!() |
There was a problem hiding this comment.
todo!() still breaks TQ encode/update paths.
These helpers are on the hot path for quantized_vector_size(), layout(), and upsert_vector(), so any TQ-backed layout lookup or vector update will panic immediately.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/quantization/src/turboquant/mod.rs` around lines 141 - 151, The two
todo!()s cause panics for any TQ-backed ops; implement get_quantized_vector_size
and encode_vector so layout() and upsert_vector() can run. In
get_quantized_vector_size(VectorParameters, TQBits, TQMode) compute and return
the exact byte length for a quantized vector using the vector dimension from
VectorParameters and the bit-packing for the given TQBits/TQMode (account for
per-component quantization, any headers/metadata and alignment/padding required
by the TQ format). In encode_vector(&[f32], TQBits, TQMode) perform the
quantization and bit-packing of the f32 slice into a Vec<u8> using the same
packing rules used to calculate size (support each TQBits variant and mode
branch), and ensure it returns an empty or zeroed vector only on zero-length
input rather than panicking. Use the function names get_quantized_vector_size
and encode_vector to locate and replace the todo!()s so callers no longer panic.
| fn encode_query(&self, _query: &[f32]) -> EncodedQueryTQ { | ||
| EncodedQueryTQ {} | ||
| } |
There was a problem hiding this comment.
TQ scoring is still wired to panic.
encode_query() produces an empty query object, and both scoring paths are todo!(). With the new TQ storage variants now routed through the scorer stack, any TQ search will abort at runtime.
Also applies to: 188-200, 257-267
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/quantization/src/turboquant/mod.rs` around lines 174 - 176, encode_query
currently returns an empty EncodedQueryTQ and the two TQ scoring code paths are
left as todo!(), causing runtime panics when the scorer stack routes TQ
searches; implement encode_query(&self, _query: &[f32]) to produce a valid
EncodedQueryTQ populated from the input float slice (convert/quantize the query
vector into the fields expected by EncodedQueryTQ), and replace the todo!()s in
the TQ scoring paths with calls into the actual TQ scoring implementation (or
return a proper Result/score) so the scorer stack can execute without panicking;
locate and update the encode_query function and the two scoring blocks
referenced in the diff so they return meaningful, non-panicking results or
propagate errors instead of todo!().
|
This PR also contains the changes from #8677 |
bc7821b to
ff84b6c
Compare
| BinaryRam(EncodedVectorsBin<u128, QuantizedRamStorage>), | ||
| BinaryMmap(EncodedVectorsBin<u128, QuantizedMmapStorage>), | ||
| BinaryChunkedMmap(EncodedVectorsBin<u128, QuantizedChunkedMmapStorage>), | ||
| TQRam(EncodedVectorsTQ<QuantizedRamStorage>), |
There was a problem hiding this comment.
This is the key change
* TQ variant for QuantizedVectorStorage * fix gpu build * fix gpu build * are you happy clippy
This PR is a part of TQ integration.
It adds a new TQ variant for
QuantizedVectorStorage.Also, it adds a tmp GPU fallback. In case of TQ, we fallback to
f16floats.Open questions: