Repository navigation
Fixes #4930: cap Titan Bedrock embedding input to avoid ValidationException - #29920
Conversation
…eption Titan text-embedding models accept at most 8192 input tokens and expose no request-side truncate directive, so oversized chunks were rejected by Bedrock with a ValidationException. The Cohere family already capped its input client-side; generalize that cap so Titan V1/V2 also truncate oversized input. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
…flow The 16384-char cap keeps typical English input to one call but can still be exceeded by token-dense scripts (CJK, emoji) where chars approx tokens. On a token-limit ValidationException, parse the reported max/actual token counts, truncate the input to fit, and retry — a content-agnostic guarantee the char cap alone cannot provide. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ounts Parsing the exact token counts out of AWS's error message is fragile and buys little: the char cap already bounds input, so halving converges in ~2 retries. Keep only the message-based detection (AWS gives no machine-readable code for token overflow) and drop the two regexes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Gitar
The retry halved the raw (uncapped) input while buildRequest re-capped every attempt, so any input >16384 chars resent byte-identical payloads and never converged (#4930 persisted for the token-dense case). Cap once up front so halving operates on what is actually sent, and: - detect token overflow via typed ValidationException + a named marker constant, so throttling/auth/other validation errors are never retried - make halveInput empty-safe and surrogate-pair-safe (emoji path) - split the retry decision into a plain requireRetryable guard (clearer loop) - reuse StringUtils.truncate for the char cap - cover the retry loop, classifier, and budget exhaustion with mock-based tests Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🟡 Playwright Results — all passed (20 flaky)✅ 4517 passed · ❌ 0 failed · 🟡 20 flaky · ⏭️ 95 skipped
🟡 20 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
|
Code Review ✅ Approved 4 resolved / 4 findingsImplements a proactive character-based cap and a reactive token-halving retry mechanism for Amazon Titan Bedrock embeddings, resolving ValidationExceptions caused by token overflows. All identified issues regarding retry logic precision and code comments have been addressed. ✅ 4 resolved✅ Edge Case: Char-based Titan cap can still overflow 8192 tokens for dense text
✅ Bug: Token-overflow retry uses full input length, not the char-capped payload
✅ Quality: Stray informal 'ponytail:' comment without ticket reference
✅ Bug: Token-overflow retry halves uncapped input, resending same capped payload
OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
…eption (#29920) (#30021) Backport of #29920 to 1.13. Titan text-embedding models accept at most 8192 input tokens and expose no request-side truncate directive, so oversized chunks were rejected by Bedrock with a ValidationException. Cap the input at 16384 chars up front, and on a token-limit ValidationException halve the (already capped) input and retry — a content-agnostic guarantee the char cap alone cannot provide for token-dense scripts (CJK, emoji). Adapted from the original: 1.13's BedrockEmbeddingClient predates the embedding-family refactor (Cohere support, doEmbedQuery, per-family request builders), so the fix is applied to the Titan-only shape that exists here. The family/Cohere portions of the upstream change and its tests are omitted. (cherry picked from commit 86909c4) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>



Describe your changes:
Fixes #4930
Amazon Titan Bedrock embedding models accept at most 8192 input tokens and — unlike Cohere — expose no request-side
truncatedirective, so oversized chunks were rejected by Bedrock with aValidationException(the document got no embedding, while the reindex job still reported 0 failed records). Two layers of defense: (1) a per-family char cap (generalized from the cap Cohere already had) truncates Titan input up front, keeping typical English text to a single call; (2) since a char cap can't guarantee the token limit for token-dense scripts (CJK, emoji, where chars ≈ tokens), a token-limitValidationExceptionis caught, the (already-capped) input is halved, and the call is retried until it fits — a content-agnostic backstop, bounded by a retry budget. Detection uses the typedValidationExceptionplus a named message marker, so throttling/auth/other validation errors are never retried;halveInputis empty-safe and never splits a surrogate pair.Type of change:
High-level design:
N/A — small change, single class. Follow-up worth filing: the oversized input is produced upstream in the shared
VectorDocBuilder/TextChunkManager, andOpenAIEmbeddingClient/GoogleEmbeddingClienthave no input bound either — amaxInputChars()hook on the baseEmbeddingClient(or a char bound in the chunker) would protect all providers. Kept out of this PR since #4930 is Bedrock-scoped.Tests:
Use cases covered
ValidationException.Unit tests
BedrockEmbeddingClientTest.java: char-cap truncation,halveInput(short/empty/surrogate-safe), and mock-based retry-loop coverage — token-limit error → halved retry → success, non-token error → immediate rethrow, persistent overflow → budget exhaustion. All 24 tests in the class pass.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes #4930above.Greptile Summary
This PR bounds Bedrock embedding inputs to avoid Titan token-limit failures. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (5): Last reviewed commit: "Merge branch 'main' into salem" | Re-trigger Greptile
Context used (3)