vmcp optimizer: OpenAI embeddings batch size hardcoded at 2048 — large MCP catalogs send whole-catalog embed requests

Aperta Adatta ai principianti
#7,295 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go, kubernetes
Ambito
backend

Direzione di ricerca

Inizia in pkg/vmcp/optimizer/internal/similarity/openai_client.go, dove openAIMaxBatchSize è fissato a 2048 e la richiesta di embed viene inviata in un'unica chiamata. Segui come gli input vengono passati alla richiesta di embeddings e dove viene usata la dimensione del batch. Il lavoro è completato quando le richieste di embeddings vengono suddivise in blocchi di dimensione configurabile, con un valore predefinito piccolo, e un test dimostra che un grande elenco di input produce più richieste.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-triage

Bug description

pkg/vmcp/optimizer/internal/similarity/openai_client.go hardcodes openAIMaxBatchSize = 2048, so the session optimizer embeds an entire aggregated MCP catalog in a single /v1/embeddings request. Against a self-hosted OpenAI-compatible embedding backend, one request with hundreds of inputs can exhaust the server, and the optimizer failure then kills session creation on the gateway entirely — tools/list stops working for every client.

Steps to reproduce

  1. Run a gateway (VirtualMCPServer) aggregating MCP servers whose combined catalog is large (ours: 10 servers → 521 tools, ~530 KB of tool name/description/schema text), with optimizer.embeddingProvider: openai pointed at a self-hosted backend (litellm → OpenVINO Model Server, Qwen3-Embedding-0.6B-int8-ov on an Intel NPU).
  2. Create a session against the gateway.
  3. The optimizer sends one embed request with 521 input strings.

Observed on the backend: 521 inputs in one request requires ~8.7 GB of transient host memory (per-input hidden states are accumulated before pooling), which exceeds what the box can give a single request; the request fails and the gateway logs failed to list core tools for session for every session (~every 5 min), so no session can be created at all.

Bisected against the backend: 64 inputs/request → OK; 128 inputs/request → fails. Empty input strings are handled fine; the failure is batch-size driven.

Expected behavior

Session creation succeeds. The optimizer should chunk its embedding requests to a size that self-hosted backends can serve, ideally configurable.

Actual behavior

Every session creation fails; the gateway is unusable for any client while the catalog is large, because the embed request is all-or-nothing (one 521-input request, no chunking below the 2048 cap).

Environment (if relevant)

  • OS/version: Talos Linux 1.14.7, Kubernetes 1.34
  • ToolHive version: ghcr.io/stacklok/toolhive/vmcp:v0.69.0 (deployed via toolhive-operator, VirtualMCPServer CRD with optimizer.embeddingProvider: openai)
  • Backend: litellm → OVMS 2026.4.1, Qwen3-Embedding-0.6B-int8-ov, Intel NPU ( Panther Lake, UMA 64 GB)

Additional context

The OpenAI API's 2048-input cap is a hosted-API rate/abuse limit, not a good default for self-hosted backends where per-request input count drives server memory.

Request: make the optimizer's embed batch size configurable in OptimizerConfig / spec.optimizer (e.g. embeddingBatchSize, defaulting small — 32–64). Adaptive chunking on 4xx/5xx would also work, but an explicit knob is simpler and predictable.

Lingua principale
Go
Stelle
2.3k
Fork
335
Merge medio
18h 4m
PR unite (30g)
194

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stacklok/toolhive

Tutte le issue di stacklok/toolhive

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.