LocalAI/core/schema
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
..
agent_jobs.go feat(agent-jobs): add multimedia support (#7398) 2025-11-30 14:09:25 +01:00
anthropic.go chore: re-enable e2e tests, fixups anthropic API tools support (#8296) 2026-01-30 12:41:50 +01:00
anthropic_test.go chore: re-enable e2e tests, fixups anthropic API tools support (#8296) 2026-01-30 12:41:50 +01:00
backend.go feat: Add backend gallery (#5607) 2025-06-15 14:56:52 +02:00
elevenlabs.go feat(musicgen): add ace-step and UI interface (#8396) 2026-02-05 12:04:53 +01:00
finetune.go feat: add (experimental) fine-tuning support with TRL (#9088) 2026-03-21 02:08:02 +01:00
gallery-model.schema.json [gallery] add JSON schema for gallery model specification (#7890) 2026-01-06 22:10:43 +01:00
jina.go fix(reranker): tests and top_n check fix #7212 (#7284) 2025-11-16 17:53:23 +01:00
localai.go feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
message.go feat(ui): MCP Apps, mcp streaming and client-side support (#8947) 2026-03-11 07:30:49 +01:00
message_test.go feat(llama.cpp): consolidate options and respect tokenizer template when enabled (#7120) 2025-11-07 21:23:50 +01:00
openai.go fix: implement encoding_format=base64 for embeddings endpoint (#9135) 2026-03-25 17:38:07 +01:00
openresponses.go fix(openresponses): do not omit required field ORItemParam.Arguments (#9074) 2026-03-19 22:04:45 +01:00
prediction.go fix: implement encoding_format=base64 for embeddings endpoint (#9135) 2026-03-25 17:38:07 +01:00
quantization.go feat(quantization): add quantization backend (#9096) 2026-03-22 00:56:34 +01:00
request.go feat: import models via URI (#7245) 2025-11-12 20:48:56 +01:00
schema_suite_test.go feat(llama.cpp): consolidate options and respect tokenizer template when enabled (#7120) 2025-11-07 21:23:50 +01:00
tokenize.go feat: Centralized Request Processing middleware (#3847) 2025-02-10 12:06:16 +01:00
transcription.go feat(whisperx): add whisperx backend for transcription with speaker diarization (#8299) 2026-02-02 16:33:12 +01:00