Repository navigation
fix(vectorstore): stop retrying Ollama 4xx and size chunks to the server's num_ctx - #487
Merged
Merged
Conversation
…ver's num_ctx Ollama embedding runs stalled for 10–30 minutes per file on large vaults with the GPU idle (#485). Two causes: 1. A permanent HTTP 400 ("the input length exceeds the context length") was retried six times with exponential backoff. LangChain's default handler skips retries for 4xx, but reads the status from `status` / `statusCode` / `response.status`, while the Ollama client's `ResponseError` carries `status_code`. Measured: 7 requests, ~85 s per call — and the bulk indexer then repeats that per entry of the failed batch. `OllamaEmbeddings` now gets an `onFailedAttempt` that rethrows on 4xx (and cancellations), keeping the default budget for the rest. 2. Chunks were sized to the architecture context `/api/show` reports (40960 for qwen3-embedding) × 4 chars/token, but Ollama enforces min(num_ctx, model context) and its num_ctx default is a VRAM-chosen 4k+. Every long note overshot by 5×+. The embedding client now pins `num_ctx` to OLLAMA_EMBED_NUM_CTX (8192) and `hydrateEmbeddingModel` caps Ollama budgets to the same number, so client and server agree. `truncate: true` backstops dense content, and CHARS_PER_TOKEN drops 4 → 3 so JSON/code/non-Latin chunks stop overshooting in general. Fixes #485
Contributor
Greptile SummaryThis PR aligns Ollama embedding chunk budgets with the
Confidence Score: 5/5The PR appears safe to merge; no outstanding correctness, security, or repository-rule issues remain. The prior partial-index concern was manually resolved after the current failure tracking preserved chunk-0 as a completion marker, and the present code consistently aligns Ollama request limits, chunk sizing, retry behavior, and recovery semantics. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read Ollama model metadata] --> B[Cap input budget at 8192 tokens]
B --> C[Split note using conservative token estimate]
C --> D[Send embedding request with num_ctx 8192]
D --> E{Response}
E -->|Success| F[Write chunks with chunk 0 last]
E -->|4xx or cancellation| G[Stop retrying]
E -->|Transport failure or 5xx| H[Use retry budget]
G --> I[Mark note failed and suppress remaining chunks]
I --> J[Leave chunk 0 absent for later reindex]
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/ollama-embe..." | Re-trigger Greptile |
…ailed The bulk fallback kept embedding a note's remaining chunks after one failed, so chunk 0 — the 'note is indexed' marker written last — could still land and startup validation then read the partial note as complete. Drop the note's remaining chunks instead; without #0 the next validation pass re-indexes it whole.
Leo310
added a commit
that referenced
this pull request
Sep 14, 2026
Stability release for the Obsidian 1.13 installer (Electron 43 / Node 24): the renderer crash on the first chat send (#492) and the transport connection error (#501), plus the streaming render coalescing (#484), the checkpoint callbacks strip (#483), and the indexing fixes since 2.1.0 (#486, #487, #490, #491, #493, #495, #497, #498, #499, #500). Co-Authored-By: Claude <noreply@anthropic.com>
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.
Fixes #485.
What was wrong
Ollama embedding runs stalled 10–30 minutes per file with the GPU idle. Two independent causes:
status/statusCode/response.status. The Ollama client'sResponseErrorexposes it asstatus_code, so "the input length exceeds the context length" was treated as transient. Reproduced against a mock server that always answers 400: 7 requests, 84.5 s for one embed call. The bulk indexer's per-entry fallback then repeats that for every chunk in the failed batch, which is where the multi-minute stalls come from./api/show's architecture context (40960 tokens for qwen3-embedding) × 4 chars/token, but Ollama's server enforcesmin(num_ctx, model context), and itsnum_ctxdefault is VRAM-chosen (4k+) and not readable from the client. Every long note overshot by 5×.What changed
createTransportedOllamaEmbeddingsinstalls anonFailedAttemptthat rethrows on 4xxstatus_codeand on cancellation, leaving the default retry budget for transport failures and 5xx.num_ctxon embed requests toOLLAMA_EMBED_NUM_CTX(8192), andhydrateEmbeddingModelcaps Ollama input budgets to the same number, so client and server agree on the limit.truncate: trueon Ollama embeddings as a backstop: a truncated vector still finds the note by its opening, a rejected one drops it from the index.CHARS_PER_TOKEN4 → 3 so dense content (JSON, code, tables, non-Latin) stops overshooting in general. Affects chunk sizing only on (re)index; existing indexes are untouched.Tests
test/providers/ollamaEmbeddings.test.ts: handler rules, and an end-to-end mock-400 that asserts exactly one request (fails by timeout before the fix), plus the template'snum_ctx/truncatewiring.test/lib/modelMetadataNormalizer.test.ts: the Ollama cap, smaller contexts left alone, other providers uncapped.bun run check,format,lint,test(1682 passing) and a dev build are clean.