Repository navigation
Document the truncate option for models.embed() in 5.4 - #771
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the documentation for Harper v5.4.0 to introduce the new truncate: true option for models.embed(), which cuts long inputs to fit within an embedding model's context window instead of failing. The changes detail backend-specific behaviors (such as Ollama, Bedrock Cohere, and OpenAI/vLLM), routing requirements, and limitations. The review feedback suggests improving readability and adhering to documentation guidelines by splitting sentences that combine critical limitations or input refusal conditions with other concepts into separate, distinct sentences.
2c2a9a4 to
c12d12f
Compare
🚀 Preview DeploymentYour preview deployment is ready! 🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-771 This preview will update automatically when you push new commits. |
Covers EmbedOpts.truncate and the truncate capability, the OpenAI
truncation: vllm entry key, Ollama and Bedrock Cohere behavior,
defineBackend({ truncate }), routing, and a 5.4 release note.
Refs HarperFast/harper#3706
Dispatch-Task: docs-harper-3706
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xample model, note @embed has no truncate Dispatch-Task: docs-harper-3706 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: docs-harper-3706 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: docs-harper-3706 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c12d12f to
45a1533
Compare
🚀 Preview DeploymentYour preview deployment is ready! 🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-771 This preview will update automatically when you push new commits. |
🧹 Preview CleanupThe preview deployment for this PR has been removed. |
⊙ Problem
Let models.embed() cut each input at the model's context window with truncate: true adds a
truncateoption tomodels.embed()for v5.4, plus a newtruncatecapability, an OpenAItruncation: vllmconfig key and adefineBackendflag. None of it is documented.🤔 Is this the right scope?
Yes. Readers need the call contract, the per-backend behavior with and without the option, and which config enables it. The docs also say plainly that
@embedand/v1/embeddingscannot set it yet (HarperFast/harper#3705).💡 Solution
truncateoption row and a "Truncating long inputs" section (look hardest here). It covers the hard-requirement rule (incapable backends are skipped, else a capability error before any request), what absent/falsemeans per backend, a YAML + JS example, and the limits on@embed,/v1/embeddingsand stored vectors.truncation: vllmon OpenAI entries, Ollama's capability, Bedrock Cohere v3/v4 behavior, anddefineBackend({ truncate }).truncatein the capability list, and the auto-require rule.@embedcannot passtruncate; and the 5.4 release note.🤔 The example uses
BAAI/bge-m3, not NomicThe brief's example had
inputType: 'document'. On main, an OpenAI entry adds no task prefix, so a Nomic example would store unprefixed vectors. Once Document OpenAI embedding task prefixes for v5.4 lands, the example can switch to Nomic withinputPrefixes.✅ Verification
npm run buildpasses, with no broken links. All new anchors resolve in the built HTML.format:check,lintandtest:examplespass.92f279d1):types.ts,Models.ts,DESIGN.md, the three provider backends,configValidator.tsandbackendRegistry.ts.🤔 v5.4.0 badges assume the core PR merges before 5.4 is cut
Core has a
v5.3release branch (newest tagv5.3.4) and nov5.4branch, so coremainships as 5.4.0. If 5.4 is cut first, the badges need to change.Overlap with open docs PRs
embed()options table, the OpenAI field table, and adds## Modelsto the 5.4 notes.## Modelsto the 5.4 notes.Whichever merges second keeps both rows and one
## Modelsheading.Refs HarperFast/harper#3706
PR QA: skipped @ 45a1533 — docs-only repository
🤖 Generated by Claude Opus 5.5 (dev-agent); posted via @kriszyp.
🤖 Generated with Claude Code
Release target: v5.4 — documents a core feature shipping in 5.4.0
Related PRs: #748 overlaps, #727 overlaps
Complexity: easy
Origin — the dispatch brief this PR was written from
Document the truncate option for models.embed() and the OpenAI truncation: vllm setting
Document the new
truncateoption for embedding calls, added in HarperFast/harper PR HarperFast/harper#3706 (targets v5.4).What changed (read the PR for exact behavior;
resources/models/types.tsandresources/models/DESIGN.mdin that PR are the source of truth):models.embed(input, { truncate: true })cuts each input to what the embedding model accepts, keeping the START of the text (and any task prefix such assearch_document:), instead of failing when the input is longer than the model's context window.truncate: truerequires the newtruncatecapability. A backend that cannot truncate is skipped (fallback entries included); if none can, the call fails withModelCapabilityErrorbefore any request is sent. Callers can also list'truncate'inrequires.truncateabsent orfalsechanges nothing: the provider's own handling applies (OpenAI, vLLM and Bedrock Titan reject an over-long input; Ollama and Bedrock Cohere embed v3 cut by default).truncation: vllm(models.embedding.), for an endpoint served by vLLM 0.18 or later. With it, Harper sendstruncate_prompt_tokens: -1andtruncation_side: 'right'. Without it the backend does not advertise truncation and never sends those fields (api.openai.com rejects unknown fields). The value is the operator's declaration; Harper does not probe the endpoint.truncate: trueon/api/embed.truncate: RIGHT; Cohere embed v3 (english/multilingual, incl. light) sendstruncate: ENDafter cutting each text to Bedrock's 2,048-character per-text limit; Titan cannot truncate.defineBackend({ ..., truncate: true })lets a custom embedding backend declare the capability.Where: the models / embeddings API reference (EmbedOpts, capabilities,
requires), themodels:configuration reference for OpenAI entries (truncation), and the custom-backend (defineBackend) page. Add a short YAML + JS example (vLLM entry withtruncation: vllm, thenmodels.embed(text, { inputType: 'document', truncate: true })).Note for readers: enabling truncation does not re-embed records already stored. The
@embeddirective and the/v1/embeddingsgateway do not expose the option yet (tracked in HarperFast/harper#3705) — say so rather than documenting it there.Mark the docs for v5.4. Cross-link the harper PR in your docs PR description.
Dispatch: task
docs-harper-3706· queued by task:harper-embed-token-truncation · ran by claude/opus/high · worker kzyp-xps-1Deferred findings
5f60e96046a71ccanit documentation —reference/models/routing.md— Custom router docs silent on whether auto-added truncate appears in RouteRequest.requires — NOT FILEDa8025f71b0fa353enit documentation —reference/models/local-development.md— Parity caveats omit Ollama default truncation vs strict prod backends for @embed — NOT FILEDReview-Coverage: authored=gemini; ran=cursor-composer,codex,claude; adjudicated=domain; declined=cursor-grok,muse; rounds=6; full=2 @ 45a1533
Review-Attention: skim ~2m (decisions: truncate-auto-requires-capability, vllm-opt-in-flag, embed-directive-excluded) @ 45a1533