Files
HomeAgent/internal/sdk/memory.go
JianFeeeee 86572d134d refactor(memory)!: 块 union 化,彻底淘汰 CAS 第一阶段(生产代码)
块自带负载(MemoryBlock.Data),删 PayloadDigest;检索纯向量,媒体随块
同生灭。生产代码全绿;CAS 专属测试将在下一提交随判据重写。

- memory: Data BLOB + migration9;blockColumns 不含 data(召回只比向量);
  MediaBlockID 内容派生 ID;BlockByIDPrefix/BlockData 按需加载
- sdk: memory_impl 去 media.Store;MemoryBlockView PayloadDigest→HasData
- core: mediaref/graphmedia/crossmodal/medialoop 全部改块语义;
  captureBlockMedia 直接产块;resolveMediaRefs 按块 ID 解析
- knowledge: 媒体字节随条目目录自带(File+Data),删 mediaGet/mediaPut
- webui: graphBlockView/pulse payload_digest→has_data
- bootstrap/registry: 去 MediaStore 接线(SetMediaStore 空实现,待⑥删包)
2026-10-12 10:13:36 +08:00

64 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package sdk
import (
"time"
pubsdk "github.com/JianFeeeee/homeagentsdk/sdk"
)
// MemoryBlockView 是块的最小只读视图(供星图轮询端点)。
//
// ★ 不直接用 memory.MemoryBlock:那是内核内部类型,而本包是**插件边界**。
// SDK 接口只暴露端点真正要用的字段(原来是先 GraphData 全量再转成
// graphBlockView 做同样的事,只是绕了一圈)。
type MemoryBlockView struct {
ID string `json:"id"`
Modality string `json:"modality"`
Text string `json:"text,omitempty"`
HasData bool `json:"has_data"` // 媒体负载在块内(CAS 淘汰后),只报有无不回显内容
MIME string `json:"mime,omitempty"`
Source string `json:"source,omitempty"`
Tool string `json:"tool,omitempty"`
Scene string `json:"scene,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// MemoryAPI 是内置插件使用的全量图记忆接口。
type MemoryAPI interface {
pubsdk.MemoryAPI
// GraphData 返回整个知识图谱的完整快照。
GraphData() (map[string]interface{}, error)
// BlocksChangedSince 返回自 since 之后创建或更新过的块(供星图轻量轮询)。
//
// ★ 为何单开一个方法而不复用 GraphData:后者是全量快照(生产实测
// 3190 块 + 2692 边,JSON 约 3.3MB、135ms),而轮询端点只想知「有新东西」。
// 原先 pulse 端点是先取全量再过滤 —— 实测与全量端点同价(145ms),
// 「轻量端点」名不副实。库侧 SQL 过滤后响应体差两个数量级。
//
// 属内置接口(非 pubsdk),与 GraphData 同理,不影响外部插件。
BlocksChangedSince(since time.Time, limit int) ([]MemoryBlockView, error)
}
type Entity = pubsdk.Entity
type Relation = pubsdk.Relation
type Triple = pubsdk.Triple
// TextMemoryAPI 是内置插件使用的全量文本记忆接口。
type TextMemoryAPI interface {
pubsdk.TextMemoryAPI
// RecentEvents 返回最近 n 条记忆事件。
RecentEvents(n int) ([]TextEvent, error)
// Stats 返回文本记忆的运行统计。
Stats() map[string]interface{}
}
type TextEvent = pubsdk.TextEvent
// MediaAttachment 是记忆附件(媒体)在插件边界上的表示。
// 与公共 SDK 同一类型,内置插件与外部插件用同一套字段。
type MediaAttachment = pubsdk.MediaAttachment
type DocMemoryAPI = pubsdk.DocMemoryAPI
type Doc = pubsdk.Doc