LocalAI/core/http/endpoints
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
..
anthropic feat: inferencing default, automatic tool parsing fallback and wire min_p (#9092) 2026-03-22 00:57:15 +01:00
elevenlabs feat(audio): set audio content type (#8416) 2026-02-05 19:14:12 +01:00
explorer feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
jina chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
localai feat(quantization): add quantization backend (#9096) 2026-03-22 00:56:34 +01:00
mcp feat(ui): MCP Apps, mcp streaming and client-side support (#8947) 2026-03-11 07:30:49 +01:00
openai fix: implement encoding_format=base64 for embeddings endpoint (#9135) 2026-03-25 17:38:07 +01:00
openresponses feat: inferencing default, automatic tool parsing fallback and wire min_p (#9092) 2026-03-22 00:57:15 +01:00