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

Abierto Apto para principiantes
#7,295 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go, kubernetes
Área
backend

Línea de trabajo

Empieza en pkg/vmcp/optimizer/internal/similarity/openai_client.go, donde openAIMaxBatchSize está fijado en 2048 y la solicitud de embed se envía en una sola llamada. Rastrea cómo se pasan las entradas a la solicitud de embeddings y dónde se usa el tamaño del lote. Se considera terminado cuando las solicitudes de embeddings se dividen en fragmentos de un tamaño configurable, con un valor predeterminado pequeño, y una prueba muestra que una lista de entradas grande produce varias solicitudes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
2.3k
Forks
335
Merge medio
18 h 4 min
PR fusionados (30 d)
194

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stacklok/toolhive

Todos los issues de stacklok/toolhive

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.