Skip to content

Fixes #4930: cap Titan Bedrock embedding input to avoid ValidationException - #29920

Merged
mohityadav766 merged 5 commits into
mainfrom
salem
Jul 13, 2026
Merged

mohityadav766 merged 5 commits into
mainfrom
salem

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #4930

Amazon Titan Bedrock embedding models accept at most 8192 input tokens and — unlike Cohere — expose no request-side truncate directive, so oversized chunks were rejected by Bedrock with a ValidationException (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-limit ValidationException is 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 typed ValidationException plus a named message marker, so throttling/auth/other validation errors are never retried; halveInput is empty-safe and never splits a surrogate pair.

Type of change:

  • Bug fix

High-level design:

N/A — small change, single class. Follow-up worth filing: the oversized input is produced upstream in the shared VectorDocBuilder/TextChunkManager, and OpenAIEmbeddingClient/GoogleEmbeddingClient have no input bound either — a maxInputChars() hook on the base EmbeddingClient (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

  • A search reindex with a Titan Bedrock model and a document exceeding the token limit gets a (truncated) embedding instead of throwing ValidationException.
  • Token-dense (CJK/emoji) documents that slip past the char cap trigger a halved-input retry that converges instead of resending identical payloads.
  • Non-token / throttling errors surface immediately without wasteful retries.

Unit tests

  • Added unit tests in 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

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to a GitHub issue via Fixes #4930 above.
  • I have added a test that covers the exact scenario we are fixing.

Greptile Summary

This PR bounds Bedrock embedding inputs to avoid Titan token-limit failures. The main changes are:

  • Adds family-specific input caps for Titan and Cohere requests.
  • Retries Titan token-limit validation failures with progressively shorter input.
  • Keeps non-token Bedrock errors on the existing failure path.
  • Adds unit tests for truncation, retry behavior, and surrogate-safe halving.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java Adds Titan input capping and retry logic that shrinks the capped request text after token-limit validation failures.
openmetadata-service/src/test/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClientTest.java Adds focused unit tests for Titan caps, halving behavior, retry success, non-token validation errors, and retry exhaustion.

Reviews (5): Last reviewed commit: "Merge branch 'main' into salem" | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - openmetadata-ui-core-components/CLAUDE.md (source)
  • Context used - AGENTS.md (source)

…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>
Copilot AI review requested due to automatic review settings July 10, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jul 10, 2026
…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>
Copilot AI review requested due to automatic review settings July 10, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…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>
Copilot AI review requested due to automatic review settings July 10, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 2 resolved / 4 findings

Adds Titan Bedrock embedding truncation and retry logic to resolve ValidationExceptions for oversized inputs, but the retry logic currently incorrectly references the original uncapped input rather than the truncated payload.

⚠️ Bug: Token-overflow retry halves uncapped input, resending same capped payload

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:209-223 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:247-261 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:144-150

invokeEmbedding keeps input as the full, uncapped text, but the payload actually sent to Bedrock is capped to TITAN_MAX_INPUT_CHARS (16384) inside buildRequest/capToLimit (lines 82, 95, 144-150). On a token-overflow ValidationException, shrinkOnTokenOverflow halves this uncapped input (line 253), not the capped payload that was actually rejected.

For an input much larger than the cap this makes the retries ineffective: e.g. a 100000-char CJK document is capped to 16384 and rejected; the retry halves 100000→50000, which is still capped back to 16384 — the byte-for-byte identical payload — and rejected again; 50000→25000 also caps to 16384. With MAX_TOKEN_LIMIT_RETRIES = 3, the first ~2 retries resend the exact rejected 16384-char payload before the shrink finally drops below the cap. The retry budget is largely wasted, and truly dense inputs still fail after exhausting retries.

The comment at lines 57-59 ("The char cap already bounds input to TITAN_MAX_INPUT_CHARS, so halving converges in at most ~2 retries") is based on this incorrect assumption — halving does not start from the capped length.

Fix: shrink relative to the effective (capped) length so each retry actually sends a smaller payload.

Cap input once before the retry loop (make capToLimit package-visible) so halveInput shrinks the actually-sent length.
private float[] invokeEmbedding(String text, boolean isQuery) {
  // Start from the effective (capped) input so retries shrink the payload that is actually sent.
  String input = BedrockEmbeddingFamily.capToLimit(text, family.maxInputChars());
  float[] embedding = null;
  int attempt = 0;
  while (embedding == null) {
    try {
      embedding = invokeOnce(input, isQuery);
    } catch (AwsServiceException e) {
      input = shrinkOnTokenOverflow(input, e, attempt++);
    } catch (SdkClientException e) {
💡 Quality: Stray informal 'ponytail:' comment without ticket reference

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:51

In BedrockEmbeddingClient.java:51 the comment // ponytail: char/token ratio is empirical — lower this knob if a denser corpus still overflows. reads like a leftover personal/codename note rather than documentation. Per the project's comment conventions, notes about future adjustment knobs should either be dropped (self-documenting constant) or, if actionable, converted into a TODO referencing a ticket number. As written it is unclear to other readers what ponytail refers to. Suggest removing it or rewording into a clear rationale line consistent with the surrounding comment block.

Reword the informal note into a clear rationale comment.
// The char/token ratio is empirical; lower TITAN_MAX_INPUT_CHARS if a denser corpus still overflows.
private static final int TITAN_MAX_INPUT_CHARS = 16384;
✅ 2 resolved
✅ Edge Case: Char-based Titan cap can still overflow 8192 tokens for dense text

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:47-52 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:70 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:83
The fix caps Titan input at TITAN_MAX_INPUT_CHARS = 16384 on the assumption of ~2 chars/token worst case (BedrockEmbeddingClient.java:47-52,74,87). That heuristic holds for typical Latin text, but for token-dense scripts (e.g., CJK, where a single character can map to one or more tokens) 16384 characters can exceed Titan's 8192-token limit, so the original ValidationException (#4930) could still occur for such documents. The comment acknowledges the ratio is empirical, but the failure mode is the same silent 'document gets no embedding' the PR aims to eliminate. Consider a more conservative cap for the worst case, or catching the ValidationException and retrying with a shorter input, so dense corpora degrade gracefully rather than failing.

✅ Bug: Token-overflow retry uses full input length, not the char-capped payload

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:215-229 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:254-268 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:150-156 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:84-98
invokeOnce sends capToLimit(text, maxInputChars()) (≤ TITAN_MAX_INPUT_CHARS = 16384 chars) to Bedrock, so the request input token count reported in the ValidationException reflects the capped payload — never the full text. But the retry path keeps the loop variable input at the untruncated length: shrinkOnTokenOverflow → truncateForTokenLimit(input, message) → targetCharsFromMessage(input.length(), message) scales input.length() by maxTokens/requestTokens, where requestTokens describes only the first 16384 chars.

When the raw document is longer than 16384 chars (the primary oversized-document scenario this PR targets), the ratio is applied to the wrong base, so the computed target stays well above 16384. capToLimit then re-cuts the retry to the same 16384 chars and Bedrock throws the identical overflow. Each pass just decrements the retry budget; for a token-dense (CJK) document the loop can exhaust MAX_TOKEN_LIMIT_RETRIES and rethrow — the exact ValidationException the fix is meant to prevent.

Example: 100000-char CJK input, maxTokens=8192, capped request ≈16384 tokens. target = 100000·(8192/16384)·0.9 = 45000 → still capped to 16384 → same error; subsequent retries (20250, 9112) may or may not converge before the budget is spent.

The truncation should be computed against the number of chars actually sent, i.e. min(input.length(), family.maxInputChars()). Note the unit test truncatesPreciselyFromReportedTokenCounts uses input length 18338 == requestTokens 18338, a combination that cannot occur in production once capToLimit runs, so it does not exercise this mismatch.

🤖 Prompt for agents
Code Review: Adds Titan Bedrock embedding truncation and retry logic to resolve ValidationExceptions for oversized inputs, but the retry logic currently incorrectly references the original uncapped input rather than the truncated payload.

1. 💡 Quality: Stray informal 'ponytail:' comment without ticket reference
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:51

   In `BedrockEmbeddingClient.java:51` the comment `// ponytail: char/token ratio is empirical — lower this knob if a denser corpus still overflows.` reads like a leftover personal/codename note rather than documentation. Per the project's comment conventions, notes about future adjustment knobs should either be dropped (self-documenting constant) or, if actionable, converted into a TODO referencing a ticket number. As written it is unclear to other readers what `ponytail` refers to. Suggest removing it or rewording into a clear rationale line consistent with the surrounding comment block.

   Fix (Reword the informal note into a clear rationale comment.):
   // The char/token ratio is empirical; lower TITAN_MAX_INPUT_CHARS if a denser corpus still overflows.
   private static final int TITAN_MAX_INPUT_CHARS = 16384;

2. ⚠️ Bug: Token-overflow retry halves uncapped input, resending same capped payload
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:209-223, openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:247-261, openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:144-150

   `invokeEmbedding` keeps `input` as the full, uncapped text, but the payload actually sent to Bedrock is capped to `TITAN_MAX_INPUT_CHARS` (16384) inside `buildRequest`/`capToLimit` (lines 82, 95, 144-150). On a token-overflow `ValidationException`, `shrinkOnTokenOverflow` halves this *uncapped* `input` (line 253), not the capped payload that was actually rejected.
   
   For an input much larger than the cap this makes the retries ineffective: e.g. a 100000-char CJK document is capped to 16384 and rejected; the retry halves 100000→50000, which is still capped back to 16384 — the byte-for-byte identical payload — and rejected again; 50000→25000 also caps to 16384. With `MAX_TOKEN_LIMIT_RETRIES = 3`, the first ~2 retries resend the exact rejected 16384-char payload before the shrink finally drops below the cap. The retry budget is largely wasted, and truly dense inputs still fail after exhausting retries.
   
   The comment at lines 57-59 ("The char cap already bounds input to TITAN_MAX_INPUT_CHARS, so halving converges in at most ~2 retries") is based on this incorrect assumption — halving does not start from the capped length.
   
   Fix: shrink relative to the *effective* (capped) length so each retry actually sends a smaller payload.

   Fix (Cap input once before the retry loop (make capToLimit package-visible) so halveInput shrinks the actually-sent length.):
   private float[] invokeEmbedding(String text, boolean isQuery) {
     // Start from the effective (capped) input so retries shrink the payload that is actually sent.
     String input = BedrockEmbeddingFamily.capToLimit(text, family.maxInputChars());
     float[] embedding = null;
     int attempt = 0;
     while (embedding == null) {
       try {
         embedding = invokeOnce(input, isQuery);
       } catch (AwsServiceException e) {
         input = shrinkOnTokenOverflow(input, e, attempt++);
       } catch (SdkClientException e) {

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

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>
Copilot AI review requested due to automatic review settings July 10, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (20 flaky)

✅ 4517 passed · ❌ 0 failed · 🟡 20 flaky · ⏭️ 95 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 424 0 3 16
✅ Shard 2 11 0 0 0
🟡 Shard 3 822 0 6 8
✅ Shard 4 820 0 0 18
🟡 Shard 5 828 0 1 5
🟡 Shard 6 832 0 1 46
🟡 Shard 7 780 0 9 2
🟡 20 flaky test(s) (passed on retry)
  • Flow/TestConnectionModal.spec.ts › failure state shows Edit Connection button and Retry Test button (shard 1, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab IS visible for supported type: metric (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › the browse tree only shows the asset-type categories a user can access (shard 1, 1 retry)
  • Features/BulkImportWithDotInName.spec.ts › Bulk edit existing entity with dot in service name (shard 3, 1 retry)
  • Features/ContextCenterArchivePage.spec.ts › archive page lazy-loads more rows on scroll within its own scroll container (shard 3, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Article listing search filters, clears, and shows empty state (shard 3, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Article list cards, recently viewed widget, and pagination work (shard 3, 1 retry)
  • Features/ContextCenterMemories.spec.ts › clicking a memory row adds ?memory= param to the URL (shard 3, 1 retry)
  • Features/DataQuality/TestCaseImportExportBasic.spec.ts › should show validation errors for invalid CSV (shard 3, 1 retry)
  • Flow/PersonaFlow.spec.ts › Set default persona for team should work properly (shard 5, 1 retry)
  • Pages/ExploreBrowse.spec.ts › service type drill-down disables unrelated roots and query-panel Clear resets it (shard 6, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should allow Data Steward to edit tags for searchIndex (shard 7, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Glossary Bulk Import Export (shard 7, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Import partial success - some terms pass, some fail (shard 7, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify Impact Analysis service filter selection (shard 7, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab is NOT visible for pipelineService in platform lineage (shard 7, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab is NOT visible for apiService in platform lineage (shard 7, 1 retry)
  • Pages/ServiceEntity.spec.ts › Announcement create, edit & delete (shard 7, 1 retry)
  • Pages/TestSuite.spec.ts › Logical TestSuite (shard 7, 1 retry)
  • Pages/UserDetails.spec.ts › Admin user can get all the roles hierarchy and edit roles (shard 7, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings July 13, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@mohityadav766
mohityadav766 merged commit 86909c4 into main Jul 13, 2026
67 of 73 checks passed
@mohityadav766
mohityadav766 deleted the salem branch July 13, 2026 11:02
@gitar-bot

gitar-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 resolved / 4 findings

Implements 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

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:47-52 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:70 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:83
The fix caps Titan input at TITAN_MAX_INPUT_CHARS = 16384 on the assumption of ~2 chars/token worst case (BedrockEmbeddingClient.java:47-52,74,87). That heuristic holds for typical Latin text, but for token-dense scripts (e.g., CJK, where a single character can map to one or more tokens) 16384 characters can exceed Titan's 8192-token limit, so the original ValidationException (#4930) could still occur for such documents. The comment acknowledges the ratio is empirical, but the failure mode is the same silent 'document gets no embedding' the PR aims to eliminate. Consider a more conservative cap for the worst case, or catching the ValidationException and retrying with a shorter input, so dense corpora degrade gracefully rather than failing.

✅ Bug: Token-overflow retry uses full input length, not the char-capped payload

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:215-229 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:254-268 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:150-156 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:84-98
invokeOnce sends capToLimit(text, maxInputChars()) (≤ TITAN_MAX_INPUT_CHARS = 16384 chars) to Bedrock, so the request input token count reported in the ValidationException reflects the capped payload — never the full text. But the retry path keeps the loop variable input at the untruncated length: shrinkOnTokenOverflow → truncateForTokenLimit(input, message) → targetCharsFromMessage(input.length(), message) scales input.length() by maxTokens/requestTokens, where requestTokens describes only the first 16384 chars.

When the raw document is longer than 16384 chars (the primary oversized-document scenario this PR targets), the ratio is applied to the wrong base, so the computed target stays well above 16384. capToLimit then re-cuts the retry to the same 16384 chars and Bedrock throws the identical overflow. Each pass just decrements the retry budget; for a token-dense (CJK) document the loop can exhaust MAX_TOKEN_LIMIT_RETRIES and rethrow — the exact ValidationException the fix is meant to prevent.

Example: 100000-char CJK input, maxTokens=8192, capped request ≈16384 tokens. target = 100000·(8192/16384)·0.9 = 45000 → still capped to 16384 → same error; subsequent retries (20250, 9112) may or may not converge before the budget is spent.

The truncation should be computed against the number of chars actually sent, i.e. min(input.length(), family.maxInputChars()). Note the unit test truncatesPreciselyFromReportedTokenCounts uses input length 18338 == requestTokens 18338, a combination that cannot occur in production once capToLimit runs, so it does not exercise this mismatch.

✅ Quality: Stray informal 'ponytail:' comment without ticket reference

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:51
In BedrockEmbeddingClient.java:51 the comment // ponytail: char/token ratio is empirical — lower this knob if a denser corpus still overflows. reads like a leftover personal/codename note rather than documentation. Per the project's comment conventions, notes about future adjustment knobs should either be dropped (self-documenting constant) or, if actionable, converted into a TODO referencing a ticket number. As written it is unclear to other readers what ponytail refers to. Suggest removing it or rewording into a clear rationale line consistent with the surrounding comment block.

✅ Bug: Token-overflow retry halves uncapped input, resending same capped payload

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:209-223 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:247-261 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/BedrockEmbeddingClient.java:144-150
invokeEmbedding keeps input as the full, uncapped text, but the payload actually sent to Bedrock is capped to TITAN_MAX_INPUT_CHARS (16384) inside buildRequest/capToLimit (lines 82, 95, 144-150). On a token-overflow ValidationException, shrinkOnTokenOverflow halves this uncapped input (line 253), not the capped payload that was actually rejected.

For an input much larger than the cap this makes the retries ineffective: e.g. a 100000-char CJK document is capped to 16384 and rejected; the retry halves 100000→50000, which is still capped back to 16384 — the byte-for-byte identical payload — and rejected again; 50000→25000 also caps to 16384. With MAX_TOKEN_LIMIT_RETRIES = 3, the first ~2 retries resend the exact rejected 16384-char payload before the shrink finally drops below the cap. The retry budget is largely wasted, and truly dense inputs still fail after exhausting retries.

The comment at lines 57-59 ("The char cap already bounds input to TITAN_MAX_INPUT_CHARS, so halving converges in at most ~2 retries") is based on this incorrect assumption — halving does not start from the capped length.

Fix: shrink relative to the effective (capped) length so each retry actually sends a smaller payload.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

mohityadav766 added a commit that referenced this pull request Jul 14, 2026
…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>

This branch was previously deployed

1 inactive deployment
test — 36cb6092 Deployed Jul 13, 2026 by mohityadav766 via playwright-ci-postgresql (1, 7) #56041
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants