fix: stabilize knowledge graph extraction for long documents
Long document imports could send oversized graph prompts, surface empty model responses without useful diagnostics, and fail the entire new document even when its full-text index was usable. Graph extraction now uses bounded token batches with retry and timeout handling, preserves successful partial results, and reports graph failures independently from new-document indexing. Chinese graph retrieval now recognizes bounded CJK query terms, while graph search keeps one-hop relationship context visible around matched entities. Release note: 修复长文档知识图谱抽取易因空响应或超时导致整篇文档导入失败的问题;现在图谱按 Token 分批重试,失败时仍保留新文档全文检索,并改进中文图谱问答和关系上下文展示。
This commit is contained in:
@@ -447,6 +447,50 @@ describe('KnowledgeService', () => {
|
||||
await service.dispose()
|
||||
})
|
||||
|
||||
it('publishes a new document when model graph extraction fails', async () => {
|
||||
const extractStructured = vi.fn(async () => {
|
||||
throw new Error('模型图谱抽取暂时不可用')
|
||||
})
|
||||
const { directory, service } = await createService(
|
||||
undefined,
|
||||
undefined,
|
||||
extractStructured
|
||||
)
|
||||
const sourcePath = join(directory, 'model-graph-failure.md')
|
||||
await writeFile(
|
||||
sourcePath,
|
||||
'# 可检索文档\n即使图谱失败,全文内容仍应可用。',
|
||||
'utf8'
|
||||
)
|
||||
const library = service.createLibrary({
|
||||
name: '模型图谱容错',
|
||||
storageMode: 'reference',
|
||||
graphEnabled: true,
|
||||
graphStrategy: 'model'
|
||||
})
|
||||
|
||||
await expect(
|
||||
service.importPaths(library.id, [sourcePath])
|
||||
).resolves.toBeUndefined()
|
||||
|
||||
const snapshot = service.snapshot(library.id)
|
||||
expect(snapshot.documents).toHaveLength(1)
|
||||
expect(service.search(library.id, '全文内容')).toHaveLength(1)
|
||||
expect(snapshot.tasks).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
kind: 'graph',
|
||||
status: 'failed',
|
||||
message: '模型图谱抽取暂时不可用'
|
||||
}),
|
||||
expect.objectContaining({
|
||||
kind: 'parsing',
|
||||
status: 'succeeded'
|
||||
})
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it('reextracts graph evidence and removes only stale generated entities', async () => {
|
||||
const { directory, service } = await createService()
|
||||
const sourcePath = join(directory, 'reextract.md')
|
||||
|
||||
Reference in New Issue
Block a user