Files
thzxx 4cd6e997b5
CI / 类型检查 + Lint + 单元测试 (push) Failing after 9m45s
CI / 全量测试 (Electron ABI) (push) Failing after 6m28s
CI / 产物编译验证 (push) Successful in 11m18s
feat: v0.8.2 安全纵深补全 · 协议保真 · 断链修复 — 图片SSRF/根MEMORY.md保护根治 · Anthropic thinking回传+pause_turn续传 · 2523 用例全量回归 + E2E 扩充
2026-09-08 14:30:27 +08:00

28 lines
1.5 KiB
TypeScript
Raw Permalink 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.
/**
* Memory Embedder — 本地向量记忆嵌入接口(v0.8.1 P1-1
*
* 职责边界:本模块只定义记忆系统消费的嵌入契约,不绑定任何 Provider 实现。
* main.ts 按用户配置装配:仅在 Provider 为 Ollama(本地推理,零成本、数据不出设备)
* 且设置面板配置了 `memory.embeddingModel` 时注入真实实现;否则保持 null,
* MemoryManager 自动回退纯 TF-IDF 检索(行为与历史版本完全兼容)。
*
* 根治背景:OllamaAdapter.embed() 自实现以来全项目零调用 —— 本地向量检索能力
* 一直躺在代码里,TF-IDF bigram 对同义改写("我喜欢简洁回答" vs "回复要短"
* 零召回。本契约激活该能力,检索升级为 混合评分(向量余弦 × TF-IDF)。
*/
/** 嵌入失败/不可用的统一返回:null = 本次无法向量化(调用方回退 TF-IDF 路径) */
export type MemoryEmbedFn = (text: string) => Promise<number[] | null>;
export interface MemoryEmbedder {
embed: MemoryEmbedFn;
/**
* v0.8.2 P3-1: 嵌入模型标识(指纹)。
* 用户更换 embedding 模型后,旧向量与新查询向量维度/语义空间不匹配 ——
* 维度不同余弦静默为 0,同维不同模型产生噪声分数。Manager 以该标识标注
* 每条向量(embedding_model 列),检索时模型不匹配的向量视为缺失并惰性重算。
* 未提供时无法做指纹校验(旧向量一律接受 —— 保持旧行为兼容)。
*/
readonly modelName?: string;
}