feat(rag): align LightRAG native citations and MCP bridge

This commit is contained in:
lix-2026
2026-06-09 09:20:56 +08:00
parent 0e8b03daf8
commit 8e3be8b0b7
39 changed files with 2255 additions and 2732 deletions
+26 -8
View File
@@ -49,11 +49,29 @@ pub struct AcpRunBridge {
}
fn collect_citation_markdowns_from_value(value: &Value) -> Vec<Value> {
fn add_citation(text: &str, seen: &mut HashSet<String>, out: &mut Vec<Value>) {
let citation = text.trim();
if !citation.is_empty() && seen.insert(citation.to_string()) {
out.push(json!({ "citationMarkdown": citation }));
fn add_citation_value(value: &Value, seen: &mut HashSet<String>, out: &mut Vec<Value>) {
let Some(citation) = value.get("citationMarkdown").and_then(Value::as_str) else {
return;
};
let citation = citation.trim();
if citation.is_empty() || !seen.insert(citation.to_string()) {
return;
}
out.push(json!({
"schema": value.get("schema").cloned().unwrap_or_else(|| json!("mnote.knowledge_rag.citation.v1")),
"citationMarkdown": citation,
"citationId": value.get("citationId").cloned().unwrap_or(Value::Null),
"citationLabel": value.get("citationLabel").cloned().unwrap_or(Value::Null),
"sourceRootRelativePath": value.get("sourceRootRelativePath").cloned().unwrap_or(Value::Null),
"sourcePath": value.get("sourcePath").cloned().unwrap_or(Value::Null),
"filePath": value.get("filePath").or_else(|| value.get("lightRagFilePath")).cloned().unwrap_or(Value::Null),
"headingPath": value.get("headingPath").cloned().unwrap_or_else(|| json!([])),
"displayQuote": value.get("displayQuote").or_else(|| value.get("quote")).cloned().unwrap_or(Value::Null),
"locatorEvidenceText": value.get("locatorEvidenceText").cloned().unwrap_or(Value::Null),
"locatorPrecision": value.get("locatorPrecision").cloned().unwrap_or(Value::Null),
"locatorDegraded": value.get("locatorDegraded").cloned().unwrap_or(Value::Bool(true)),
"citationUrl": value.get("citationUrl").cloned().unwrap_or(Value::Null),
}));
}
fn add_reference_citations(
@@ -73,7 +91,7 @@ fn collect_citation_markdowns_from_value(value: &Value) -> Vec<Value> {
if out.len() >= 8 {
break;
}
let Some(citation) = reference.get("citationMarkdown").and_then(Value::as_str) else {
let Some(_citation) = reference.get("citationMarkdown").and_then(Value::as_str) else {
continue;
};
if has_precise
@@ -82,7 +100,7 @@ fn collect_citation_markdowns_from_value(value: &Value) -> Vec<Value> {
continue;
}
let before = out.len();
add_citation(citation, seen, out);
add_citation_value(reference, seen, out);
added = added || out.len() > before;
}
added
@@ -120,9 +138,9 @@ fn collect_citation_markdowns_from_value(value: &Value) -> Vec<Value> {
.get("references")
.and_then(Value::as_array)
.is_some_and(|references| add_reference_citations(references, seen, out));
if let Some(citation) = map.get("citationMarkdown").and_then(Value::as_str) {
if let Some(_citation) = map.get("citationMarkdown").and_then(Value::as_str) {
if !has_filtered_references {
add_citation(citation, seen, out);
add_citation_value(value, seen, out);
}
}
for (key, item) in map {