55 lines
3.0 KiB
Python
55 lines
3.0 KiB
Python
"""memory_unit 客户长期记忆主体表 ORM 模型。"""
|
|||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
from decimal import Decimal
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from sqlalchemy import BigInteger, DateTime, Integer, JSON, Numeric, String, Text, func
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
|
|
||
|
|
from model.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class MemoryUnit(Base):
|
||
|
|
"""客户长期记忆主体,向量和关系索引保存在外部库。"""
|
||
|
|
|
||
|
|
__tablename__ = "memory_unit"
|
||
|
|
__table_args__ = {"comment": "客户长期记忆主体表"}
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
||
|
|
customer_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||
|
|
session_id: Mapped[str | None] = mapped_column(String(64))
|
||
|
|
agent_run_id: Mapped[str | None] = mapped_column(String(64))
|
||
|
|
memory_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||
|
|
tag: Mapped[str] = mapped_column(String(64), nullable=False)
|
||
|
|
content: Mapped[str] = mapped_column(String(512), nullable=False)
|
||
|
|
info_type: Mapped[str] = mapped_column(String(8), nullable=False)
|
||
|
|
source: Mapped[str] = mapped_column(String(32), nullable=False)
|
||
|
|
evidence_ref: Mapped[list[dict[str, Any]] | None] = mapped_column(JSON)
|
||
|
|
source_confidence: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.20")
|
||
|
|
confidence: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.20")
|
||
|
|
historical_accuracy: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.50")
|
||
|
|
confidence_version: Mapped[str | None] = mapped_column(String(32))
|
||
|
|
confidence_reason: Mapped[str | None] = mapped_column(String(255))
|
||
|
|
confidence_update_time: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
evidence_count: Mapped[int] = mapped_column(Integer, server_default="0")
|
||
|
|
recall_count: Mapped[int] = mapped_column(Integer, server_default="0")
|
||
|
|
memory_version: Mapped[int] = mapped_column(Integer, server_default="1")
|
||
|
|
update_time: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
last_recall_time: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
create_time: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||
|
|
status: Mapped[str] = mapped_column(String(16), server_default="candidate")
|
||
|
|
valid_from: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
valid_until: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
last_verified_at: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
milvus_id: Mapped[str | None] = mapped_column(String(128))
|
||
|
|
graph_node_id: Mapped[str | None] = mapped_column(String(128))
|
||
|
|
milvus_sync_status: Mapped[str] = mapped_column(String(16), server_default="pending")
|
||
|
|
neo4j_sync_status: Mapped[str] = mapped_column(String(16), server_default="pending")
|
||
|
|
sync_retry_count: Mapped[int] = mapped_column(Integer, server_default="0")
|
||
|
|
last_sync_error: Mapped[str | None] = mapped_column(String(500))
|
||
|
|
next_retry_at: Mapped[datetime | None] = mapped_column(DateTime)
|
||
|
|
last_synced_at: Mapped[datetime | None] = mapped_column(DateTime)
|