feat(embedder): configurable request timeout and max retries#257
Open
kryptt wants to merge 1 commit into
Open
Conversation
Two new optional EmbedderConfig fields:
request_timeout_seconds: HTTP client timeout per embedding request.
Defaults preserved (60s, except synthetic which keeps its 90s).
Useful when running against slow self-hosted endpoints where a
full batch can take longer than a minute, leading to spurious
"context deadline exceeded" errors mid-scan.
max_retries: caps RetryPolicy.MaxAttempts for transient (429/5xx)
failures. Default preserved at 5. Only honored by providers that
implement retry today (openai); other providers silently ignore.
Adds With…Timeout option to all five embedders and WithOpenAIMaxRetries
to the openai embedder. Factory threads both through. Tests cover the
override path and the default-preservation path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The HTTP client timeout (60s) and retry max-attempts (5) used by the embedders are compiled-in constants. They're well-tuned for OpenAI's hosted API but break down against slow self-hosted endpoints — a shared `ollama-cuda` instance handling other inference jobs can easily take > 60s to return a single batch's embeddings, especially under model warm-up or memory pressure.
Symptom I hit while building a large workspace through a self-hosted Ollama:
```
Warning: failed to initialize runtime for emacs-source: initial indexing failed:
failed to embed batches: failed to send request to OpenAI:
Post "https://ollama.hr-home.xyz/v1/embeddings\":
context deadline exceeded (Client.Timeout exceeded while awaiting headers)
```
The watcher abandons the whole project on the first batch that exceeds 60s, even though the underlying queue is still making forward progress on the server side. Larger projects (in my case ~47k chunks across emacs-source) become un-indexable end-to-end.
Solution
Two new optional fields on `EmbedderConfig`:
```yaml
embedder:
provider: openai
request_timeout_seconds: 600 # default: 0 = preserve historical 60s
max_retries: 8 # default: 0 = preserve historical 5
```
Both fields are zero-valued by default and *explicitly preserve existing behavior* in that case. A bare `embedder:` block produces the same embedder as before this PR.
Test plan
Two new tests in `embedder/factory_test.go`:
All existing tests continue to pass (`go test ./...`).