fix(vector): New 在 embedder 维度未知(API 首请求前为0)时先 probe 一次学真实维度,避免 PG 向量索引 fallback
This commit is contained in:
1 parent
74f8eada47
commit
111ad598be
1 file changed
+9
@@ -98,6 +98,15 @@ func New(cfg config.DBConfig, embedder embedding.Embedder, log *slog.Logger) (In
|
||||
return nil, ErrNoEmbedder
|
||||
}
|
||||
dim := embedder.Dim()
|
||||
if dim <= 0 {
|
||||
// API-backed embedders do not know their vector dimension until the first
|
||||
// successful response. Probe once so the index is built with the real
|
||||
// dimension instead of erroring out and falling back to in-memory.
|
||||
if _, err := embedder.Embed(context.Background(), []string{"probe"}); err != nil {
|
||||
return nil, fmt.Errorf("memory/vector: probe embedder dim: %w", err)
|
||||
}
|
||||
dim = embedder.Dim()
|
||||
}
|
||||
if dim <= 0 {
|
||||
return nil, fmt.Errorf("memory/vector: %w (got %d)", ErrInvalidDim, dim)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user