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

Function parse_vector_search_json

nodedb-client/src/remote/parse.rs:19–42  ·  view source on GitHub ↗

Parse a JSON string from the DSL's "result" column into `Vec `.

(json_text: &str)

Source from the content-addressed store, hash-verified

17
18/// Parse a JSON string from the DSL's "result" column into `Vec<SearchResult>`.
19pub(super) fn parse_vector_search_json(json_text: &str) -> NodeDbResult<Vec<SearchResult>> {
20 let parsed: serde_json::Value = sonic_rs::from_str(json_text)
21 .map_err(|e| NodeDbError::serialization("json", e.to_string()))?;
22
23 let mut results = Vec::new();
24 if let Some(arr) = parsed.as_array() {
25 for item in arr {
26 let id = item
27 .get("id")
28 .and_then(|v| v.as_str())
29 .unwrap_or("")
30 .to_string();
31 let distance = item.get("distance").and_then(|v| v.as_f64()).unwrap_or(0.0) as f32;
32 results.push(SearchResult {
33 id,
34 node_id: None,
35 distance,
36 metadata: HashMap::new(),
37 });
38 }
39 }
40
41 Ok(results)
42}
43
44/// Parse a JSON string from graph_traverse into `SubGraph`.
45pub(super) fn parse_graph_traverse_json(json_text: &str) -> NodeDbResult<SubGraph> {

Callers 3

parse_empty_search_jsonFunction · 0.85
vector_search_implMethod · 0.85

Calls 7

serializationFunction · 0.85
to_stringMethod · 0.80
as_arrayMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
as_f64Method · 0.45
pushMethod · 0.45

Tested by 2

parse_empty_search_jsonFunction · 0.68