mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-01 14:57:38 +00:00
## ① 全面改名 HomeAgent → HologramAgent
仓库已改名,但代码与文档里仍有大量旧名。本次按"用户能看到的优先"全量替换:
- 用户可见:登录页标题/页脚、默认人格第一句、CLI 状态输出、启动日志、
plugin_install 的工具描述、AI 图片插件的 User-Agent
- 文档与脚本:README、assets/docs、docs/zh、deploy/*.sh、.github/workflows
- 鸿蒙工程:cmd/ohos/HomeAgent → cmd/ohos/HologramAgent(git mv)
目录内的 module/app 描述同步;**证书路径原样保留**
(default_HomeAgent_xxx.cer/p7b/p12 是签名材料的实际文件名,改了会找不到证书)
- 插件元数据:plugin.json 的 author
★ 必须保持原样的两处(改了会坏):
· legacySeededPromptSignature = "你是 HomeAgent 的看板娘「小宅」…"
—— 那是识别历史播种人格卡的**原文锚点**,改了就识别不出旧数据
· 公开 SDK 的 ProxyAuthHomeAgent = "homeagent"
—— 那是 SDK 契约里的值,属独立仓库,本仓不改
## ② 修 21 处乱码(U+FFFD)
这些是历史编辑留下的编码破坏,全在注释里,例如:
「赌注重下���遍」→「赌注重下一遍」
「「不��滤」」 →「「不过滤」」
「**待��退场**」→「**待退场**」
★ 保留 providers/chineseclip/tokenizer.go 里的 2 处:那是**故意**用
U+FFFD 演示"非法 UTF-8 字节被归一成 U+FFFD",不是乱码。
## ③ 提示词技术内容下沉(用户:技术性内容应该收敛到 skill 与 -help 中)
实测系统提示词 2309 字,其中两段几乎全是**模型无法据以行动的实现细节**:
【工具执行顺序】1272 字(ParallelSafe 声明、批内降级、batchRunnable 判据…)
【三层记忆】 1069 字(L1/L2/L3 编号、消费式删除、向量空间、指纹…)
收敛后 **2309 → 1723 字(-25%)**,保留的全是"模型据此做什么不同的事":
工具顺序:默认并行 / 不要依赖先后 / 同通道保序 / 写类工具可能串行
三层记忆:时序里能看最近 / doc_query 把历史事件按原始时间戳插回时序 /
关系用 memory_recall / 成文知识用 knowledge_search
判断口径写进判据:新加一段提示词前先问"模型会据此做什么不同的事",
答不上来就该进 skill 或工具描述。
## 判据
prompt_memory_test.go 新增 2 条:
- TestSystemPromptHasNoImplementationJargon
黑名单:ParallelSafe / batchRunnable / 消费式 / DenseCosine / fingerprint /
向量空间 / 批内降级 / 自激
- TestSystemPromptStaysCompact:上限 2000 字(当前 1723)
变异:把 "ParallelSafe 声明、批内降级" 加回工具顺序段 ⇒ 第一条立刻红。
## 验证
- go build ./... / go vet ./... 干净
- go test ./... -count=1:58 包 0 失败
- make check-client-versions:客户端与内核版本一致
173 lines
5.1 KiB
Go
173 lines
5.1 KiB
Go
// Package embedding defines the public SPI for dense multimodal embedding providers.
|
|
//
|
|
// The HologramAgent core depends only on this package. Model runtimes, tokenizers,
|
|
// preprocessing, media decoding, and model-specific configuration belong in
|
|
// provider packages registered with Register.
|
|
package embedding
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
"sort"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// Modality identifies the semantic kind of an embedding input. Providers may
|
|
// support additional modality strings; the constants are the common values.
|
|
type Modality string
|
|
|
|
const (
|
|
ModalityText Modality = "text"
|
|
ModalityImage Modality = "image"
|
|
ModalityAudio Modality = "audio"
|
|
ModalityVideo Modality = "video"
|
|
)
|
|
|
|
// Purpose tells a provider how the vector will be used. Providers whose model
|
|
// distinguishes query and document prompts can map this value accordingly.
|
|
type Purpose string
|
|
|
|
const (
|
|
PurposeQuery Purpose = "query"
|
|
PurposeDocument Purpose = "document"
|
|
)
|
|
|
|
// Input is the model-neutral request passed to a provider.
|
|
//
|
|
// Data is deliberately opaque to the core. MIME describes the encoding; the
|
|
// selected provider owns decoding, frame sampling, preprocessing, and all
|
|
// other model-specific interpretation. Text is used for textual inputs.
|
|
type Input struct {
|
|
Modality Modality
|
|
Purpose Purpose
|
|
Text string
|
|
Data []byte
|
|
MIME string
|
|
Metadata map[string]string
|
|
}
|
|
|
|
// Info describes one vector space. Fingerprint must change whenever vectors
|
|
// cease to be comparable with vectors produced by a previous provider build.
|
|
type Info struct {
|
|
Dimension int
|
|
Fingerprint string
|
|
Modalities []Modality
|
|
}
|
|
|
|
// Provider is the public Go extension point for a dense multimodal vector
|
|
// space. Implementations must be safe for concurrent Embed calls unless their
|
|
// factory documents otherwise and serializes internally.
|
|
type Provider interface {
|
|
Embed(context.Context, Input) ([]float64, error)
|
|
Info() Info
|
|
Close()
|
|
}
|
|
|
|
// Config contains provider-owned options. The core does not interpret option
|
|
// names or values; it only passes core.memory.multimodal_space.options.*
|
|
// through after stripping the prefix.
|
|
type Config struct {
|
|
Options map[string]string
|
|
}
|
|
|
|
// Factory constructs a provider instance.
|
|
type Factory func(Config) (Provider, error)
|
|
|
|
var (
|
|
// ErrUnsupportedModality means this vector space has no native encoder for
|
|
// the requested modality. Callers must not substitute another model's vector.
|
|
ErrUnsupportedModality = errors.New("embedding: unsupported modality")
|
|
|
|
registryMu sync.RWMutex
|
|
registry = make(map[string]Factory)
|
|
)
|
|
|
|
// Register makes a provider factory available under name. It is normally
|
|
// called from a provider package's init function. Duplicate names panic so a
|
|
// build cannot silently select whichever package initialized last.
|
|
func Register(name string, factory Factory) {
|
|
name = strings.TrimSpace(name)
|
|
if name == "" {
|
|
panic("embedding: register empty provider name")
|
|
}
|
|
if factory == nil {
|
|
panic("embedding: register nil factory for " + name)
|
|
}
|
|
registryMu.Lock()
|
|
defer registryMu.Unlock()
|
|
if _, exists := registry[name]; exists {
|
|
panic("embedding: provider already registered: " + name)
|
|
}
|
|
registry[name] = factory
|
|
}
|
|
|
|
// Open constructs a registered provider and validates its vector-space identity.
|
|
func Open(name string, cfg Config) (Provider, error) {
|
|
name = strings.TrimSpace(name)
|
|
registryMu.RLock()
|
|
factory := registry[name]
|
|
registryMu.RUnlock()
|
|
if factory == nil {
|
|
return nil, fmt.Errorf("embedding: unknown provider %q (available: %s)", name, strings.Join(Names(), ", "))
|
|
}
|
|
provider, err := factory(cloneConfig(cfg))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("embedding: open provider %q: %w", name, err)
|
|
}
|
|
if provider == nil {
|
|
return nil, fmt.Errorf("embedding: provider %q returned nil", name)
|
|
}
|
|
if err := ValidateInfo(provider.Info()); err != nil {
|
|
provider.Close()
|
|
return nil, fmt.Errorf("embedding: provider %q: %w", name, err)
|
|
}
|
|
return provider, nil
|
|
}
|
|
|
|
// Names returns registered provider names in deterministic order.
|
|
func Names() []string {
|
|
registryMu.RLock()
|
|
defer registryMu.RUnlock()
|
|
names := make([]string, 0, len(registry))
|
|
for name := range registry {
|
|
names = append(names, name)
|
|
}
|
|
sort.Strings(names)
|
|
return names
|
|
}
|
|
|
|
// ValidateInfo checks the stable identity required by vector persistence.
|
|
func ValidateInfo(info Info) error {
|
|
if info.Dimension <= 0 {
|
|
return fmt.Errorf("invalid dimension %d", info.Dimension)
|
|
}
|
|
if strings.TrimSpace(info.Fingerprint) == "" {
|
|
return errors.New("empty fingerprint")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateVector rejects malformed provider output before it reaches storage.
|
|
func ValidateVector(vec []float64, dimension int) error {
|
|
if len(vec) != dimension {
|
|
return fmt.Errorf("embedding: vector dimension %d, want %d", len(vec), dimension)
|
|
}
|
|
for i, value := range vec {
|
|
if math.IsNaN(value) || math.IsInf(value, 0) {
|
|
return fmt.Errorf("embedding: vector value %d is not finite", i)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func cloneConfig(cfg Config) Config {
|
|
out := Config{Options: make(map[string]string, len(cfg.Options))}
|
|
for key, value := range cfg.Options {
|
|
out.Options[key] = value
|
|
}
|
|
return out
|
|
}
|