feat: 完整实现 NLP 三元组提取系统 + token budget 上下文分配

- 重写 extractor.go: 分句、17条 POS 模板、依存模板 + COO 链、ATT合并
- parser.go: 分句循环 + TransE 向量验证(h+r≈t)
- fallback.go: jieba POS 降级解析器
- bridge.go: nlp.Triple ↔ memory.Triple 转换
- pipeline.go: extractKeyTriples 改用 NLP 提取器, 删除5条旧前缀规则
- distill.go: docToTriples 改用 NLP 提取器
- reorgGraph: 语义相似度增强检测, 保持纯 LLM 决断
- Provider 接口加 MaxContextTokens() + 模型窗口映射表
- tokenbudget.go: 中文 token 估算器 + budget 分配(80%利用率)
- process.go/buildSystemPrompt: 按 token 预算截断 memory+timeline
This commit is contained in:
root
2026-07-27 15:26:23 +08:00
parent d19b7bd13e
commit 1cb3e87dde
30 changed files with 1508 additions and 773 deletions

View File

@ -35,14 +35,11 @@ func TestDocToTriples(t *testing.T) {
triples := docToTriples(doc)
foundSummary := false
foundRel := false
foundSource := false
for _, tr := range triples {
switch {
case tr.Subject == "文档" && tr.Relation == "主题":
foundSummary = true
case tr.Relation == "关联":
foundRel = true
case tr.Subject == "文档" && tr.Relation == "来源":
foundSource = true
}
@ -54,9 +51,6 @@ func TestDocToTriples(t *testing.T) {
if !foundSource {
t.Error("missing '来源' triple")
}
if needJieba() && !foundRel {
t.Error("missing '关联' triple with jieba available")
}
}
func TestDocToTriplesNil(t *testing.T) {
@ -88,7 +82,6 @@ func TestDocToTriplesTypes(t *testing.T) {
triples := docToTriples(doc)
// 主题 and 来源 triples have Subject=文档
for _, tr := range triples {
if tr.Subject == "文档" {
if tr.SubjectType != "Concept" {
@ -97,14 +90,6 @@ func TestDocToTriplesTypes(t *testing.T) {
if tr.Confidence != 1.0 {
t.Errorf("文档 triple confidence should be 1.0, got %f", tr.Confidence)
}
} else {
// 关联 triples use extracted terms as subject/object
if tr.Relation != "关联" {
t.Errorf("non-文档 triple should have 关联 relation, got %q", tr.Relation)
}
if tr.Confidence != 0.8 {
t.Errorf("关联 triple confidence should be 0.8, got %f", tr.Confidence)
}
}
// all should have SubjectType/ObjectType set
if tr.SubjectType == "" || tr.ObjectType == "" {