[Feature]: 支持编辑 image_ocr / image_caption 分块并重算 embedding(画廊图片描述可修改)
Affected Component
Backend Service & API
Problem Description
image_ocr、image_caption 分块参与检索,但当前无法修改,只能整库重新解析。
v0.9.0 里的三处限制(internal/application/service/chunk.go 在 v0.8.3 与 v0.9.0 内容完全一致,两版行为相同):
-
编辑接口硬拒绝非 text 分块 ——
internal/application/service/chunk.go:501:if chunk.ChunkType != types.ChunkTypeText { return nil, fmt.Errorf("only text chunks can be edited") }PUT /api/v1/chunks/{knowledge_id}/{chunk_id}对image_ocr/image_caption/image_vector/parent_text一律返回错误。Agent 工具chunk.update复用同一个 service,同样被拒。 -
前端分块详情不请求这两类 ——
frontend/src/api/knowledge-base/index.ts:677的getKnowledgeDetailsCon未传chunk_type,后端internal/handler/chunk.go:134默认只返回text:// Default to text chunks; callers may override via ?chunk_type=image_caption etc. chunkType := []types.ChunkType{types.ChunkTypeText}接口本身支持
?chunk_type=image_caption(可多值),但前端没有使用。 -
画廊只读 ——
GET与POST /api/v1/knowledge-bases/{id}/images都是列表查询(ListImagesPost只是把筛选参数放进 JSON 体以绕过长 URL),没有任何写入口。
对照 text 分块:编辑链路已经完整,chunk.go:613 的 syncChunkIndex 会重算索引,改正文会 rebuildParentContent,删除 Markdown 图片会通过 syncEditedChunkImages 禁用对应图片子块。"编辑后重新 embedding" 的链路已经存在,只是不对 image_* 类型开放。
实际影响:视觉模型给出的描述可能跑偏或陷入重复循环(参见 #4242 的重复循环、#3834 的索引写入被吞),扫描页 OCR 的错字也无法修正。用户只能整库重新解析,代价是重跑 OCR/VLM/embedding,且未必得到更好结果。
Proposed Solution
- 放开
UpdateDocumentChunk对image_ocr、image_caption的类型限制,保留现有 revision 机制与expected_revision冲突检测(HTTP 409)。 - 编辑后重算该分块向量:
image_caption/image_ocr用文本 embedding 模型重算,并维护content_hash(v0.9.0 新增的000123_resource_content_hash_index)与index_status,避免被空图片分块清理逻辑或重复处理逻辑误判。 - 前端分块详情支持加载
chunk_type=text,image_ocr,image_caption,标出分块类型并提供编辑入口。 - 画廊里可对单张图的描述直接编辑,与分块详情共享同一接口。
Alternatives
- 前端只读、后端接口可改:改动最小,但用户需要自己拼请求。
- 重新生成而非编辑:现有的
image_caption_enabled只能整库重跑 caption,无法针对单张图纠正,也覆盖不了 OCR 文本。
Impact
Many users would benefit
Use Case
- 扫描件 PDF 某页 OCR 把型号、编号识别错,检索和问答都会带着错字。
- 视觉模型把表格或图纸描述成空泛的一句话(或陷入重复循环),实际内容没有进入向量。
- 图纸类知识库需要人工校准图片描述,让它与业务术语一致,之后才对检索有用。
Additional Information
关联 issue:
- #2361(已完成):实现了
text分块的手动编辑与历史版本。本 issue 是把同一能力扩展到image_*,不是重开该需求。 - #4129:分块列表可查看
image_ocr/image_caption。本 issue 是查看之后的编辑能力。 - #4661:补齐存量图片 OCR/描述及检索索引,属于重新生成,不是编辑。
- #4242、#3834:描述质量与索引写入问题,编辑能力可作为人工补救手段。
复现环境:v0.9.0(wechatopenai/weknora-app:v0.9.0),RETRIEVE_DRIVER=qdrant。直接调用 PUT /api/v1/chunks/{knowledge_id}/{chunk_id} 并传入 image_caption 分块 ID,返回 only text chunks can be edited。
Confirmation
- [x] I have searched existing issues and confirmed this is a new request
- [x] I understand this request may need discussion and evaluation