跳到主要内容

数据模型

所有模型定义在 models.py 中,使用 SQLAlchemy 2.x 声明式语法,继承自 DeclarativeBase。数据库为 SQLite,启用 WAL 模式。

实体关系图


Photo (截图)

表名:photos

列名类型约束说明
idIntegerPK, autoincrement主键
local_media_store_idString(128)nullableAndroid MediaStore ID(用于去重)
filenameString(512)NOT NULL原始文件名
original_pathString(1024)NOT NULL原始文件存储路径
thumbnail_pathString(1024)nullable缩略图路径
file_sizeBigIntegerdefault 0文件大小(字节)
widthIntegernullable图片宽度
heightIntegernullable图片高度
mime_typeString(64)default "image/jpeg"MIME 类型
source_typeString(64)default "screenshot"来源类型
device_idString(256)nullable设备标识
device_nameString(256)nullable设备名称
original_timestampDateTimenullable截图原始时间
sync_timeDateTimedefault utcnow同步时间
created_atDateTimedefault utcnow记录创建时间

唯一约束: (device_id, local_media_store_id) — 同一设备的同一张截图不会重复入库。

索引:

  • ix_photos_device_id — 按设备查询
  • ix_photos_original_timestamp — 按时间排序

关系: analysis — 一对一关联 Analysis,cascade delete-orphan,使用 selectin 加载策略。


Analysis (分析)

表名:analyses

列名类型约束说明
idIntegerPK, autoincrement主键
photo_idIntegerFK -> photos.id, NOT NULL关联截图
statusEnumdefault PENDING状态: pending/processing/done/error
llm_responseTextnullableLLM 原始返回的完整 JSON
app_nameString(256)nullable识别的应用名称
content_categoryString(256)nullable内容分类
intentString(256)nullable意图类型
summaryTextnullable内容摘要
entitiesTextnullable提取的实体 (JSON 数组)
confidenceFloatnullable置信度 0-1
error_messageTextnullable错误信息
created_atDateTimedefault utcnow创建时间
completed_atDateTimenullable完成时间

索引:

  • ix_analyses_status — 按状态筛选
  • ix_analyses_photo_id — 按截图查询

AnalysisStatus 枚举值:

class AnalysisStatus(str, enum.Enum):
PENDING = "pending" # 等待处理
PROCESSING = "processing" # 正在分析
DONE = "done" # 分析完成
ERROR = "error" # 分析失败

Conversation (对话)

表名:conversations

列名类型约束说明
idString(64)PK对话 ID (hex 格式)
titleString(256)default "新对话"对话标题
device_idString(256)nullable设备标识
created_atDateTimedefault utcnow创建时间
updated_atDateTimedefault utcnow最后更新时间

索引:

  • ix_conversations_device_id — 按设备筛选
  • ix_conversations_updated_at — 按更新时间排序

关系: messages — 一对多关联 ChatMessage,按 created_at 排序,cascade delete-orphan。


ChatMessage (聊天消息)

表名:chat_messages

列名类型约束说明
idIntegerPK, autoincrement主键
conversation_idString(64)FK -> conversations.id, NOT NULL所属对话
roleString(32)NOT NULL角色: user/assistant/tool
contentTextnullable消息内容
encrypted_contentTextnullableFernet 加密的敏感内容
tool_nameString(64)nullable工具名称 (role=tool 时)
tool_call_idString(128)nullable工具调用 ID
tool_callsTextnullable工具调用列表 (JSON, role=assistant 时)
created_atDateTimedefault utcnow创建时间

属性:

  • display_content — 如果 encrypted_content 存在则解密返回,否则返回 content

索引: ix_chat_messages_conversation_id


Dynamic (动态)

表名:dynamics

由后台意图推理生成的文章/笔记。

列名类型约束说明
idIntegerPK, autoincrement主键
titleString(512)NOT NULL文章标题
contentTextNOT NULLMarkdown 正文
summaryTextnullable一句话摘要
categoryString(64)default "note"分类: insight/reminder/report/note
source_photo_idsTextnullable来源截图 ID (JSON 数组)
source_conversation_idsTextnullable来源对话 ID (JSON 数组)
source_memory_idsTextnullable来源记忆 ID (JSON 数组)
confidenceFloatdefault 0.5置信度
is_readBooleandefault False是否已读
is_pinnedBooleandefault False是否置顶
device_idString(256)nullable设备标识
created_atDateTimedefault utcnow创建时间

索引: ix_dynamics_device_created(device_id, created_at) 复合索引


Memory (记忆)

表名:memories

Agent 记忆系统,分为短期(48h 过期)和长期(持久)两种类型。

列名类型约束说明
idIntegerPK, autoincrement主键
contentTextNOT NULL记忆内容
encrypted_contentTextnullableFernet 加密的内容
content_hashString(32)nullable, indexedMD5 哈希(用于去重)
memory_typeString(32)NOT NULLshort_term/long_term
source_typeString(32)NOT NULLchat/photo/inferred
source_idString(128)nullable来源 ID (conversation_id 或 photo_id)
categoryString(64)default "fact"分类: fact/people/project/finance/schedule/preference/interest/habit
importanceFloatdefault 0.5重要度 0-1
access_countIntegerdefault 0访问次数
device_idString(256)nullable设备标识
created_atDateTimedefault utcnow创建时间
last_accessedDateTimenullable最后访问时间
expires_atDateTimenullable过期时间(null = 永不过期)

唯一约束: (device_id, content_hash) — 同一设备不存储重复记忆。

索引:

  • ix_memories_device_type(device_id, memory_type) 复合索引
  • ix_memories_expires — 按过期时间查询(清理用)

属性:

  • display_content — 解密后的内容

DeviceToken (推送设备)

表名:device_tokens

列名类型约束说明
idIntegerPK, autoincrement主键
device_idString(256)NOT NULL, UNIQUE设备标识
tokenString(1024)NOT NULLFCM Token 或推送端点
platformString(32)default "android"平台: android/ios
device_nameString(256)nullable设备名称
device_modelString(256)nullable设备型号
app_versionString(32)nullableApp 版本
last_seenDateTimenullable最后在线时间
created_atDateTimedefault utcnow注册时间

索引: ix_device_tokens_device_id


DeviceSyncState (设备同步状态)

表名:device_sync_state

列名类型约束说明
device_idString(256)PK设备标识
device_nameString(256)nullable设备名称
last_synced_timestampDateTimenullable最后同步的截图时间戳
last_sync_timeDateTimenullable最后同步操作时间
total_syncedIntegerdefault 0已同步总数

Skill (技能)

表名:skills

列名类型约束说明
idString(64)PK技能 ID (小写字母数字下划线)
nameString(128)NOT NULL技能名称
descriptionTextnullable技能描述
system_promptTextNOT NULL注入 Agent 的系统提示词
iconString(16)default "⚡"图标 (emoji)
enabledBooleandefault True是否启用
created_atDateTimedefault utcnow创建时间

默认技能:

ID名称图标说明
summarize总结截图📝分析最近截图,生成摘要笔记
reminders提取提醒从截图中提取提醒事项
research深度研究🔬对截图主题进行深入研究
stock股票分析📈整理截图中的金融信息

MCPServer (MCP 服务器)

表名:mcp_servers

列名类型约束说明
idString(64)PK服务器 ID
nameString(128)NOT NULL服务器名称
urlString(512)NOT NULL服务器 URL (含 SSRF 防护)
descriptionTextnullable描述
enabledBooleandefault True是否启用
tools_jsonTextnullable工具列表 (JSON)
created_atDateTimedefault utcnow创建时间

LLMConfig (LLM 配置)

表名:llm_config

单行配置表(固定 id=1),存储 LLM 服务商配置。

列名类型约束说明
idIntegerPK, default 1固定为 1
providerString(64)default "mimo"服务商名称
base_urlString(512)default mimo URLAPI 地址
api_keyString(512)default ""API Key(明文存储,已知限制)
modelString(128)default "mimo-v2.5"模型名称
max_context_tokensIntegerdefault 1048576最大上下文 token 数
temperatureFloatdefault 0.1生成温度
updated_atDateTimedefault utcnow最后更新时间

!!! warning "安全注意" api_key 以明文存储在数据库中。API 响应中不会返回实际值,仅返回 api_key_set: true/false。生产环境建议使用 EVATAR_ENCRYPTION_KEY 环境变量配合 Fernet 加密。