feat(memory): 增强记忆构建系统并优化检索性能

- 添加记忆提取异常处理机制,提升系统稳定性
- 实现记忆内容格式化功能,增强可读性和结构化输出
- 优化LLM响应解析逻辑,避免系统标识误写入记忆
- 改进向量存储批量嵌入生成,提升处理效率
- 为记忆系统添加机器人身份上下文注入,避免自身信息记录
- 增强记忆检索接口,支持额外上下文参数传递
- 添加控制台记忆预览功能,便于人工检查
- 优化记忆融合算法,正确处理单记忆组情况
- 改进流循环管理器,支持未读消息积压强制分发机制
This commit is contained in:
Windpicker-owo
2025-09-30 21:15:40 +08:00
parent 0a3c908654
commit 37c8253f54
11 changed files with 873 additions and 180 deletions

View File

@@ -421,7 +421,7 @@ class Prompt:
context_data[key] = value
except asyncio.TimeoutError:
logger.error(f"构建超时 ({timeout_seconds}s)")
logger.error("构建超时")
context_data = {}
for key, value in pre_built_params.items():
if value:
@@ -584,14 +584,18 @@ class Prompt:
# 构建记忆块
memory_parts = []
existing_contents = set()
if running_memories:
memory_parts.append("以下是当前在聊天中,你回忆起的记忆:")
for memory in running_memories:
memory_parts.append(f"- {memory['content']}")
content = memory["content"]
memory_parts.append(f"- {content}")
existing_contents.add(content)
if instant_memory:
memory_parts.append(f"- {instant_memory}")
if instant_memory not in existing_contents:
memory_parts.append(f"- 最相关记忆:{instant_memory}")
memory_block = "\n".join(memory_parts) if memory_parts else ""