mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:09:19 +08:00
feat: 长期记忆改为摘要检索并由模型按需载入
This commit is contained in:
@@ -79,12 +79,13 @@ class ChatMessage:
|
||||
|
||||
@dataclass
|
||||
class UserMemory:
|
||||
"""用户级长期记忆条目。"""
|
||||
"""用户级长期记忆条目;summary 供检索,text 仅按需载入。"""
|
||||
|
||||
company_id: int
|
||||
user_id: str
|
||||
kind: MemoryKind
|
||||
text: str
|
||||
summary: str = ""
|
||||
key: str | None = None
|
||||
value: dict[str, Any] = field(default_factory=dict)
|
||||
source_thread_id: str | None = None
|
||||
|
||||
@@ -41,6 +41,19 @@ class MemoryRepository(ABC):
|
||||
self, company_id: int, user_id: str, limit: int
|
||||
) -> list[UserMemory]: ...
|
||||
|
||||
@abstractmethod
|
||||
async def count_active(self, company_id: int, user_id: str) -> int: ...
|
||||
|
||||
@abstractmethod
|
||||
async def search(
|
||||
self, company_id: int, user_id: str, query: str, limit: int
|
||||
) -> list[UserMemory]: ...
|
||||
|
||||
@abstractmethod
|
||||
async def get_by_ids(
|
||||
self, company_id: int, user_id: str, memory_ids: list[str]
|
||||
) -> list[UserMemory]: ...
|
||||
|
||||
@abstractmethod
|
||||
async def upsert(self, memory: UserMemory) -> UserMemory: ...
|
||||
|
||||
@@ -76,6 +89,7 @@ class ChatStreamer(ABC):
|
||||
llm: LlmRuntimeConfig,
|
||||
history: list[ChatMessage],
|
||||
user_text: str,
|
||||
memory_lines: list[str] | None = None,
|
||||
tools: list[Any] | None = None,
|
||||
memory_count: int = 0,
|
||||
memory_just_saved: str | None = None,
|
||||
) -> AsyncIterator[str]: ...
|
||||
|
||||
Reference in New Issue
Block a user