feat(knowledge): v2 Phase 3+4 向量混合检索与 AI Chat/Ask 双模式#10
Open
wynxing wants to merge 3 commits into
Open
Conversation
Phase 3 — sqlite-vec 向量索引 + RRF 混合检索:
- packages/ai: 新增 embedding.ts(OpenAI 兼容 /v1/embeddings batch,重试+超时,与 chat provider 解耦)
- packages/db: loadVecExtension/toVecBuffer + vec0 延迟建表(维度发现)+ embedding_cache 去重 + searchKnn(KNN)
+ getIndexStatus 三态(hybrid/indexing/fts-only) + 顺手修 reindexTask 缺 FTS5 INSERT bug
- modules/knowledge: service drain 队列(单飞 mutex, cache 复用) + searchHybrid(FTS5+vec) + rrf.ts 纯函数(k=60)
- routes: search 切 hybrid、index-status 真实 flags、新增 GET/PUT /embedding-config(内存态, apiKey 不回显)
- 前端: api 层 + KnowledgeSection embedding baseUrl/apiKey 配置闭环
Phase 4 — AI Chat/Ask 双模式 + 三级上下文 + 引用审计:
- packages/db: ai_conversations/ai_messages 表 + createAiConversationStore(多轮持久化 + sources_json)
- modules/ai/context.ts: ContextBuilder 纯函数(权重/greedy fill/gap fill 句子边界/三明治排序)
- modules/ai/citation.ts: injectSources(稳定 sN id) + parseAndAuditCitations(丢弃未注入 id 防幻觉) + buildSources(服务端生成)
- modules/ai/service.ts: handleChat(全量上下文多轮) + handleAsk(RAG 一次性) + plainChat 降级
- app.ts: /api/ai/chat 重构委托 service,请求体扩 mode/projectId/context/conversationId,ai:done 携带 {text,sources,retrievalMode}
测试:embedding(8)、rrf(6)、context(7)、citation(5)、db vec(skipIf)、server-local 全绿
本机无 better-sqlite3 binding,vec/sqlite 专属测试 skipIf,CI 验证
Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Fenno AI is not enabled for this organization Fenno AI is currently in internal testing and is not yet open for external organizations. If you would like to request access, sign in to Fenno AI Console, choose Give Feedback in the lower-left corner, and tell us what you need. We will follow up promptly. |
CI 在真实 sqlite-vec 环境暴露两个本机 skipIf 漏掉的问题: - KNN 测试用 updateNote 后未 reindex → 无 chunk → listPendingChunks 空。改用 reindexNote 显式触发。 - cache 测试 toEqual 失败:Float32 序列化 0.1→0.10000000149 精度损失。改 toBeCloseTo。 Co-Authored-By: Claude <noreply@anthropic.com>
原测试断言 vectorExtensionAvailable===false,但 CI 环境 vec 实际加载成功。 真实语义:mode 由 vecLoaded && providerConfigured 共同决定;无 embedding provider 配置时(providerConfigured=false)即为 fts-only,与 vec 是否加载无关。 Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
知识库 v2 Phase 3(sqlite-vec 向量索引 + RRF 混合检索)与 Phase 4(AI Chat/Ask 双模式 + 三级上下文权限 + 引用审计)。在 PR #9(Phase 0-2)之上叠加向量层与 RAG 对话层,向 issue #7/#8 推进。
Phase 3 — sqlite-vec + RRF
packages/ai/src/embedding.ts):OpenAI 兼容/v1/embeddingsbatch,重试+超时,与 chat provider 解耦(DeepSeek 无 embedding 端点)loadVecExtension/toVecBuffer+ vec0 延迟建表(首嵌发现维度)+embedding_cache内容哈希去重 +searchKnn(KNN) +getIndexStatus三态(hybrid/indexing/fts-only)reindexTask缺 FTS5 INSERT,task 无法被检索 → 已补searchHybrid(FTS5+vec) +rrf.ts纯函数(k=60)GET/PUT /api/knowledge/embedding-config(内存态,apiKey 不回显)Phase 4 — Chat/Ask 双模式
ai_conversations/ai_messages表 +createAiConversationStore(多轮 + sources_json)modules/ai/context.ts):权重/greedy fill/gap fill 句子边界/三明治排序modules/ai/citation.ts):injectSources(稳定 sN id) +parseAndAuditCitations(丢弃未注入 id 防幻觉) +buildSources(服务端生成,非模型自报)handleChat(全量上下文多轮) +handleAsk(RAG 一次性) +plainChat降级/api/ai/chat委托 service,请求体扩 mode/projectId/context/conversationId,ai:done携带{text, sources, retrievalMode}降级路径
mode='fts-only',search 回退 FTSmode='fts-only'测试计划
pnpm typecheck全绿(shared/ai/db/tts/desktop/server-local)pnpm -r test全绿:ai 8、db 9+4skip、server-local 41+5skip、desktop 28、tts 1说明
skipIf,CI 为唯一验证(Phase 2 已验证此模式)后续