feat(docreader): support forcing PDF scanned-page OCR parsing

This commit is contained in:
杨聪聪
2026-06-25 16:48:57 +08:00
committed by lyingbug
parent 2c44a41f2a
commit 917feceb59
14 changed files with 210 additions and 6 deletions
+4
View File
@@ -701,6 +701,10 @@ export default {
asrRequiredForAudio: 'Off (batch includes audio)',
vlmModelSelectRequired: 'Multimodal is enabled. Please select a VLM model.',
asrModelSelectRequired: 'Speech recognition is enabled. Please select an ASR model.',
pdfForceScanned: {
label: 'Force scanned PDF parsing',
description: 'Useful for web-print, scanned, or image-heavy PDFs. Every page will be rendered as an image and processed via OCR/VLM. May increase processing time and model costs.'
},
continueAdd: 'Add more',
addMoreFiles: 'Add more files',
addMoreFolder: 'Add more from folder',
+4
View File
@@ -704,6 +704,10 @@ export default {
asrRequiredForAudio: "未开启(本批次含音频)",
vlmModelSelectRequired: "已启用多模态,请选择 VLM 模型",
asrModelSelectRequired: "已启用语音识别,请选择 ASR 模型",
pdfForceScanned: {
label: "按扫描件解析 PDF",
description: "适用于网页打印、扫描件、图片型 PDF。开启后会逐页 OCR,解析更完整但耗时和模型调用更多。"
},
continueAdd: "继续添加",
addMoreFiles: "继续添加文件",
addMoreFolder: "继续添加文件夹",
+1
View File
@@ -62,4 +62,5 @@ export interface KnowledgeProcessOverrides {
question_generation_config?: QuestionGenerationConfigOverride
graph_enabled?: boolean
extract_config?: ExtractConfigOverride
parser_engine_overrides?: Record<string, string>
}
@@ -124,6 +124,17 @@
:parser-engine-rules="uiState.chunkingConfig.parserEngineRules"
@update:parser-engine-rules="handleParserEngineRulesUpdate"
/>
<div v-if="hasPdf" class="kb-embedded-settings" style="margin-top: 16px;">
<div class="setting-row setting-row--toggle">
<div class="setting-info">
<label>{{ t('uploadConfirm.pdfForceScanned.label') }}</label>
<p class="desc">{{ t('uploadConfirm.pdfForceScanned.description') }}</p>
</div>
<div class="setting-control">
<t-switch v-model="uiState.pdfForceScanned" size="medium" />
</div>
</div>
</div>
</div>
<div v-show="activeSection === 'chunking'" class="section">
<KBChunkingSettings
@@ -290,6 +301,7 @@ interface UploadUIState {
relations: Array<{ node1: string; node2: string; type: string }>
}
graphEnabled: boolean
pdfForceScanned: boolean
}
const props = withDefaults(defineProps<{
@@ -437,6 +449,10 @@ const batchFileExts = computed(() => {
return [...set]
})
const hasPdf = computed(() => {
return batchFileExts.value.includes('pdf')
})
function resolveEngineForExt(ext: string): string {
const rules = uiState.value.chunkingConfig.parserEngineRules
if (rules?.length) {
@@ -624,6 +640,7 @@ function createDefaultUIState(): UploadUIState {
relations: [],
},
graphEnabled: false,
pdfForceScanned: false,
}
}
@@ -670,6 +687,7 @@ function initFromKbInfo(kb: any) {
relations: kb.extract_config?.relations || [],
},
graphEnabled: kb.indexing_strategy?.graph_enabled ?? false,
pdfForceScanned: false,
}
}
@@ -677,7 +695,7 @@ function buildProcessOverrides(): KnowledgeProcessOverrides {
const state = uiState.value
const chunking = state.chunkingConfig
return {
const overrides: KnowledgeProcessOverrides = {
parser_engine_rules: chunking.parserEngineRules,
chunking_config: {
chunk_size: chunking.chunkSize,
@@ -713,6 +731,14 @@ function buildProcessOverrides(): KnowledgeProcessOverrides {
relations: state.nodeExtractConfig.relations,
},
}
if (state.pdfForceScanned) {
overrides.parser_engine_overrides = {
pdf_force_scanned: 'true',
}
}
return overrides
}
function applyOverridesToState(o?: KnowledgeProcessOverrides | null) {
@@ -756,6 +782,11 @@ function applyOverridesToState(o?: KnowledgeProcessOverrides | null) {
if (ec.relations) s.nodeExtractConfig.relations = ec.relations
}
if (o.graph_enabled != null) s.graphEnabled = o.graph_enabled
if (o.parser_engine_overrides && o.parser_engine_overrides.pdf_force_scanned === 'true') {
s.pdfForceScanned = true
} else {
s.pdfForceScanned = false
}
}
async function loadModels() {