fix(rag): default search to keyword and rebuild saved roots

This commit is contained in:
lix-2026
2026-06-09 09:32:36 +08:00
parent 8e3be8b0b7
commit 516121e6f9
4 changed files with 50 additions and 10 deletions
@@ -369,7 +369,27 @@ pub async fn ingest(
let mut expanded_count = 0usize;
let mut seen_sources = BTreeSet::<String>::new();
let force = body.force.unwrap_or(false);
for source in body.sources {
let mut requested_sources = body.sources;
if requested_sources.is_empty() {
requested_sources = registry
.indexed_roots
.iter()
.map(|root| KnowledgeRagSourceInput {
source_path: Some(root.root_relative_path.clone()),
path: None,
parser_hint: None,
})
.collect();
}
if requested_sources.is_empty() {
return Err(WebError::bad_request_code(
"knowledge_rag_source_required",
"资料库索引缺少 sourcePath,且没有可重建的已保存索引范围",
)
.with_context(&context));
}
for source in requested_sources {
let source_path = source.source_path.or(source.path).ok_or_else(|| {
WebError::bad_request_code("knowledge_rag_source_required", "资料库索引缺少 sourcePath")
.with_context(&context)
@@ -1087,7 +1107,8 @@ fn normalize_knowledge_rag_search_mode(mode: Option<&str>) -> String {
Some("hybrid") => "hybrid".into(),
Some("naive" | "vector") => "naive".into(),
Some("mix" | "mixed") => "mix".into(),
_ => "mix".into(),
Some(_) => "mix".into(),
None => "exact".into(),
}
}
@@ -4718,7 +4739,7 @@ mod tests {
normalize_knowledge_rag_search_mode(Some("hybrid")),
"hybrid"
);
assert_eq!(normalize_knowledge_rag_search_mode(None), "mix");
assert_eq!(normalize_knowledge_rag_search_mode(None), "exact");
}
#[test]
@@ -568,6 +568,11 @@ mod tests {
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("pruneKnowledgeRagRegistry"));
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("setKnowledgeRagSourceFilter"));
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("mnote:knowledge-rag-source-updated"));
assert!(
SIDEBAR_TREE_RUNTIME_JS.contains(r#"<option value="exact" selected>关键词</option>"#)
);
assert!(SIDEBAR_TREE_RUNTIME_JS
.contains(r#"data-search-switch="knowledge" role="switch" aria-checked="true""#));
assert!(SIDEBAR_FILETREE_COMMAND_RUNTIME_JS.contains("knowledgeRagSourceRelativePath"));
assert!(SIDEBAR_FILETREE_COMMAND_RUNTIME_JS.contains("supportsKnowledgeRagSource"));
assert!(!SIDEBAR_FILETREE_COMMAND_RUNTIME_JS.contains("runLocalOcr"));