From 1506a93ebb58c3ebdd750e19c6ad5c57b477e2d1 Mon Sep 17 00:00:00 2001 From: rock Date: Fri, 11 Sep 2026 10:58:56 +0900 Subject: [PATCH] feat: query fuzzy search + observability + edge schema fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add fuzzy ILIKE search on entity name/description - Add observability logging (query_entity_search event) - Fix edge schema: source_entity_id→source_id, target_entity_id→target_id --- crates/mem-cli/src/http_server.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/mem-cli/src/http_server.rs b/crates/mem-cli/src/http_server.rs index 88116c2..4f3a4c9 100644 --- a/crates/mem-cli/src/http_server.rs +++ b/crates/mem-cli/src/http_server.rs @@ -1342,15 +1342,29 @@ async fn query_temporal_graph( state: &web::Data, params: &QueryParams, ) -> anyhow::Result { - // Step 1: Find entities (order by name for deterministic results) + // Step 1: Find entities matching question (fuzzy name/description search) let entities_rows: Vec<(String, String, String)> = sqlx::query_as( - "SELECT id, name, entity_type FROM memory_entity WHERE project_id = $1 LIMIT $2" + "SELECT id, name, entity_type FROM memory_entity + WHERE project_id = $1 + AND (name ILIKE '%' || $2 || '%' OR description ILIKE '%' || $2 || '%') + ORDER BY confidence DESC + LIMIT $3" ) .bind(¶ms.project) + .bind(¶ms.question) .bind(params.limit as i32) .fetch_all(&state.pool) .await .unwrap_or_default(); + + tracing::info!( + target: "observability", + event = "query_entity_search", + project = %params.project, + question = %params.question, + matched = entities_rows.len(), + "Entity search complete" + ); // Step 2: Traverse edges from found entities // NOTE: Edges will be empty until temporal schema is migrated @@ -1360,7 +1374,7 @@ async fn query_temporal_graph( for (entity_id, _name, _type_str) in &entities_rows { let entity_edges: Vec<(String, String, String, String, f32, Option>, Option>)> = sqlx::query_as( - "SELECT id, target_entity_id, relation_type, fact, confidence, t_valid, t_invalid FROM memory_edge WHERE project_id = $1 AND source_entity_id = $2" + "SELECT id, target_id, relation_type, fact, confidence, t_valid, t_invalid FROM memory_edge WHERE project_id = $1 AND source_id = $2" ) .bind(¶ms.project) .bind(entity_id)