feat: 增强知识库索引与设置页面模块化拆分
扩展知识库索引任务和 RAG 检索支持增量入库和文档去重,优 化本体检测和规则匹配精度,前端设置页面拆分为 LLM、邮件 和 Hermes 员工同步子面板并重构样式,新增日志详情组件和 知识入库日志模型,补充单元测试覆盖。
This commit is contained in:
117
web/tests/knowledge-ingest-log-model.test.mjs
Normal file
117
web/tests/knowledge-ingest-log-model.test.mjs
Normal file
@@ -0,0 +1,117 @@
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
buildKnowledgeIngestLogModel,
|
||||
isKnowledgeIngestRun
|
||||
} from '../src/utils/knowledgeIngestLogModel.js'
|
||||
|
||||
function buildRun() {
|
||||
return {
|
||||
status: 'running',
|
||||
route_json: {
|
||||
job_type: 'knowledge_index_sync',
|
||||
folder: '制度文件',
|
||||
phase: 'indexing',
|
||||
progress: {
|
||||
total_documents: 2,
|
||||
completed_documents: 1,
|
||||
failed_documents: 0,
|
||||
percent: 55
|
||||
},
|
||||
knowledge_ingest: {
|
||||
status: 'running',
|
||||
phase: 'indexing',
|
||||
current_document_id: 'doc-2',
|
||||
graph: {
|
||||
chunk_count: 5,
|
||||
entity_count: 3,
|
||||
relation_count: 2,
|
||||
entities: ['远光软件', '支出管理'],
|
||||
relations: [{ source: '远光软件', target: '支出管理', type: '关联' }]
|
||||
},
|
||||
documents: [
|
||||
{
|
||||
document_id: 'doc-1',
|
||||
name: '公司支出管理办法.pdf',
|
||||
folder: '制度文件',
|
||||
extension: 'pdf',
|
||||
status: 'succeeded',
|
||||
phase: 'indexed',
|
||||
chunk_count: 3,
|
||||
entity_count: 2,
|
||||
relation_count: 1,
|
||||
chunks: [{ id: 'chunk-1', order: 0, tokens: 21, summary: '支出管理范围' }],
|
||||
sections: [{ title: '第一章 总则', excerpt: '适用于公司支出。' }],
|
||||
events: [{ at: '2026-05-22T08:00:00Z', level: 'info', message: '完成' }]
|
||||
},
|
||||
{
|
||||
document_id: 'doc-2',
|
||||
name: '费用审批台账.xlsx',
|
||||
folder: '制度文件',
|
||||
extension: 'xlsx',
|
||||
status: 'running',
|
||||
phase: 'indexing',
|
||||
chunk_count: 2,
|
||||
entity_count: 1,
|
||||
relation_count: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testDetectsKnowledgeIngestRun() {
|
||||
assert.equal(isKnowledgeIngestRun(buildRun()), true)
|
||||
assert.equal(isKnowledgeIngestRun({ route_json: { job_type: 'daily_check' } }), false)
|
||||
}
|
||||
|
||||
function testBuildsInteractiveModel() {
|
||||
const model = buildKnowledgeIngestLogModel(buildRun())
|
||||
|
||||
assert.equal(model.available, true)
|
||||
assert.equal(model.folder, '制度文件')
|
||||
assert.equal(model.selectedDocumentId, 'doc-2')
|
||||
assert.equal(model.documents.length, 2)
|
||||
assert.equal(model.documents[0].statusLabel, '已完成')
|
||||
assert.equal(model.documents[0].chunks[0].summary, '支出管理范围')
|
||||
assert.equal(model.graph.entityCount, 3)
|
||||
assert.equal(model.graph.relations[0].source, '远光软件')
|
||||
assert.equal(model.metrics[1].value, '5')
|
||||
}
|
||||
|
||||
function testFallsBackToToolCallDocuments() {
|
||||
const model = buildKnowledgeIngestLogModel({
|
||||
status: 'succeeded',
|
||||
route_json: {
|
||||
job_type: 'knowledge_index_sync',
|
||||
requested_document_ids: ['doc-1']
|
||||
},
|
||||
tool_calls: [
|
||||
{
|
||||
response_json: {
|
||||
documents: [
|
||||
{
|
||||
document_id: 'doc-1',
|
||||
name: '归集结果.docx',
|
||||
status: 'succeeded',
|
||||
chunk_count: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert.equal(model.documents[0].name, '归集结果.docx')
|
||||
assert.equal(model.graph.chunkCount, 1)
|
||||
}
|
||||
|
||||
function run() {
|
||||
testDetectsKnowledgeIngestRun()
|
||||
testBuildsInteractiveModel()
|
||||
testFallsBackToToolCallDocuments()
|
||||
console.log('knowledge ingest log model tests passed')
|
||||
}
|
||||
|
||||
run()
|
||||
Reference in New Issue
Block a user