76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package ctxmgr_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/ctxmgr"
|
|
"chat-agent-system/internal/docgov"
|
|
)
|
|
|
|
func TestContextManager_ApprovedCaseIndexingAndSemanticSearch(t *testing.T) {
|
|
mgr := ctxmgr.NewContextManager(nil, nil, ctxmgr.DefaultTimeDecayConfig())
|
|
ctx := context.Background()
|
|
|
|
// 1. 模拟一个已被终审批准的交付物
|
|
approvedTime := time.Now()
|
|
doc := &docgov.DocumentRecord{
|
|
DocID: "doc_proj101_feasibility_reg",
|
|
ProjectID: 101,
|
|
TaskKey: "feasibility_reg",
|
|
Title: "注册路径可行性评估报告",
|
|
Stage: "V0.5_feasibility",
|
|
CurrentState: docgov.StateApproved,
|
|
IsLocked: true,
|
|
ApprovedAt: &approvedTime,
|
|
AuthorName: "张工",
|
|
}
|
|
|
|
markdownBody := `# 注册路径可行性评估报告
|
|
|
|
## 概述与器械分类
|
|
超声软组织切割止血手术设备,主要用于外科手术中软组织的切割与血管闭合,按国家药监局三类医疗器械管理。
|
|
|
|
## 关键性能与型检预估
|
|
设备需满足 GB 9706.1-2020 电气安全标准,以及 YY 0644 超声手术设备专用安全要求。型式检验周期预估 4-6 个月。
|
|
|
|
## 注册申报周期与成本策略
|
|
整体 CDMO 研发与型检预算约为 180 万元人民币,临床评价采用同品种对比路径。`
|
|
|
|
// 2. 切片并向量化入库
|
|
chunkIDs, err := mgr.IndexApprovedDocument(ctx, doc, markdownBody)
|
|
if err != nil {
|
|
t.Fatalf("IndexApprovedDocument failed: %v", err)
|
|
}
|
|
if len(chunkIDs) == 0 {
|
|
t.Fatalf("expected indexed chunks, got 0")
|
|
}
|
|
|
|
// 3. 语义搜索相似标杆案例
|
|
cases, err := mgr.SearchSimilarCases(ctx, ctxmgr.CaseSearchOptions{
|
|
Query: "超声刀设备需要测哪些电气安全和专用标准?",
|
|
Limit: 3,
|
|
MinScore: 0.10,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("SearchSimilarCases failed: %v", err)
|
|
}
|
|
if len(cases) == 0 {
|
|
t.Fatalf("expected similar cases found, got 0")
|
|
}
|
|
|
|
foundStandard := false
|
|
for _, c := range cases {
|
|
if c.DocID == doc.DocID && c.TaskKey == "feasibility_reg" {
|
|
foundStandard = true
|
|
t.Logf("✓ 成功命中往期标杆案例: 标题=%s, 章节=%s, 相似度=%.2f, 提要=%s",
|
|
c.ArtifactTitle, c.SectionTitle, c.SimilarityScore, c.SummarySnippet)
|
|
break
|
|
}
|
|
}
|
|
if !foundStandard {
|
|
t.Fatalf("expected to match indexed document doc_proj101_feasibility_reg")
|
|
}
|
|
}
|