feat: 新增微信图片文字索引与问问微信图片检索能力

This commit is contained in:
电摇小子 committed 2026-09-16 10:42:52 +08:00
1 parent 24399f1d70
commit b8f08d54c8
46 files changed
+6938 -75

No files matched your search

+51
View File
@@ -42,8 +42,30 @@ export interface KnowledgeSourceMessage {
voiceTranscript?: string
/** Local coverage state only. Error text is never copied into the index. */
voiceTranscriptState?: 'pending' | 'transcribed' | 'failed'
/**
* 图片里的文字(本地 System OCR 的派生结果)。
*
* 与 voiceTranscript 同构:这是 **derived content**,原图片消息仍然是
* authoritative source。它绝不写回 message.body,也绝不产生"OCR 消息"。
*/
imageOcrText?: string
/** 图片 OCR 的本地状态;与 voiceTranscriptState 一样不含错误正文。 */
imageOcrState?: KnowledgeImageOcrState
}
/** 图片 OCR 的本地覆盖状态(错误详情绝不进索引)。 */
export type KnowledgeImageOcrState =
| 'pending'
| 'indexed'
| 'empty'
| 'metadata_missing'
| 'image_missing'
| 'decrypt_unavailable'
| 'decrypt_failed'
| 'decode_failed'
| 'ocr_failed'
| 'cancelled'
export interface KnowledgeNormalizedMessage extends KnowledgeSourceMessage {
searchableText: string
contentHash: string
@@ -194,9 +216,38 @@ export interface KnowledgeEvidence {
/** The source type belongs to the original message, not the retrieval method. */
sourceKind: KnowledgeMessageKind
text: string
/**
* 这条证据里「从图片里读出来的文字」(本地 System OCR 的派生结果)。
*
* 只用于**来源解释**:让用户/模型知道这段内容来自图片,而不是群友真的发了一条文字消息。
* authoritative source 始终是原始图片消息 —— 这里不产生任何"OCR 消息"。
*/
imageOcrText?: string
/**
* 命中所依赖的**派生来源**。
*
* 有值 = 这条结果依赖本地派生内容才能命中(而不是原始消息本身的文字)。
* 与 `sourceKind` 正交:`sourceKind` 说的是原始消息是什么,这里说的是"靠什么搜到的"。
*/
derivedSource?: 'image_ocr'
score?: number
}
/**
* 证据文本面向用户 / 模型时的可读化处理。
*
* `searchableText` 里的 `图片文字:` 只是索引期用来区分派生内容的内部标签,
* 它**绝不能出现在 Evidence 里**:用户不该看到引擎内部前缀,
* 而且"这段文字来自图片"应该由结构化的来源标记表达,而不是靠一个冒号前缀。
*/
export function toEvidenceDisplayText(searchableText: string): string {
return searchableText
.split('\n')
.map((line) => line.replace(/^\s*(?:图片文字|OCR|system-ocr)\s*[::]\s*/i, ''))
.join('\n')
.trim()
}
export interface KnowledgeVoiceCoverage {
voiceMessageCount: number
transcribedVoiceCount: number