mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 17:38:10 +00:00
feat(vector): Vectorizer 接口加 EmbedImage,支持多模态嵌入扩展
Vectorizer 新增可选的 EmbedImage(img []byte, mime string) (Vector, error): 支持视觉嵌入的实现者(如 CLIP/MobileCLIP)覆写此方法;不支持的 (StaticEmbedder、TFIDFVectorizer)返回 ErrNotSupported 调用方按文本降级。 这是路线 3(完整跨模态检索)的接口基础:后续在 media.Store 里, Describe 时同时算视觉向量并存库,QueryMedia 做跨模态混合检索。
This commit is contained in:
@ -391,6 +391,13 @@ func (e *StaticEmbedder) Vectorize(text string) vector.Vector {
|
||||
return vec
|
||||
}
|
||||
|
||||
// EmbedImage 返回 ErrNotSupported:fastText 是纯文本词向量模型,
|
||||
// 没有视觉编码器。要用图像嵌入需要外部视觉模型(如 CLIP/MobileCLIP),
|
||||
// 那个由 config 里的 EmbeddingModelPath 指定的视觉模型负责。
|
||||
func (e *StaticEmbedder) EmbedImage(img []byte, mime string) (vector.Vector, error) {
|
||||
return nil, vector.ErrNotSupported
|
||||
}
|
||||
|
||||
func (e *StaticEmbedder) Dim() int {
|
||||
e.mu.RLock()
|
||||
defer e.mu.RUnlock()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package vector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
@ -8,10 +9,17 @@ import (
|
||||
)
|
||||
|
||||
// Vectorizer 接口:将文本转为向量
|
||||
//
|
||||
// 多模态嵌入新增可选的 EmbedImage:支持视觉嵌入的实现者覆写此方法,
|
||||
// 不支持的(TF-IDF 等)在默认实现里返回 ErrNotSupported。
|
||||
type Vectorizer interface {
|
||||
Vectorize(text string) Vector
|
||||
EmbedImage(img []byte, mime string) (Vector, error)
|
||||
}
|
||||
|
||||
// ErrNotSupported 表示 Vectorizer 不支持图像嵌入,调用方按文本描述降级。
|
||||
var ErrNotSupported = fmt.Errorf("vectorizer does not support image embedding")
|
||||
|
||||
// Vector 是带权特征映射:feature → weight
|
||||
type Vector map[string]float64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user