diff --git a/go/internal/api/routes/core.go b/go/internal/api/routes/core.go index b13b14d..a4e00eb 100644 --- a/go/internal/api/routes/core.go +++ b/go/internal/api/routes/core.go @@ -21,11 +21,11 @@ import ( // API 暴露织忆的 HTTP API 端点 type API struct { LanceDB storage.LanceDB - Embedder *storage.Embedder - Reranker *storage.Reranker - Pipeline *storage.RecallPipeline + Embedder *storage.Embedder + Reranker *storage.Reranker + Pipeline *storage.RecallPipeline ConflictDetector *governance.ConflictDetector - GraphStore governance.GraphStore + GraphStore governance.GraphStore } func NewAPI(ldb storage.LanceDB, emb *storage.Embedder, rerank *storage.Reranker, cd *governance.ConflictDetector, gs governance.GraphStore) *API { @@ -33,11 +33,11 @@ func NewAPI(ldb storage.LanceDB, emb *storage.Embedder, rerank *storage.Reranker pipeline.SetPrefetchPusher(&WSPrefetchAdapter{}) return &API{ LanceDB: ldb, - Embedder: emb, - Reranker: rerank, - Pipeline: pipeline, + Embedder: emb, + Reranker: rerank, + Pipeline: pipeline, ConflictDetector: cd, - GraphStore: gs, + GraphStore: gs, } } @@ -101,6 +101,9 @@ func (a *API) Commit(w http.ResponseWriter, r *http.Request) { // 3a. 精确 content 匹配(内容完全相同) if existing.Content == req.Content { a.mergeMemory(existing, req.Content, req.Category, req.AgentID) + // 合并后仍需触发蒸馏:让 t6 等冲突检测器有机会比对这条记忆, + // 且 exact_dup 可能是 namespace 相同但实际语义冲突(如"在"vs"不在")。 + go AutoDistillTrigger(epID, req.Content, req.Category, req.Namespace, req.AgentID) respond(w, 200, map[string]string{ "episode_id": epID, "memory_id": existing.ID, "status": "merged", "reason": "exact_dup", @@ -113,6 +116,8 @@ func (a *API) Commit(w http.ResponseWriter, r *http.Request) { ev, eErr := a.Embedder.EncodeSingle(existing.Content) if eErr == nil && cosineSimilarity(vector, ev) >= 0.98 { a.mergeMemory(existing, req.Content, req.Category, req.AgentID) + // 与 exact_dup 同理:合并后仍需触发蒸馏,让冲突检测器有机会比对。 + go AutoDistillTrigger(epID, req.Content, req.Category, req.Namespace, req.AgentID) respond(w, 200, map[string]string{ "episode_id": epID, "memory_id": existing.ID, "status": "merged", "reason": "near_dup", @@ -228,11 +233,11 @@ func (a *API) Recall(w http.ResponseWriter, r *http.Request) { var req struct { Query string `json:"query"` Limit int `json:"limit"` - TopK int `json:"top_k"` // 兼容插件 top_k 参数 + TopK int `json:"top_k"` // 兼容插件 top_k 参数 Namespace string `json:"namespace"` - AgentID string `json:"agent_id"` // 用于推导默认 namespace + AgentID string `json:"agent_id"` // 用于推导默认 namespace Diversity float64 `json:"diversity"` - Mode string `json:"mode"` // "hybrid"(default), "semantic", "keyword" + Mode string `json:"mode"` // "hybrid"(default), "semantic", "keyword" } if err := json.NewDecoder(r.Body).Decode(&req); err != nil { respondError(w, 400, "invalid body") @@ -451,10 +456,10 @@ func (a *API) RecallDebug(w http.ResponseWriter, r *http.Request) { } type stepInfo struct { - Step string `json:"step"` - Status string `json:"status"` - LatencyMs int64 `json:"latency_ms"` - Detail string `json:"detail,omitempty"` + Step string `json:"step"` + Status string `json:"status"` + LatencyMs int64 `json:"latency_ms"` + Detail string `json:"detail,omitempty"` } var steps []stepInfo var totalStart = time.Now() @@ -513,12 +518,17 @@ func (a *API) RecallDebug(w http.ResponseWriter, r *http.Request) { results := make([]models.RecallResult, 0, req.Limit) for i, idx := range finalIndices { - if i >= req.Limit { break } + if i >= req.Limit { + break + } if idx < len(candidates) { c := candidates[idx] score := 0.0 for _, r := range reranked { - if r.Index == idx { score = r.Score; break } + if r.Index == idx { + score = r.Score + break + } } results = append(results, models.RecallResult{ ID: c.ID, Content: c.Content, Category: c.Category,