Files
MemoryBear/api/app/schemas/memory_agent_schema.py
lanceyq 1f0c88a5f0 refactor(memory): consolidate write pipeline and rename statement extraction step
- Rename StatementExtractionStep → StatementTemporalExtractionStep and
  extract_statement.jinja2 → extract_statement_temporal.jinja2 to reflect
  merged temporal extraction logic
- Move extraction_pipeline_orchestrator.py out of steps/ to engine root
- Move dedup_step.py into steps/ directory
- Introduce WriteMemoryRequest schema to replace positional args in write_memory()
- Extract _resolve_and_load_config, _preprocess_files, _write_neo4j, and
  _invalidate_interest_cache as private helpers in MemoryAgentService
- Remove shadow pipeline and simplify NEW_PIPELINE_ENABLED branch
- Merge 类型归属/成员隶属/任职服务 relation types into single 归属身份关系 in triplet prompt
- Add alias merge logic (别名属于) in deduplication and MERGE_ALIAS_BELONGS_TO Cypher query
- Add StorageType, Language, MessageItem enums/models to memory_agent_schema
- Reduce AgentMemory_Long_Term.DEFAULT_SCOPE from 6 to 1
- Delete standalone extract_temporal.jinja2 (logic merged into statement step)
2026-05-08 11:26:24 +08:00

68 lines
1.5 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 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
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 = '用户'