MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / complete_build

Method complete_build

nodedb-vector/src/collection/lifecycle.rs:199–244  ·  view source on GitHub ↗

Accept a completed HNSW build from the background thread. After promoting the segment to sealed, rebuilds the collection-level codec-dispatch index when `self.quantization` is `RaBitQ` or `Bbq`. The rebuild trains over all vectors so the codec index always covers every sealed segment.

(&mut self, segment_id: u32, index: HnswIndex)

Source from the content-addressed store, hash-verified

197 /// The rebuild trains over all vectors so the codec index always covers
198 /// every sealed segment.
199 pub fn complete_build(&mut self, segment_id: u32, index: HnswIndex) {
200 if let Some(pos) = self
201 .building
202 .iter()
203 .position(|b| b.segment_id == segment_id)
204 {
205 let building = self.building.remove(pos);
206 let use_codec_dispatch = matches!(
207 self.quantization,
208 VectorQuantization::RaBitQ | VectorQuantization::Bbq
209 );
210 let use_pq = !use_codec_dispatch && self.index_config.index_type == IndexType::HnswPq;
211 let (sq8, pq) = if use_codec_dispatch {
212 (None, None)
213 } else if use_pq {
214 (
215 None,
216 Self::build_pq_for_index(&index, self.index_config.pq_m),
217 )
218 } else {
219 (Self::build_sq8_for_index(&index), None)
220 };
221 let (tier, mmap_vectors) =
222 self.resolve_tier_for_build(segment_id, building.base_id, &index);
223
224 self.sealed.push(SealedSegment {
225 index,
226 base_id: building.base_id,
227 sq8,
228 pq,
229 tier,
230 mmap_vectors,
231 });
232
233 if use_codec_dispatch {
234 let tag = match self.quantization {
235 VectorQuantization::RaBitQ => "rabitq",
236 VectorQuantization::Bbq => "bbq",
237 _ => unreachable!(
238 "invariant: use_codec_dispatch is only true for RaBitQ and Bbq quantization variants"
239 ),
240 };
241 self.build_codec_dispatch(tag);
242 }
243 }
244 }
245
246 /// Access sealed segments (read-only).
247 pub fn sealed_segments(&self) -> &[SealedSegment] {

Calls 5

build_codec_dispatchMethod · 0.80
iterMethod · 0.45
removeMethod · 0.45
pushMethod · 0.45