pub struct FlatVectorData {
pub dim: usize,
pub doc_ids: Vec<(u32, u16)>,
/* private fields */
}Expand description
Flat vector data for brute-force search.
Uses a single contiguous Vec<f32> instead of Vec<Vec<f32>>.
Loading is a single bulk memcpy (1 allocation) instead of N separate
allocations with float-by-float parsing. For 3.3M vectors at 768 dims
this reduces load time from ~36s to ~1s.
Fields§
§dim: usize§doc_ids: Vec<(u32, u16)>Document IDs with ordinals: (doc_id, ordinal) pairs Ordinal tracks which vector in a multi-valued field
Implementations§
Source§impl FlatVectorData
impl FlatVectorData
Sourcepub fn num_vectors(&self) -> usize
pub fn num_vectors(&self) -> usize
Number of vectors
Sourcepub fn get_vector(&self, idx: usize) -> &[f32]
pub fn get_vector(&self, idx: usize) -> &[f32]
Sourcepub fn get_doc_id(&self, idx: usize) -> (u32, u16)
pub fn get_doc_id(&self, idx: usize) -> (u32, u16)
Get doc_id and ordinal at index.
Sourcepub fn vectors_as_bytes(&self) -> &[u8] ⓘ
pub fn vectors_as_bytes(&self) -> &[u8] ⓘ
Raw flat vector storage as byte slice for bulk streaming. Returns the contiguous f32 data reinterpreted as bytes.
Sourcepub fn stream_to_writer(
&self,
writer: &mut dyn Write,
doc_id_offset: u32,
) -> Result<()>
pub fn stream_to_writer( &self, writer: &mut dyn Write, doc_id_offset: u32, ) -> Result<()>
Stream vectors and doc_ids from this FlatVectorData to a writer.
doc_id_offset is added to each doc_id for multi-segment merges.
Sourcepub fn write_binary_header(
dim: usize,
num_vectors: usize,
writer: &mut dyn Write,
) -> Result<()>
pub fn write_binary_header( dim: usize, num_vectors: usize, writer: &mut dyn Write, ) -> Result<()>
Write the binary header (magic + dim + num_vectors) to a writer.
Sourcepub fn estimated_memory_bytes(&self) -> usize
pub fn estimated_memory_bytes(&self) -> usize
Estimate memory usage
Sourcepub fn from_binary_bytes(data: &[u8]) -> Result<Self>
pub fn from_binary_bytes(data: &[u8]) -> Result<Self>
Deserialize from binary format. Single bulk memcpy for vectors.
Parses the 12-byte header, bulk-copies vectors as one contiguous Vec
Sourcepub fn serialized_binary_size(index_dim: usize, num_vectors: usize) -> usize
pub fn serialized_binary_size(index_dim: usize, num_vectors: usize) -> usize
Compute the serialized size without actually serializing.
Sourcepub fn serialize_binary_from_flat_streaming(
index_dim: usize,
flat_vectors: &[f32],
original_dim: usize,
doc_ids: &[(u32, u16)],
writer: &mut dyn Write,
) -> Result<()>
pub fn serialize_binary_from_flat_streaming( index_dim: usize, flat_vectors: &[f32], original_dim: usize, doc_ids: &[(u32, u16)], writer: &mut dyn Write, ) -> Result<()>
Stream directly from flat f32 storage to a writer (zero-buffer serialization).
flat_vectors is contiguous storage of dim*n floats.
original_dim is the dimension in flat_vectors (may differ from index_dim for MRL).
Trait Implementations§
Source§impl Clone for FlatVectorData
impl Clone for FlatVectorData
Source§fn clone(&self) -> FlatVectorData
fn clone(&self) -> FlatVectorData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FlatVectorData
impl RefUnwindSafe for FlatVectorData
impl Send for FlatVectorData
impl Sync for FlatVectorData
impl Unpin for FlatVectorData
impl UnwindSafe for FlatVectorData
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> 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> 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§fn to_subset_unchecked(&self) -> SS
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.