feat(models): cap background embedding concurrency per model

Extend the per-model background concurrency governor to embedding, the
highest-volume background model call (document ingestion vectorises every
chunk, so a batch upload can burst the whole worker pool against one provider).

The wrapper sits innermost (below debug/langfuse) because BatchEmbedWithPool
fans a batch out into per-sub-batch BatchEmbed calls via the pooler, and the
pooler invokes BatchEmbed on whichever Embedder is threaded down as `model`;
sitting innermost routes those per-sub-batch provider round-trips through Gate
so the semaphore bounds real concurrent calls rather than one coarse per-doc
unit. Only background (asynq) calls are throttled; interactive query embedding
is never gated.
This commit is contained in:
wizardchen
2026-07-09 19:41:18 +08:00
committed by lyingbug
parent 98ad41cda4
commit 200c344065
3 changed files with 259 additions and 0 deletions
+4
View File
@@ -90,6 +90,10 @@ func NewEmbedder(config Config, pooler EmbedderPooler, ollamaService *ollama.Oll
if setter, ok := e.(interface{ SetSupportsDimensionOverride(bool) }); ok {
setter.SetSupportsDimensionOverride(config.SupportsDimensionOverride)
}
// Innermost: gate the real provider round-trips (including the per-sub-batch
// pool callbacks) before debug/langfuse wrap for logging/tracing. See
// concurrencyEmbedder for why this sits below the observability decorators.
e = wrapEmbeddingConcurrency(e)
if logger.LLMDebugEnabled() {
e = &debugEmbedder{inner: e}
}