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

Function basic_search

nodedb/src/engine/vector/sparse/search.rs:124–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122
123 #[test]
124 fn basic_search() {
125 let mut idx = SparseInvertedIndex::new();
126 idx.insert("doc1", &make_sv(&[(10, 0.5), (20, 0.8)]));
127 idx.insert("doc2", &make_sv(&[(10, 0.3), (30, 1.0)]));
128 idx.insert("doc3", &make_sv(&[(20, 0.9), (30, 0.2)]));
129
130 let query = make_sv(&[(10, 1.0), (20, 1.0)]);
131 let results = dot_product_topk(&idx, &query, 3);
132
133 assert_eq!(results.len(), 3);
134 // doc1: 0.5*1.0 + 0.8*1.0 = 1.3
135 // doc2: 0.3*1.0 = 0.3
136 // doc3: 0.9*1.0 = 0.9
137 assert_eq!(results[0].doc_id.as_deref(), Some("doc1"));
138 assert!((results[0].score - 1.3).abs() < 1e-6);
139 assert_eq!(results[1].doc_id.as_deref(), Some("doc3"));
140 assert_eq!(results[2].doc_id.as_deref(), Some("doc2"));
141 }
142
143 #[test]
144 fn topk_limits_results() {

Callers

nothing calls this directly

Calls 3

dot_product_topkFunction · 0.85
make_svFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected