Files
MemoryBear/api/app/schemas/memory_agent_schema.py
lanceyq cf389bb978 refactor(memory): remove expired_at field and add dialog_at timestamp
Remove the deprecated expired_at field from all graph models, Neo4j
Cypher queries, repositories, and pipeline code. Replace with dialog_at
on StatementNode to track the original dialog timestamp.

- Strip expired_at from DialogueNode, ChunkNode, StatementNode,
  ExtractedEntityNode, edges, and all Cypher queries
- Add dialog_at to MessageItem schema and propagate through extraction
  and graph build steps
- Extract emotion/metadata async submission from WritePipeline into
  a generic _submit_celery_task helper
- Add post_store_dedup_and_alias_merge Celery task for async alias
  merging and second-layer dedup after Neo4j write
- Switch pytest async backend from anyio to asyncio_mode=auto
2026-05-08 11:27:59 +08:00

73 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from abc import ABC
from enum import Enum
from typing import Any, Optional
from pydantic import Field
from pydantic import BaseModel
class StorageType(str, Enum):
"""记忆存储后端类型"""
NEO4J = "neo4j"
RAG = "rag"
class Language(str, Enum): # 没有传递到聚类的celery任务中去任务会回退失败用默认值考虑统一语言问题
"""支持的语言"""
ZH = "zh"
EN = "en"
class MessageItem(BaseModel):
"""单条消息结构"""
role: str
content: str
dialog_at: Optional[str] = Field(
None,
description="该条消息发生的绝对时间ISO 8601 格式),不传则使用服务端当前时间",
)
files: Optional[list[dict]] = None
file_content: Optional[list[Any]] = None
model_config = {"extra": "allow"}
class UserInput(BaseModel):
message: str
history: list[dict]
search_switch: str
end_user_id: str
config_id: Optional[str] = None
class Write_UserInput(BaseModel):
messages: list[dict]
end_user_id: str
config_id: Optional[str] = None
class WriteMemoryRequest(BaseModel):
"""write_memory() 的参数封装"""
end_user_id: str
messages: list[MessageItem]
config_id: Optional[Any] = None
storage_type: StorageType = StorageType.NEO4J
user_rag_memory_id: str = ""
language: Language = Language.ZH
class AgentMemory_Long_Term(ABC):
"""长期记忆配置常量"""
STORAGE_NEO4J = "neo4j"
STORAGE_RAG = "rag"
STRATEGY_AGGREGATE = "aggregate"
STRATEGY_CHUNK = "chunk"
STRATEGY_TIME = "time"
DEFAULT_SCOPE = 1
TIME_SCOPE = 5
class AgentMemoryDataset(ABC):
PRONOUN = ['', '本人', '在下', '自己', '', '鄙人', '', '']
NAME = '用户'