MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / batch_push

Method batch_push

src/structures/dense_vector_list.rs:82–116  ·  view source on GitHub ↗
(
        &mut self,
        vectors: Vec<[u8; QUANTIZED_VECTOR_SIZE]>,
    )

Source from the content-addressed store, hash-verified

80 }
81
82 pub fn batch_push(
83 &mut self,
84 vectors: Vec<[u8; QUANTIZED_VECTOR_SIZE]>,
85 ) -> io::Result<Vec<usize>> {
86 let start_offset = self.used_space + HEADER_SIZE;
87 let total_size = vectors.len() * QUANTIZED_VECTOR_SIZE;
88 let required_space = start_offset + total_size;
89
90 // println!(
91 // "Required space: {}, mmap len: {}",
92 // required_space,
93 // self.mmap.len()
94 // );
95
96 if required_space > self.mmap.len() {
97 self.resize_mmap(required_space * 2)?;
98 }
99
100 // println!("Batch push");
101
102 for (i, vector) in vectors.iter().enumerate() {
103 let offset = start_offset + i * QUANTIZED_VECTOR_SIZE;
104 self.mmap[offset..offset + QUANTIZED_VECTOR_SIZE].copy_from_slice(vector);
105 }
106
107 // println!("Batch push done");
108
109 self.used_space += total_size;
110 // Update the header in the mmap
111 self.mmap[0..HEADER_SIZE].copy_from_slice(&(self.used_space as u64).to_le_bytes());
112
113 Ok((((start_offset - HEADER_SIZE) / QUANTIZED_VECTOR_SIZE)
114 ..(self.used_space / QUANTIZED_VECTOR_SIZE))
115 .collect())
116 }
117
118 pub fn get(&self, index: usize) -> io::Result<&[u8; QUANTIZED_VECTOR_SIZE]> {
119 let offset = HEADER_SIZE + index * QUANTIZED_VECTOR_SIZE;

Callers 2

commitMethod · 0.80
recover_point_in_timeMethod · 0.80

Calls 2

lenMethod · 0.80
resize_mmapMethod · 0.45

Tested by

no test coverage detected