feat(memory): 引入基于向量的瞬时记忆系统

用基于 ChromaDB 和向量相似度的新瞬时记忆系统取代了原有的实现。此更改旨在提高记忆创建和检索的准确性和相关性。

主要变更:
- **向量化重要性判断**: 放弃了原有的 LLM 判断方法,通过将聊天记录与预定义的“重要性模式”进行向量相似度比较,来决定是否创建记忆。
- **高效去重**: 在存储新记忆之前,通过向量相似度检查,有效避免了内容重复。
- **精准检索**: 利用向量搜索,根据用户当前输入检索最相关的记忆,提高了上下文的连贯性。
- **双重存储**: 为了保持系统兼容性,记忆同时存储在 ChromaDB 向量数据库和现有的 SQLAlchemy 数据库中。
- **代码集成**: 在 `DefaultReplyer` 中将 `InstantMemory` 的实现切换为新的 `VectorInstantMemory`。
This commit is contained in:
minecraft1024a
2025-08-19 18:48:10 +08:00
committed by Windpicker-owo
parent 0cb9705946
commit 4fc7c51ee0
2 changed files with 349 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ from src.chat.utils.chat_message_builder import (
)
from src.chat.express.expression_selector import expression_selector
from src.chat.memory_system.memory_activator import MemoryActivator
from src.chat.memory_system.instant_memory import InstantMemory
from src.chat.memory_system.vector_instant_memory import VectorInstantMemory
from src.mood.mood_manager import mood_manager
from src.person_info.person_info import Person, is_person_known
from src.plugin_system.base.component_types import ActionInfo, EventType
@@ -190,7 +190,7 @@ class DefaultReplyer:
self.is_group_chat, self.chat_target_info = get_chat_type_and_target_info(self.chat_stream.stream_id)
self.heart_fc_sender = HeartFCSender()
self.memory_activator = MemoryActivator()
self.instant_memory = InstantMemory(chat_id=self.chat_stream.stream_id)
self.instant_memory = VectorInstantMemory(chat_id=self.chat_stream.stream_id)
from src.plugin_system.core.tool_use import ToolExecutor # 延迟导入ToolExecutor不然会循环依赖
@@ -423,7 +423,8 @@ class DefaultReplyer:
if global_config.memory.enable_instant_memory:
asyncio.create_task(self.instant_memory.create_and_store_memory(chat_history))
instant_memory = await self.instant_memory.get_memory(target)
instant_memory_list = await self.instant_memory.get_memory(target)
instant_memory = instant_memory_list[0] if instant_memory_list else None
logger.info(f"即时记忆:{instant_memory}")
if not running_memories: