feat(knowledge): 会话级去重 + 知识域地图注入 Planner 解决 ISS-001 重复检索
- RetrievedDocTracker: sessionId → Set<filePath> 会话级去重,LookupKnowledgeTool Step 5 过滤已检索文档 - KnowledgeDomainService: 域级聚合,LLM 生成 when_to_retrieve,构建 knowledge map YAML - DocumentFieldEnricher: 上传时 LLM 补全 covers + whenToRetrieve(含同域文档排除上下文) - KnowledgeDomain entity + V009 迁移: 域级元数据持久化,避免重启重复 LLM 调用 - ChatService: 注入 knowledge map 到 Planner prompt,会话结束时清理去重状态 - KnowledgeIndexService: 手写 JSON 解析替换为 Jackson ObjectMapper,启动时补建缺失域记录 - chat-planner-prompt: 新增知识库检索规则(按域 when_to_retrieve 判断,每域最多一次检索) - doc-field-enricher-prompt / domain-summary-prompt: 外部化 LLM 提示词
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.superbiz.agent.tool;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* session 级已召回文档追踪器
|
||||
* 防止同一 session 内重复召回相同文档
|
||||
*/
|
||||
@Component
|
||||
public class RetrievedDocTracker {
|
||||
|
||||
// key: sessionId, value: 已召回文档的 filePath 集合
|
||||
private final ConcurrentHashMap<String, Set<String>> retrieved = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean isAlreadyRetrieved(String sessionId, String filePath) {
|
||||
if (sessionId == null || filePath == null) return false;
|
||||
Set<String> docs = retrieved.get(sessionId);
|
||||
return docs != null && docs.contains(filePath);
|
||||
}
|
||||
|
||||
public void markRetrieved(String sessionId, String filePath) {
|
||||
if (sessionId == null || filePath == null) return;
|
||||
retrieved.computeIfAbsent(sessionId,
|
||||
k -> Collections.newSetFromMap(new ConcurrentHashMap<>()))
|
||||
.add(filePath);
|
||||
}
|
||||
|
||||
public void clearSession(String sessionId) {
|
||||
if (sessionId == null) return;
|
||||
retrieved.remove(sessionId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user