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

Method execute_sparse_search

nodedb/src/data/executor/handlers/vector_sparse.rs:83–156  ·  view source on GitHub ↗

Search the sparse inverted index via dot-product scoring.

(
        &self,
        task: &ExecutionTask,
        tid: u64,
        collection: &str,
        field_name: &str,
        query_entries: &[(u32, f32)],
        top_k: usize,
    )

Source from the content-addressed store, hash-verified

81
82 /// Search the sparse inverted index via dot-product scoring.
83 pub(in crate::data::executor) fn execute_sparse_search(
84 &self,
85 task: &ExecutionTask,
86 tid: u64,
87 collection: &str,
88 field_name: &str,
89 query_entries: &[(u32, f32)],
90 top_k: usize,
91 ) -> Response {
92 debug!(
93 core = self.core_id,
94 %collection,
95 %field_name,
96 query_nnz = query_entries.len(),
97 top_k,
98 "sparse search"
99 );
100
101 let key = Self::sparse_index_key(tid, collection, field_name);
102 let Some(index) = self.sparse_vector_indexes.get(&key) else {
103 // No index exists — return empty results (not an error).
104 return match super::super::response_codec::encode(&Vec::<
105 super::super::response_codec::VectorSearchHit,
106 >::new())
107 {
108 Ok(payload) => self.response_with_payload(task, payload),
109 Err(e) => self.response_error(
110 task,
111 ErrorCode::Internal {
112 detail: e.to_string(),
113 },
114 ),
115 };
116 };
117
118 let query = match nodedb_types::SparseVector::from_entries(query_entries.to_vec()) {
119 Ok(sv) => sv,
120 Err(e) => {
121 return self.response_error(
122 task,
123 ErrorCode::RejectedConstraint {
124 detail: String::new(),
125 constraint: e.to_string(),
126 },
127 );
128 }
129 };
130
131 let results = crate::engine::vector::sparse::search::dot_product_topk(index, &query, top_k);
132
133 // Convert to VectorSearchHit for unified response codec.
134 let hits: Vec<super::super::response_codec::VectorSearchHit> = results
135 .iter()
136 .map(|r| super::super::response_codec::VectorSearchHit {
137 id: r.internal_id,
138 distance: r.score,
139 doc_id: r.doc_id.clone(),
140 body: None,

Callers 1

dispatch_vectorMethod · 0.80

Calls 10

dot_product_topkFunction · 0.85
response_with_payloadMethod · 0.80
response_errorMethod · 0.80
to_stringMethod · 0.80
collectMethod · 0.80
encodeFunction · 0.50
getMethod · 0.45
to_vecMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected