chat中源文件没用的问题

This commit is contained in:
runny committed 2026-05-19 04:23:38 +08:00
1 parent 3d4b2647ae
commit b745a9c803
6 files changed
+490 -99

No files matched your search

+9 -3
View File
@@ -40,7 +40,7 @@ const normalizeResources = (resources: any): RetrieverResource[] => {
return [];
};
// 将检索来源资源合并到消息中,并按文档名+片段ID+内容做去重
// 将检索来源资源合并到消息中,并按文档名+片段ID+内容做去重和更新
const addRetrieverResources = (msg: ChatMessage, resources: any) => {
const list = normalizeResources(resources);
if (list.length === 0) return;
@@ -48,11 +48,17 @@ const addRetrieverResources = (msg: ChatMessage, resources: any) => {
for (const item of list) {
// 使用稳定键进行去重,避免同一条来源在多事件中重复展示
const key = `${item.document_name || ''}|${item.segment_id || ''}|${item.content || ''}`;
const exists = msg.retriever_resources.some(
const existingIndex = msg.retriever_resources.findIndex(
(r) => `${r.document_name || ''}|${r.segment_id || ''}|${r.content || ''}` === key
);
if (!exists) {
if (existingIndex < 0) {
msg.retriever_resources.push(item);
} else {
// 存在则合并,确保后续带有 enrich 链接的字段能覆盖进去
msg.retriever_resources[existingIndex] = {
...msg.retriever_resources[existingIndex],
...item
};
}
}
};