封堵鉴权旁路与导出 IDOR,DocGov 改服务端身份;对话层 PendingAction 接真实 docgov/taskrun;修复流式租约假死与会话级任务流;加固配置/doc_id/NULL;补齐 slog 与测试;前端 ErrorBoundary 与受控文档重试。 Co-authored-by: Cursor <cursoragent@cursor.com>
114 lines
4.8 KiB
Go
114 lines
4.8 KiB
Go
package kb
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// KnowledgeDomain 知识领域类型
|
|
type KnowledgeDomain string
|
|
|
|
const (
|
|
// DomainRegulatory 医疗器械法律法规、国家标准(GB/T)、行业标准(YY)与指导原则
|
|
DomainRegulatory KnowledgeDomain = "regulatory"
|
|
// DomainProjectAsset 已完成历史项目数字资产(可行性报告、CDO 报价、方案文档、BOM清单)
|
|
DomainProjectAsset KnowledgeDomain = "project_asset"
|
|
// DomainStaffCapability 研发团队人员工作能力(技术专长、历史人效系数、工时评估模型)
|
|
DomainStaffCapability KnowledgeDomain = "staff_capability"
|
|
)
|
|
|
|
// HitItem 统一跨领域知识检索命中项
|
|
type HitItem struct {
|
|
Domain KnowledgeDomain `json:"domain"`
|
|
Category string `json:"category"` // standards, guidance, laws, catalog, project_doc, staff_model
|
|
DocCode string `json:"doc_code"` // 如 GB 9706.1-2020, YY 0569-2019, PRJ-2025-001
|
|
Title string `json:"title"` // 文档或标准全称
|
|
HeadingPath string `json:"heading_path"` // 章节小节层级路径 (如: 8. 电气安全 > 8.4 接地)
|
|
Content string `json:"content"` // 命中正文或条款详细描述
|
|
Score float64 `json:"score"` // 综合匹配评分 (Reranker 或 RRF 分数)
|
|
CiteKey string `json:"cite_key"` // 权威引用键 (如: [GB 9706.1-2020 §8.4])
|
|
Source string `json:"source"` // 来源信息
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
}
|
|
|
|
// SearchOptions 检索配置选项
|
|
type SearchOptions struct {
|
|
Domains []KnowledgeDomain `json:"domains,omitempty"` // 目标领域范围 (空表示默认法规域)
|
|
ProjectID int64 `json:"project_id,omitempty"` // 项目资产检索必填:限定项目范围
|
|
RequesterID int64 `json:"requester_id,omitempty"` // 项目资产检索必填:请求者身份(审计/ACL)
|
|
Limit int `json:"limit,omitempty"` // 最终期望返回数量
|
|
CandidateLimit int `json:"candidate_limit,omitempty"` // 初筛召回数量 (Rerank 前)
|
|
IncludeRepealed bool `json:"include_repealed,omitempty"` // 是否包含已废止/历史版本标准
|
|
FilterCategory string `json:"filter_category,omitempty"` // 过滤分类
|
|
MinScore float64 `json:"min_score,omitempty"` // 最低分数阈值
|
|
}
|
|
|
|
// DefaultSearchOptions 返回通用检索默认配置
|
|
func DefaultSearchOptions() SearchOptions {
|
|
return SearchOptions{
|
|
Domains: []KnowledgeDomain{DomainRegulatory},
|
|
Limit: 5,
|
|
CandidateLimit: 20,
|
|
IncludeRepealed: false,
|
|
MinScore: 0.0,
|
|
}
|
|
}
|
|
|
|
// Document 数据库文档实体
|
|
type Document struct {
|
|
ID int64 `json:"id"`
|
|
DocID string `json:"doc_id"`
|
|
SHA256 string `json:"sha256"`
|
|
FilePath string `json:"file_path"`
|
|
FileName string `json:"file_name"`
|
|
Kind string `json:"kind"`
|
|
DocNo string `json:"doc_no"`
|
|
Title string `json:"title"`
|
|
Jurisdiction string `json:"jurisdiction"`
|
|
Status string `json:"status"`
|
|
EffectiveDate *time.Time `json:"effective_date,omitempty"`
|
|
RepealDate *time.Time `json:"repeal_date,omitempty"`
|
|
SourceURL string `json:"source_url"`
|
|
PageCount int `json:"page_count"`
|
|
ExtraJSON map[string]any `json:"extra_json,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// Node 结构化大纲节点实体
|
|
type Node struct {
|
|
ID int64 `json:"id"`
|
|
DocumentID int64 `json:"document_id"`
|
|
ParentID *int64 `json:"parent_id,omitempty"`
|
|
Level int `json:"level"`
|
|
NodeKind string `json:"node_kind"`
|
|
SectionNo string `json:"section_no"`
|
|
Title string `json:"title"`
|
|
HeadingPath string `json:"heading_path"`
|
|
Content string `json:"content"`
|
|
PageStart int `json:"page_start"`
|
|
PageEnd int `json:"page_end"`
|
|
SortOrder int `json:"sort_order"`
|
|
}
|
|
|
|
// Chunk 向量切片实体
|
|
type Chunk struct {
|
|
ID int64 `json:"id"`
|
|
DocumentID int64 `json:"document_id"`
|
|
NodeID int64 `json:"node_id"`
|
|
Grain string `json:"grain"`
|
|
ChunkNo string `json:"chunk_no"`
|
|
Content string `json:"content"`
|
|
HeadingPath string `json:"heading_path"`
|
|
CiteKey string `json:"cite_key"`
|
|
Page int `json:"page"`
|
|
Embedding []float32 `json:"-"`
|
|
MetadataJSON map[string]any `json:"metadata_json,omitempty"`
|
|
}
|
|
|
|
// Stats 统计信息
|
|
type Stats struct {
|
|
DocumentCount int64 `json:"document_count"`
|
|
NodeCount int64 `json:"node_count"`
|
|
ChunkCount int64 `json:"chunk_count"`
|
|
}
|