Skip to content

feat(embedder): add configurable batch_size#274

Open
ibreakshit wants to merge 1 commit into
yoanbernabeu:mainfrom
ibreakshit:feat/configurable-embedding-batch-size
Open

feat(embedder): add configurable batch_size#274
ibreakshit wants to merge 1 commit into
yoanbernabeu:mainfrom
ibreakshit:feat/configurable-embedding-batch-size

Conversation

@ibreakshit

Copy link
Copy Markdown

Summary

Adds an optional embedder.batch_size config option that caps the number of inputs per embedding API request. Default is 2000 (unchanged).

Motivation

On slow or self-hosted OpenAI-compatible embedding endpoints, grepai's initial scan packs the entire batch (up to MaxBatchSize = 2000) into a single /v1/embeddings request. When the endpoint is slow, that one request exceeds the embedder's client timeout and the whole initial index fails:

initial indexing failed: failed to embed batches: failed to send request to OpenAI:
Post ".../v1/embeddings": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

There is currently no config-level way to work around this. Lowering batch_size keeps each request short so indexing completes reliably as more, smaller requests (slower overall, but it finishes). On throughput-bound endpoints it pairs well with parallelism: 1.

embedder:
  provider: openai
  endpoint: http://my-slow-gateway:4000/v1
  model: qwen3-embedding-8b
  parallelism: 1
  batch_size: 20

Changes

  • config: EmbedderConfig.BatchSize (yaml: batch_size)
  • embedder: additive FormBatchesWithSize(files, maxBatchSize); FormBatches now delegates to it with the MaxBatchSize default (no behavior change). Values <= 0 or > MaxBatchSize fall back to the default.
  • indexer: per-Indexer batchSize (defaults to MaxBatchSize) + SetBatchSize; the batched embed path uses FormBatchesWithSize.
  • cli/watch: applies cfg.Embedder.BatchSize to the indexer for both the single-project and workspace paths.
  • Tests (FormBatchesWithSize custom size, default fallback, FormBatches delegation) and docs.

Backward compatibility

Fully backward compatible. Unset / <= 0 / > MaxBatchSize all use the existing 2000 default; FormBatches behaves exactly as before. The MaxBatchTokens limit still applies.

Testing

go build ./cmd/grepai
go test ./embedder/... ./config/... ./indexer/...   # all pass
gofmt -l ...                                         # clean

🤖 Generated with Claude Code

Add an optional embedder.batch_size config option that caps the number of inputs per embedding API request (default 2000, unchanged). Slow or self-hosted embedding endpoints can time out on a single large request and fail the whole initial scan; lowering batch_size keeps each request short so indexing completes as more, smaller requests.

- config: EmbedderConfig.BatchSize (yaml: batch_size)
- embedder: additive FormBatchesWithSize; FormBatches delegates with the MaxBatchSize default (no behavior change); out-of-range values fall back to default
- indexer: per-Indexer batchSize (default MaxBatchSize) + SetBatchSize; batched embed path uses FormBatchesWithSize
- cli/watch: apply cfg.Embedder.BatchSize
- tests + docs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant