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

Function extract_vector

nodedb-strict/src/arrow_extract.rs:338–369  ·  view source on GitHub ↗

Vector columns → BinaryArray of packed f32 bytes. Each entry is `dim * 4` bytes of packed little-endian f32.

(
    decoder: &TupleDecoder,
    tuples: &[&[u8]],
    col_idx: usize,
    n: usize,
    dim: usize,
)

Source from the content-addressed store, hash-verified

336/// Vector columns → BinaryArray of packed f32 bytes.
337/// Each entry is `dim * 4` bytes of packed little-endian f32.
338fn extract_vector(
339 decoder: &TupleDecoder,
340 tuples: &[&[u8]],
341 col_idx: usize,
342 n: usize,
343 dim: usize,
344) -> Result<ArrayRef, StrictError> {
345 let (null_buf, null_count) = build_null_buffer(decoder, tuples, col_idx)?;
346 let vec_size = dim * 4;
347 let mut blobs: Vec<Option<&[u8]>> = Vec::with_capacity(n);
348
349 for tuple in tuples {
350 if let Some(raw) = decoder.extract_fixed_raw(tuple, col_idx)? {
351 blobs.push(Some(&raw[..vec_size]));
352 } else {
353 blobs.push(None);
354 }
355 }
356
357 let array = BinaryArray::from(blobs);
358 if null_count > 0 {
359 let data = array
360 .into_data()
361 .into_builder()
362 .null_bit_buffer(Some(null_buf.into_inner().into_inner()))
363 .build()
364 .expect("arrow array builder lengths are consistent");
365 Ok(Arc::new(BinaryArray::from(data)))
366 } else {
367 Ok(Arc::new(array))
368 }
369}
370
371#[cfg(test)]
372mod tests {

Callers 1

extract_column_to_arrowFunction · 0.85

Calls 5

build_null_bufferFunction · 0.85
extract_fixed_rawMethod · 0.80
pushMethod · 0.45
expectMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected