fix: agent search uses smart_search for content queries
- Update system prompt to prioritize smart_search over find_file - Add source prefix ([OCR], [ASRX], [ASRX+OCR]) to exec_smart_search results - Users can now see chunk content with source indicators
This commit is contained in:
+71
-5
@@ -555,7 +555,7 @@ pub async fn exec_smart_search(
|
||||
|
||||
let chunk_table = schema::table_name("chunk");
|
||||
let mut sql = format!(
|
||||
"SELECT chunk_id, text_content, start_frame, end_frame, chunk_type \
|
||||
"SELECT chunk_id, text_content, start_frame, end_frame, chunk_type, content \
|
||||
FROM {} WHERE text_content ILIKE $1",
|
||||
chunk_table
|
||||
);
|
||||
@@ -566,21 +566,87 @@ pub async fn exec_smart_search(
|
||||
|
||||
if let Some(fuid) = file_uuid {
|
||||
let like = format!("%{}%", query);
|
||||
let rows: Vec<(String, Option<String>, i64, i64, String)> = sqlx::query_as(&sql)
|
||||
let rows: Vec<(String, Option<String>, i64, i64, String, Option<serde_json::Value>)> = sqlx::query_as(&sql)
|
||||
.bind(&like)
|
||||
.bind(fuid)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(serde_json::json!({"results": rows}).to_string())
|
||||
|
||||
let results: Vec<Vec<serde_json::Value>> = rows.into_iter().map(|(chunk_id, text_content, start_frame, end_frame, chunk_type, content)| {
|
||||
let source_prefix = if let Some(ref content) = content {
|
||||
let text = content.get("text").and_then(|t| t.as_str()).unwrap_or("");
|
||||
let ocr_text = content.get("ocr_text").and_then(|t| t.as_str()).unwrap_or("");
|
||||
|
||||
let has_asrx = !text.trim().is_empty();
|
||||
let has_ocr = !ocr_text.trim().is_empty();
|
||||
|
||||
if has_asrx && has_ocr {
|
||||
"[ASRX+OCR] "
|
||||
} else if has_asrx {
|
||||
"[ASRX] "
|
||||
} else if has_ocr {
|
||||
"[OCR] "
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let prefixed_text = text_content.map(|t| format!("{}{}", source_prefix, t));
|
||||
|
||||
vec![
|
||||
serde_json::json!(chunk_id),
|
||||
serde_json::json!(prefixed_text),
|
||||
serde_json::json!(start_frame),
|
||||
serde_json::json!(end_frame),
|
||||
serde_json::json!(chunk_type),
|
||||
]
|
||||
}).collect();
|
||||
|
||||
Ok(serde_json::json!({"results": results}).to_string())
|
||||
} else {
|
||||
let like = format!("%{}%", query);
|
||||
let rows: Vec<(String, Option<String>, i64, i64, String)> = sqlx::query_as(&sql)
|
||||
let rows: Vec<(String, Option<String>, i64, i64, String, Option<serde_json::Value>)> = sqlx::query_as(&sql)
|
||||
.bind(&like)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(serde_json::json!({"results": rows}).to_string())
|
||||
|
||||
let results: Vec<Vec<serde_json::Value>> = rows.into_iter().map(|(chunk_id, text_content, start_frame, end_frame, chunk_type, content)| {
|
||||
let source_prefix = if let Some(ref content) = content {
|
||||
let text = content.get("text").and_then(|t| t.as_str()).unwrap_or("");
|
||||
let ocr_text = content.get("ocr_text").and_then(|t| t.as_str()).unwrap_or("");
|
||||
|
||||
let has_asrx = !text.trim().is_empty();
|
||||
let has_ocr = !ocr_text.trim().is_empty();
|
||||
|
||||
if has_asrx && has_ocr {
|
||||
"[ASRX+OCR] "
|
||||
} else if has_asrx {
|
||||
"[ASRX] "
|
||||
} else if has_ocr {
|
||||
"[OCR] "
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let prefixed_text = text_content.map(|t| format!("{}{}", source_prefix, t));
|
||||
|
||||
vec![
|
||||
serde_json::json!(chunk_id),
|
||||
serde_json::json!(prefixed_text),
|
||||
serde_json::json!(start_frame),
|
||||
serde_json::json!(end_frame),
|
||||
serde_json::json!(chunk_type),
|
||||
]
|
||||
}).collect();
|
||||
|
||||
Ok(serde_json::json!({"results": results}).to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user