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

Method vector_search_impl

nodedb-client/src/remote/client/vector.rs:20–63  ·  view source on GitHub ↗
(
        &self,
        collection: &str,
        query: &[f32],
        k: usize,
        filter: Option<&MetadataFilter>,
    )

Source from the content-addressed store, hash-verified

18
19impl NodeDbRemote {
20 pub(super) async fn vector_search_impl(
21 &self,
22 collection: &str,
23 query: &[f32],
24 k: usize,
25 filter: Option<&MetadataFilter>,
26 ) -> NodeDbResult<Vec<SearchResult>> {
27 let sql = build_vector_search_sql(collection, query, k, filter)?;
28
29 let (columns, rows) = self.query_raw(&sql, &[]).await?;
30
31 // The DSL path returns JSON in a single "result" column.
32 if columns.len() == 1 && columns[0] == "result" {
33 if let Some(row) = rows.first()
34 && let Some(nodedb_types::value::Value::String(json_text)) = row.first()
35 {
36 return parse_vector_search_json(json_text);
37 }
38 return Ok(Vec::new());
39 }
40
41 // Structured result set: id, distance columns.
42 let mut results = Vec::with_capacity(rows.len());
43 let id_idx = columns.iter().position(|c| c == "id").unwrap_or(0);
44 let dist_idx = columns.iter().position(|c| c == "distance").unwrap_or(1);
45
46 for row in &rows {
47 let id = row
48 .get(id_idx)
49 .and_then(|v| v.as_str())
50 .unwrap_or("")
51 .to_string();
52 let distance = row.get(dist_idx).and_then(|v| v.as_f64()).unwrap_or(0.0) as f32;
53
54 results.push(SearchResult {
55 id,
56 node_id: None,
57 distance,
58 metadata: HashMap::new(),
59 });
60 }
61
62 Ok(results)
63 }
64
65 pub(super) async fn vector_insert_field_impl(
66 &self,

Callers 1

vector_searchMethod · 0.45

Calls 11

build_vector_search_sqlFunction · 0.85
parse_vector_search_jsonFunction · 0.85
query_rawMethod · 0.80
firstMethod · 0.80
to_stringMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45
as_f64Method · 0.45
pushMethod · 0.45

Tested by

no test coverage detected