pub struct SparsePostingBlock {
pub header: PostingBlockHeader,
/* private fields */
}Expand description
A compressed block of posting list entries for sparse vector search.
§On-disk format
┌────────────────────────────── 16-byte header ─────────────────────────────┐
│ num_entries(u16) │ bits_per_delta(u8) │ reserved(u8) │ min_offset(u32) │ │
│ max_offset(u32) │ max_weight(f32) │
└──────────────────────────────────────────────────────────────────────────┘
┌──── body ────────────────────────────────────────────────────────────────┐
│ bitpacked delta-encoded doc offsets (BitPacker4x, groups of 128) │
│ — ceil(num_entries / 128) groups, last group padded to 128 entries │
│ f16 little-endian weights (2 bytes × num_entries, no padding) │
└──────────────────────────────────────────────────────────────────────────┘§Dual access modes
This type supports two access patterns used by different cursor modes in the query pipeline:
-
Materialized (
decode()): Decompresses the full block into ownedVecs. Used by eager cursors for small dimensions. Transitions the body fromEncodedtoDecodedon first call. -
Zero-copy (
peek_header,decompress_offsets_into,read_value_at,raw_weight_bytes): Static methods that operate directly on a&[u8]slice (e.g. from an Arrow block cache) without constructing aSparsePostingBlock. Used by lazy/view cursors for large dimensions where we only touch a fraction of each block’s entries.
Fields§
§header: PostingBlockHeaderThe 16-byte header fields (num_entries, bits_per_delta, min/max offset, max weight).
Implementations§
Source§impl SparsePostingBlock
impl SparsePostingBlock
Sourcepub fn from_sorted_entries(
entries: &[(u32, f32)],
) -> Result<Self, SparsePostingBlockError>
pub fn from_sorted_entries( entries: &[(u32, f32)], ) -> Result<Self, SparsePostingBlockError>
Build a block from pre-sorted (offset, value) pairs.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn decode(&mut self) -> (&[u32], &[f32])
pub fn decode(&mut self) -> (&[u32], &[f32])
Decode this block in place, transitioning from Encoded to Decoded.
Returns (&[u32], &[f32]) — the decompressed offsets and values.
If already Decoded, returns the existing data. Returns empty
slices for directory blocks (which are always Encoded and have
no posting-block-shaped body).
Callers do not need to call this directly — offsets() and
values() invoke it automatically.
Sourcepub fn offsets(&mut self) -> &[u32]
pub fn offsets(&mut self) -> &[u32]
Decompressed doc offsets. Decodes on first call for deserialized
posting blocks. Returns &[] for directory blocks.
Sourcepub fn values(&mut self) -> &[f32]
pub fn values(&mut self) -> &[f32]
Decompressed f32 weights. Decodes on first call for deserialized
posting blocks. Returns &[] for directory blocks.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
pub fn serialize(&self) -> Vec<u8> ⓘ
Serialize to bytes: 16-byte header + bitpacked deltas + f16 weights.
Sourcepub fn serialized_size(&self) -> usize
pub fn serialized_size(&self) -> usize
Byte length of the serialized representation (computable without decompression).
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self, SparsePostingBlockError>
pub fn deserialize(bytes: &[u8]) -> Result<Self, SparsePostingBlockError>
Deserialize from bytes. Stores body bytes as Encoded; call
decode() to decompress posting blocks on first access.
Returns an error if the buffer is too small for the header or the body is shorter than the header implies.
Sourcepub fn peek_header(
bytes: &[u8],
) -> Result<PostingBlockHeader, SparsePostingBlockError>
pub fn peek_header( bytes: &[u8], ) -> Result<PostingBlockHeader, SparsePostingBlockError>
Read the 16-byte header without heap allocation.
Sourcepub fn decompress_offsets_into(
bytes: &[u8],
hdr: &PostingBlockHeader,
buf: &mut Vec<u32>,
)
pub fn decompress_offsets_into( bytes: &[u8], hdr: &PostingBlockHeader, buf: &mut Vec<u32>, )
Decompress offsets from raw serialized bytes into a reusable buffer. Must not be called on directory blocks.
Sourcepub fn raw_weight_bytes<'a>(
bytes: &'a [u8],
hdr: &PostingBlockHeader,
) -> &'a [u8] ⓘ
pub fn raw_weight_bytes<'a>( bytes: &'a [u8], hdr: &PostingBlockHeader, ) -> &'a [u8] ⓘ
Zero-copy slice of the raw f16 weight bytes from serialized data. Each weight is 2 bytes (f16 little-endian). Must not be called on directory blocks.
Sourcepub fn read_value_at(
bytes: &[u8],
hdr: &PostingBlockHeader,
index: usize,
) -> f32
pub fn read_value_at( bytes: &[u8], hdr: &PostingBlockHeader, index: usize, ) -> f32
Read a single f16 weight at index and convert to f32. O(1).
Must not be called on directory blocks.
Sourcepub fn decompress_values_into(
bytes: &[u8],
hdr: &PostingBlockHeader,
buf: &mut Vec<f32>,
)
pub fn decompress_values_into( bytes: &[u8], hdr: &PostingBlockHeader, buf: &mut Vec<f32>, )
Decompress f16 weights from raw serialized bytes into a reusable f32 buffer. Must not be called on directory blocks.
pub fn is_directory(&self) -> bool
Trait Implementations§
Source§impl Clone for SparsePostingBlock
impl Clone for SparsePostingBlock
Source§fn clone(&self) -> SparsePostingBlock
fn clone(&self) -> SparsePostingBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SparsePostingBlock
impl RefUnwindSafe for SparsePostingBlock
impl Send for SparsePostingBlock
impl Sync for SparsePostingBlock
impl Unpin for SparsePostingBlock
impl UnsafeUnpin for SparsePostingBlock
impl UnwindSafe for SparsePostingBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.