Parse a JSON string from the DSL's "result" column into `Vec `.
(json_text: &str)
| 17 | |
| 18 | /// Parse a JSON string from the DSL's "result" column into `Vec<SearchResult>`. |
| 19 | pub(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`. |
| 45 | pub(super) fn parse_graph_traverse_json(json_text: &str) -> NodeDbResult<SubGraph> { |