From 93671dc1d6ec7c341dfb68d0c60973c982711b7a Mon Sep 17 00:00:00 2001 From: xiaowei Date: Sat, 30 May 2026 21:58:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=85=A5=20WSPrefetchAdapter?= =?UTF-8?q?=20=E5=88=B0=20recall=20=E7=AE=A1=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 WSPrefetchAdapter 实现 storage.PrefetchPusher 接口 - 当 agentID 为空时使用 WSBus.Broadcast(支持多 Agent) - 在 NewAPI 中通过 SetPrefetchPusher 注入 - WebSocket prefetch.push 事件在 CO_OCCURS 权重 > 0.6 时触发 --- go/internal/api/routes/core.go | 4 +++- go/internal/api/routes/ws_events.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go/internal/api/routes/core.go b/go/internal/api/routes/core.go index 06c70cf..7884568 100644 --- a/go/internal/api/routes/core.go +++ b/go/internal/api/routes/core.go @@ -24,11 +24,13 @@ type API struct { } func NewAPI(ldb storage.LanceDB, emb *storage.Embedder, rerank *storage.Reranker) *API { + pipeline := storage.NewRecallPipeline(emb, ldb, rerank) + pipeline.SetPrefetchPusher(&WSPrefetchAdapter{}) return &API{ LanceDB: ldb, Embedder: emb, Reranker: rerank, - Pipeline: storage.NewRecallPipeline(emb, ldb, rerank), + Pipeline: pipeline, } } diff --git a/go/internal/api/routes/ws_events.go b/go/internal/api/routes/ws_events.go index 8329e92..99241b5 100644 --- a/go/internal/api/routes/ws_events.go +++ b/go/internal/api/routes/ws_events.go @@ -1,6 +1,19 @@ // 织忆 MemoryWeave — WebSocket 事件推送函数 package routes +import "github.com/xiaoxue/memoryweave/internal/models" + +// WSPrefetchAdapter 实现 storage.PrefetchPusher 接口 +type WSPrefetchAdapter struct{} + +func (a *WSPrefetchAdapter) PushPrefetch(agentID string, memories []models.RecallResult) { + if agentID != "" { + WSBus.Push(agentID, "prefetch.push", memories) + } else { + WSBus.Broadcast("prefetch.push", memories) + } +} + // PushPrefetch 预取推送(recall 管道调用) func PushPrefetch(agentID string, memories interface{}) { WSBus.Push(agentID, "prefetch.push", memories)