Skip to main content

SparsePostingBlock

Struct SparsePostingBlock 

Source
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 owned Vecs. Used by eager cursors for small dimensions. Transitions the body from Encoded to Decoded on 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 a SparsePostingBlock. Used by lazy/view cursors for large dimensions where we only touch a fraction of each block’s entries.

Fields§

§header: PostingBlockHeader

The 16-byte header fields (num_entries, bits_per_delta, min/max offset, max weight).

Implementations§

Source§

impl SparsePostingBlock

Source

pub fn from_sorted_entries( entries: &[(u32, f32)], ) -> Result<Self, SparsePostingBlockError>

Build a block from pre-sorted (offset, value) pairs.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn offsets(&mut self) -> &[u32]

Decompressed doc offsets. Decodes on first call for deserialized posting blocks. Returns &[] for directory blocks.

Source

pub fn values(&mut self) -> &[f32]

Decompressed f32 weights. Decodes on first call for deserialized posting blocks. Returns &[] for directory blocks.

Source

pub fn serialize(&self) -> Vec<u8>

Serialize to bytes: 16-byte header + bitpacked deltas + f16 weights.

Source

pub fn serialized_size(&self) -> usize

Byte length of the serialized representation (computable without decompression).

Source

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.

Source

pub fn peek_header( bytes: &[u8], ) -> Result<PostingBlockHeader, SparsePostingBlockError>

Read the 16-byte header without heap allocation.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_directory(&self) -> bool

Trait Implementations§

Source§

impl Clone for SparsePostingBlock

Source§

fn clone(&self) -> SparsePostingBlock

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SparsePostingBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more