Skip to main content

系统架构

存储职责

存储内容原因
LanceDB Cloudmemories(向量 + content + metadata)专用向量引擎,不吃 Supabase CPU,serverless 按量付费
Supabase XLprofiles、consolidation 状态、结构化统计已有 XL 实例,边际成本为零
Dragonflyprofile 热缓存每次 inject 不查 Postgres,<1ms 返回

数据模型

memories(LanceDB Cloud)

interface Memory {
  id: string;                  // UUID
  entity_id: string;           // userId 或 groupId
  entity_type: 'user' | 'group';

  // 内容
  content: string;             // 自然语言描述
  embedding: Float32Array;     // 512 维向量(Voyage multimodal-3.5)

  // 分类
  type: 'preference' | 'workflow' | 'instruction' | 'episodic';
  source: 'behavior' | 'conversation' | 'explicit';

  // 权重
  importance: number;          // 0-1,重要性评分
  access_count: number;        // 被检索命中次数
  decay_weight: number;        // 衰减权重,定期降低

  // 元数据
  metadata: {
    thread_id?: string;
    tool_name?: string;
    model?: string;
    prompt?: string;
    satisfaction?: 'positive' | 'negative' | 'neutral';
  };

  // 时间
  created_at: string;          // ISO timestamp
  last_accessed_at?: string;
  consolidated_at?: string;    // 已固化到 profile 的时间
}

profiles(Supabase memory schema)

CREATE SCHEMA memory;

CREATE TABLE memory.profiles (
  entity_id     TEXT NOT NULL,
  entity_type   TEXT NOT NULL CHECK (entity_type IN ('user', 'group')),

  -- 画像摘要(LLM 生成的自然语言)
  style         TEXT,       -- "偏好复古暖色调,vintage 使用率 80%,平均暖色 +18"
  workflow      TEXT,       -- "典型流程:滤镜→微调→裁剪 1:1→导出。常用 upscale"
  instructions  TEXT,       -- "要求导出时保持原始分辨率,不喜欢过度饱和"
  context       TEXT,       -- 用户:"常拍人像" / 群:"商业摄影讨论群"

  -- 结构化统计(快速查询)
  stats         JSONB DEFAULT '{}',
  -- {
  --   "top_filters": [{"name":"vintage","pct":0.8}],
  --   "top_ratios": [{"ratio":"1:1","pct":0.9}],
  --   "top_tools": [{"tool":"upscale","pct":0.7}],
  --   "total_sessions": 142,
  --   "avg_edits_per_session": 3.2
  -- }

  updated_at    TIMESTAMPTZ DEFAULT NOW(),

  PRIMARY KEY (entity_type, entity_id)
);