M7-16 P0 | KnowledgeItem.sourceRef 从未被赋值,material scope 检索失效 #104

Closed
opened 2026-06-06 17:16:35 +08:00 by wangdl · 1 comment
Owner

发现

代码审查 Batch 2 发现 sourceRef 字段在整个代码库中只有一处使用:

// rag-chat.service.ts L347 - loadContextByScope material branch
where: {
  knowledgeBaseId: kbId,
  sourceRef: scopeId,  // ← 查询条件
  deletedAt: null,
}

sourceRef 从未在任何地方被赋值

  • KnowledgeItemsRepository.create() — 不传 sourceRef
  • ImportCandidateService.accept() — 不传 sourceRef
  • DocumentImportService — 不传 sourceRef

结果:material scope 的 AI 检索永远查不到任何 KnowledgeItem,资料范围的对话实际上用的是空上下文。

影响范围

  • ChatScope material 类型会话的 AI 回答无法检索到资料内容
  • 用户从「资料详情」进入 AI 对话时,AI 看不到该资料的内容
  • knowledge_baseknowledge_item scope 不受影响

修复方案

  1. KnowledgeItemsRepository.create() 增加 sourceRef 参数
  2. ImportCandidateService.accept() 传入 candidate 的 sourceId 作为 sourceRef
  3. 或者在 import candidate 创建时传入 sourceRef

涉及文件

文件 变更
src/modules/knowledge-items/knowledge-items.repository.ts create 增加 sourceRef 参数
src/modules/import-candidate/import-candidate.service.ts accept 传入 sourceRef
src/modules/import-candidate/import-candidate.repository.ts createMany 传入 sourceRef(如果有)
## 发现 代码审查 Batch 2 发现 `sourceRef` 字段在整个代码库中只有一处使用: ```typescript // rag-chat.service.ts L347 - loadContextByScope material branch where: { knowledgeBaseId: kbId, sourceRef: scopeId, // ← 查询条件 deletedAt: null, } ``` 但 `sourceRef` **从未在任何地方被赋值**: - `KnowledgeItemsRepository.create()` — 不传 sourceRef - `ImportCandidateService.accept()` — 不传 sourceRef - `DocumentImportService` — 不传 sourceRef **结果:material scope 的 AI 检索永远查不到任何 KnowledgeItem,资料范围的对话实际上用的是空上下文。** ## 影响范围 - ChatScope `material` 类型会话的 AI 回答无法检索到资料内容 - 用户从「资料详情」进入 AI 对话时,AI 看不到该资料的内容 - `knowledge_base` 和 `knowledge_item` scope 不受影响 ## 修复方案 1. `KnowledgeItemsRepository.create()` 增加 `sourceRef` 参数 2. `ImportCandidateService.accept()` 传入 candidate 的 sourceId 作为 sourceRef 3. 或者在 import candidate 创建时传入 sourceRef ## 涉及文件 | 文件 | 变更 | |------|------| | src/modules/knowledge-items/knowledge-items.repository.ts | create 增加 sourceRef 参数 | | src/modules/import-candidate/import-candidate.service.ts | accept 传入 sourceRef | | src/modules/import-candidate/import-candidate.repository.ts | createMany 传入 sourceRef(如果有)
wangdl added this to the M7:ChatScope 会话系统 — 学习对象绑定的上下文会话 milestone 2026-06-06 17:16:35 +08:00
Author
Owner

修复

  • KnowledgeItemsRepository.create() 支持 sourceRef 参数
  • ImportCandidateService.accept() 传入 candidate.sourceId 作为 sourceRef
  • update 白名单增加 sourceRef

涉及: knowledge-items.repository.ts + import-candidate.service.ts

## 修复 - KnowledgeItemsRepository.create() 支持 sourceRef 参数 - ImportCandidateService.accept() 传入 candidate.sourceId 作为 sourceRef - update 白名单增加 sourceRef 涉及: knowledge-items.repository.ts + import-candidate.service.ts
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#104
No description provided.