后端: 1. Memory 写入链路新增"召回→比对→汇总"去重决策层 - 新增决策流程:Runner 根据decision.enabled 配置走决策路径(语义召回候选 → Hash 精确命中 → LLM 逐对比对 → 汇总决策 → 执行 ADD/UPDATE/DELETE/NONE),默认关闭,旧路径完全保留 - 新增 LLMDecisionOrchestrator:单对关系判断编排器,输出 duplicate/update/conflict/unrelated 四种关系 - 新增 decision_flow / apply_actions:决策流程主循环与动作落地(新增、更新内容、软删除、跳过) - 新增 aggregate_decision / decision_validate:汇总规则(按优先级判定动作)与 LLM 输出校验 - 新增 decision model:CandidateSnapshot / ComparisonResult / FinalDecision 等决策层核心类型 - ItemRepo 新增 FindActiveByHash / UpdateContentByID / SoftDeleteByID 三个决策层专用方法 - RAG Runtime / Pipeline / Service 新增 DeleteMemory 向量删除能力,MilvusStore 补充 duplicate collection 错误识别 - Runner 新增 syncVectorDeletes 处理决策层 DELETE 动作的向量清理 - config 新增 decision(enabled/candidateTopK/candidateMinScore/fallbackMode)和 write.mode 配置项,config_loader 增加默认值兜底 - 删除 HANDOFF-RAG复用后续实施计划.md 和旧 log.txt,新增 Log.txt 记录决策流程调试日志 - normalize_facts 导出 HashContent 供决策层复用,audit 新增 update 操作常量 前端:无 仓库:无
119 lines
2.9 KiB
Go
119 lines
2.9 KiB
Go
package rag
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Runtime 是 RAG Infra 对业务侧暴露的唯一稳定方法面。
|
|
//
|
|
// 职责边界:
|
|
// 1. 负责承接 memory/web 两类语料的统一入库与检索入口;
|
|
// 2. 负责屏蔽底层 Pipeline / Store / Embedder / Reranker 的装配细节;
|
|
// 3. 不负责 provider 搜索、HTML 抓取、prompt 注入等业务语义。
|
|
type Runtime interface {
|
|
IngestMemory(ctx context.Context, req MemoryIngestRequest) (*IngestResult, error)
|
|
RetrieveMemory(ctx context.Context, req MemoryRetrieveRequest) (*RetrieveResult, error)
|
|
DeleteMemory(ctx context.Context, documentIDs []string) error
|
|
|
|
IngestWeb(ctx context.Context, req WebIngestRequest) (*IngestResult, error)
|
|
RetrieveWeb(ctx context.Context, req WebRetrieveRequest) (*RetrieveResult, error)
|
|
}
|
|
|
|
// IngestResult 描述一次统一入库执行摘要。
|
|
type IngestResult struct {
|
|
DocumentCount int
|
|
ChunkCount int
|
|
DocumentIDs []string
|
|
}
|
|
|
|
// RetrieveHit 是对业务侧暴露的统一命中项。
|
|
type RetrieveHit struct {
|
|
ChunkID string
|
|
DocumentID string
|
|
Text string
|
|
Score float64
|
|
Metadata map[string]any
|
|
}
|
|
|
|
// RetrieveResult 描述一次检索执行摘要。
|
|
type RetrieveResult struct {
|
|
Items []RetrieveHit
|
|
RawCount int
|
|
FallbackUsed bool
|
|
FallbackReason string
|
|
}
|
|
|
|
// MemoryIngestItem 是 memory 语料入库项。
|
|
type MemoryIngestItem struct {
|
|
MemoryID int64
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
MemoryType string
|
|
Title string
|
|
Content string
|
|
Confidence float64
|
|
Importance float64
|
|
SensitivityLevel int
|
|
IsExplicit bool
|
|
Status string
|
|
TTLAt *time.Time
|
|
CreatedAt *time.Time
|
|
}
|
|
|
|
// MemoryIngestRequest 描述一次记忆向量入库请求。
|
|
type MemoryIngestRequest struct {
|
|
TraceID string
|
|
Action string
|
|
Items []MemoryIngestItem
|
|
}
|
|
|
|
// MemoryRetrieveRequest 描述一次记忆检索请求。
|
|
type MemoryRetrieveRequest struct {
|
|
TraceID string
|
|
Query string
|
|
TopK int
|
|
Threshold float64
|
|
Action string
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
MemoryTypes []string
|
|
}
|
|
|
|
// WebIngestItem 是网页语料入库项。
|
|
type WebIngestItem struct {
|
|
URL string
|
|
Title string
|
|
Content string
|
|
Snippet string
|
|
Domain string
|
|
QueryID string
|
|
SessionID string
|
|
PublishedAt *time.Time
|
|
FetchedAt *time.Time
|
|
SourceRank int
|
|
}
|
|
|
|
// WebIngestRequest 描述一次网页语料入库请求。
|
|
type WebIngestRequest struct {
|
|
TraceID string
|
|
Action string
|
|
Items []WebIngestItem
|
|
}
|
|
|
|
// WebRetrieveRequest 描述一次网页检索请求。
|
|
type WebRetrieveRequest struct {
|
|
TraceID string
|
|
Query string
|
|
TopK int
|
|
Threshold float64
|
|
Action string
|
|
QueryID string
|
|
SessionID string
|
|
Domain string
|
|
}
|