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

Function build_store

nodedb-vector/src/multivec/meta_embed.rs:87–105  ·  view source on GitHub ↗

Build a store with `n` documents, each with one unit-vector at dimension `i % dim`.

(n: u32, dim: usize, k: u8)

Source from the content-addressed store, hash-verified

85 /// Build a store with `n` documents, each with one unit-vector at
86 /// dimension `i % dim`.
87 fn build_store(n: u32, dim: usize, k: u8) -> MultiVectorStore {
88 let mut store = MultiVectorStore::new(dim, MultiVecMode::MetaToken { k });
89 for i in 0..n {
90 let mut vecs: Vec<Vec<f32>> = Vec::new();
91 for j in 0..k as usize {
92 let mut v = vec![0.0f32; dim];
93 // Each Meta Token of doc i points in direction (i + j) % dim.
94 v[(i as usize + j) % dim] = 1.0;
95 vecs.push(v);
96 }
97 store
98 .insert(MultiVectorDoc {
99 doc_id: i,
100 vectors: vecs,
101 })
102 .unwrap();
103 }
104 store
105 }
106
107 #[test]
108 fn search_returns_at_most_k_results() {

Calls 2

pushMethod · 0.45
insertMethod · 0.45