mirror of
https://github.com/ForLoopCodes/contextplus.git
synced 2026-04-26 06:25:50 +03:00
[PR #14] [MERGED] Fix: pre-truncate oversized embedding input to prevent SDK hang #16
Labels
No labels
bug
bug
documentation
enhancement
enhancement
good first issue
good first issue
help wanted
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/contextplus#16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ForLoopCodes/contextplus/pull/14
Author: @dearcodes
Created: 3/4/2026
Status: ✅ Merged
Merged: 3/5/2026
Merged by: @ForLoopCodes
Base:
main← Head:fix/pre-truncate-oversized-embed-input📝 Commits (1)
60acdbaFix: pre-truncate oversized embedding input to prevent Ollama SDK hang📊 Changes
1 file changed (+3 additions, -1 deletions)
View changed files
📝
src/core/embeddings.ts(+3 -1)📄 Description
Problem
The Ollama JS SDK hangs indefinitely (promise never resolves or rejects) when embedding input exceeds the model's context window (e.g.
nomic-embed-textat 8192 tokens).This means
embedSingleAdaptive's retry logic never fires — no error is thrown, soisContextLengthErroris never checked. The result issemantic_code_searchfailing with "Unable to embed oversized input after adaptive retries" for any project with large files.Root Cause
Ollama server returns HTTP 400 with
"the input length exceeds the context length", but the JS SDK (ollama@^0.6.3) doesn't surface this as a rejected promise — it hangs.Reproduction
Any project containing large generated or auto-generated files (codegen output, type declarations, migration snapshots, etc.) triggers this. The text assembled at
SearchIndex.index()(header + symbols + content) for these files far exceeds the model's context window.Fix
Pre-truncate input text to 8000 chars before calling
ollama.embed(). This is conservative fornomic-embed-text's 8192 token context. Truncation at index time preserves file headers and symbol names (most semantically relevant) while trimming excess file content.Verification
Tested locally against a monorepo with generated files up to 2MB. Before fix: hangs/errors. After fix: indexes and searches correctly.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.