LocalAI/core
walcz-de 00fcf6936c
fix: implement encoding_format=base64 for embeddings endpoint (#9135)
The OpenAI Node.js SDK v4+ sends encoding_format=base64 by default.
LocalAI previously ignored this parameter and always returned a float
JSON array, causing a silent data corruption bug in any Node.js client
(AnythingLLM Desktop, LangChain.js, LlamaIndex.TS, …):

  // What the client does when it expects base64 but receives a float array:
  Buffer.from(floatArray, 'base64')

Node.js treats a non-string first argument as a byte array — each
float32 value is truncated to a single byte — and Float32Array then
reads those bytes as floats, yielding dims/4 values.  Vector databases
(Qdrant, pgvector, …) then create collections with the wrong dimension,
causing all similarity searches to fail silently.

  e.g. granite-embedding-107m (384 dims) → 96 stored in Qdrant
       jina-embeddings-v3      (1024 dims) → 256 stored in Qdrant

Changes:
- core/schema/prediction.go: add EncodingFormat string field to
  PredictionOptions so the request parameter is parsed and available
  throughout the request pipeline
- core/schema/openai.go: add EmbeddingBase64 string field to Item;
  add MarshalJSON so the "embedding" JSON key emits either []float32
  or a base64 string depending on which field is populated — all other
  Item consumers (image, video endpoints) are unaffected
- core/http/endpoints/openai/embeddings.go: add floatsToBase64()
  which packs a float32 slice as little-endian bytes and base64-encodes
  it; add embeddingItem() helper; both InputToken and InputStrings loops
  now honour encoding_format=base64

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 17:38:07 +01:00
..
application fix: Add tracing settings loading from runtime_settings.json (#9081) 2026-03-20 00:58:52 +01:00
backend feat: inferencing default, automatic tool parsing fallback and wire min_p (#9092) 2026-03-22 00:57:15 +01:00
cli feat(quantization): add quantization backend (#9096) 2026-03-22 00:56:34 +01:00
clients feat(store): add Golang client (#1977) 2024-04-16 15:54:14 +02:00
config feat: inferencing default, automatic tool parsing fallback and wire min_p (#9092) 2026-03-22 00:57:15 +01:00
dependencies_manager feat(ui): move to React for frontend (#8772) 2026-03-05 21:47:12 +01:00
explorer feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
gallery fix(download): do not remove dst dir until we try all fallbacks (#9100) 2026-03-22 10:29:57 +01:00
http fix: implement encoding_format=base64 for embeddings endpoint (#9135) 2026-03-25 17:38:07 +01:00
p2p feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
schema fix: implement encoding_format=base64 for embeddings endpoint (#9135) 2026-03-25 17:38:07 +01:00
services feat(quantization): add quantization backend (#9096) 2026-03-22 00:56:34 +01:00
startup feat(api): Add transcribe response format request parameter & adjust STT backends (#8318) 2026-02-01 17:33:17 +01:00
templates chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
trace feat(ui): Per model backend logs and various fixes (#9028) 2026-03-18 08:31:26 +01:00