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

Function make_backing

nodedb-vector/src/segment_backing/plain.rs:116–132  ·  view source on GitHub ↗
(dim: usize, vecs: &[Vec<f32>])

Source from the content-addressed store, hash-verified

114 use crate::mmap_segment::MmapVectorSegment;
115
116 fn make_backing(dim: usize, vecs: &[Vec<f32>]) -> PlainMmapBacking {
117 let dir = tempdir().unwrap();
118 let path = dir.path().join("test.ndvs");
119
120 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
121 let surrogates: Vec<u64> = (0..vecs.len() as u64).collect();
122
123 let seg =
124 MmapVectorSegment::create_with_surrogates(&path, dim, &refs, &surrogates).unwrap();
125
126 // Keep the tempdir alive by leaking it for the test duration.
127 // The backing borrows from the mmap, which is already self-contained
128 // (fd kept open by the segment); dir can be dropped.
129 drop(dir);
130
131 PlainMmapBacking::new(seg)
132 }
133
134 #[test]
135 fn plain_backing_basic_roundtrip() {

Calls 6

joinMethod · 0.80
collectMethod · 0.80
pathMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45
lenMethod · 0.45