feat(embedding): data-driven dimension config with multi-provider support

- Add `dimensions` field to EmbeddingSettings for per-provider truncation
- Default to 1536 dims to match pgvector schema, preventing INSERT failures
- Replace hardcoded Gemini-only dimension truncation with data-driven config
- Fix verify endpoint to apply dimensions and return mismatch warning
- Expand curated embedding models: Gemini (gemini-embedding-001), Cohere
  (embed-v4), DashScope (text-embedding-v3), OpenAI (text-embedding-3-large)
- Add dimensions input to provider detail UI with i18n (en/vi/zh)
- Add anthropic_native to NoEmbeddingTypes (incompatible auth format)
- System settings verify always requests 1536d to match production behavior
This commit is contained in:
viettranx committed 2026-03-25 14:50:43 +07:00
1 parent fabec18606
commit 28a17c4d6b
13 files changed
+144 -47

No files matched your search

+8 -8
View File
@@ -123,8 +123,12 @@ func buildEmbeddingProvider(
apiBase = memCfg.EmbeddingAPIBase
}
// Gemini requires dimension truncation to match pgvector(1536) index.
needsDimTruncate := dbp.ProviderType == store.ProviderGeminiNative
// Dimension truncation: provider settings override, default to 1536 to match pgvector schema.
// Models that natively output 1536 ignore the parameter; models with larger native dims get truncated.
dims := 1536
if es != nil && es.Dimensions > 0 {
dims = es.Dimensions
}
// Try registry first for the actual API key / base (handles runtime-registered providers)
if providerReg != nil {
@@ -134,9 +138,7 @@ func buildEmbeddingProvider(
apiBase = op.APIBase()
}
ep := memory.NewOpenAIEmbeddingProvider(dbp.Name, op.APIKey(), apiBase, model)
if needsDimTruncate {
ep.WithDimensions(1536)
}
ep.WithDimensions(dims)
return ep
}
slog.Debug("embedding provider in registry is not OpenAI-compatible, using DB record", "name", dbp.Name)
@@ -146,9 +148,7 @@ func buildEmbeddingProvider(
// Fallback: build directly from DB record
if dbp.APIKey != "" {
ep := memory.NewOpenAIEmbeddingProvider(dbp.Name, dbp.APIKey, apiBase, model)
if needsDimTruncate {
ep.WithDimensions(1536)
}
ep.WithDimensions(dims)
return ep
}