Skip to content

TQ variant for QuantizedVectorStorage - #8678

Merged
IvanPleshkov merged 4 commits into
devfrom
TQ-variant-for-QuantizedVectorStorage
Apr 16, 2026
Merged

IvanPleshkov merged 4 commits into
devfrom
TQ-variant-for-QuantizedVectorStorage

Conversation

@IvanPleshkov

@IvanPleshkov IvanPleshkov commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

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 f16 floats.

Open questions:

  • do we need to enable appendable TQ for each bits count?
  • do we need to rescore by default?

@IvanPleshkov IvanPleshkov added this to the TurboQuant milestone Apr 14, 2026
@IvanPleshkov IvanPleshkov mentioned this pull request Apr 14, 2026
63 of 69 tasks
Base automatically changed from empty-turbo-quant to dev April 15, 2026 08:07
@IvanPleshkov
IvanPleshkov marked this pull request as ready for review April 15, 2026 21:32

@coderabbitai coderabbitai Bot 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.

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 | 🟠 Major

The new TQ variants are not constructible through QuantizedVectors.

This file adds TQ storage cases, but create_impl/create_multi_impl and load_impl below still exhaustively handle only QuantizationConfig::{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

📥 Commits

Reviewing files that changed from the base of the PR and between acabdc0 and bc7821b.

📒 Files selected for processing (5)
  • lib/quantization/src/lib.rs
  • lib/quantization/src/turboquant/mod.rs
  • lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs
  • lib/segment/src/vector_storage/quantized/quantized_scorer_builder.rs
  • lib/segment/src/vector_storage/quantized/quantized_vectors.rs

Comment on lines +141 to +151
// 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!()

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.

⚠️ Potential issue | 🔴 Critical

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.

Comment on lines +174 to +176
fn encode_query(&self, _query: &[f32]) -> EncodedQueryTQ {
EncodedQueryTQ {}
}

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.

⚠️ Potential issue | 🔴 Critical

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!().

@JojiiOfficial

Copy link
Copy Markdown
Member

This PR also contains the changes from #8677
Could you maybe rebase it?

@IvanPleshkov
IvanPleshkov force-pushed the TQ-variant-for-QuantizedVectorStorage branch from bc7821b to ff84b6c Compare April 16, 2026 07:45
BinaryRam(EncodedVectorsBin<u128, QuantizedRamStorage>),
BinaryMmap(EncodedVectorsBin<u128, QuantizedMmapStorage>),
BinaryChunkedMmap(EncodedVectorsBin<u128, QuantizedChunkedMmapStorage>),
TQRam(EncodedVectorsTQ<QuantizedRamStorage>),

@IvanPleshkov IvanPleshkov Apr 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the key change

coderabbitai[bot]

This comment was marked as resolved.

@IvanPleshkov
IvanPleshkov merged commit e6c82db into dev Apr 16, 2026
15 checks passed
@IvanPleshkov
IvanPleshkov deleted the TQ-variant-for-QuantizedVectorStorage branch April 16, 2026 08:53
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 22, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 22, 2026
timvisee pushed a commit that referenced this pull request May 8, 2026
* TQ variant for QuantizedVectorStorage

* fix gpu build

* fix gpu build

* are you happy clippy
@coderabbitai coderabbitai Bot mentioned this pull request Jul 2, 2026
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