Commit f93f483
fix: shrink oversized embedding input instead of dropping the document
`createEmbeddingOrEmpty` logs a failed embedding as "transient/non-fatal" and
moves on. For a rate limit that is right. For an over-length input it is not:
the input is deterministic, so the same document fails on every rebuild, and
the index keeps a permanent hole that looks like a passing run.
Observed on a 567-table MySQL connection during a full reindex:
Skipping embedding for RELATIONSHIP document b7efe9d2-... due to
transient/non-fatal error: 400: Invalid 'input': maximum context length
is 8192 tokens.
The cause is the character budget, not a missing one. `truncate` already cut
input to `app.embedding.max-chars` (default 30,000) on the stated assumption of
"roughly 4 chars per token", which would be 7,500 tokens. That ratio holds for
prose. It does not hold for what this service embeds: schema and relationship
documents are dense identifiers, underscores, punctuation and repeated
scaffolding, which tokenize closer to 2-3 chars per token. At that density
30,000 chars is 10,000-15,000 tokens and the provider rejects the call.
No fixed ratio is safe across content, so this stops betting on one.
`LlmErrorCategory.CONTEXT_LENGTH` already documents itself as "never retry; the
caller may trim" — until now nothing trimmed. `embedWithShrink` halves the
budget on each CONTEXT_LENGTH rejection (30,000 -> 15,000 -> ... -> 1,875,
floor 1,000) and lets the provider decide when the call fits. That needs no
tokenizer dependency and stays correct for any content and any model window.
Deliberately narrow:
- Only CONTEXT_LENGTH shrinks. Retries and fail-open are untouched for every
other category, since a smaller input answers nothing about a rate limit or
a rejected credential.
- The inner attempt runs with fail-open off so the rejection reaches the shrink
loop; fail-open would convert it into an empty vector indistinguishable from
a real one. The operator's fail-open setting is still honoured once shrinking
is exhausted.
- Shrinking a batch only affects members longer than the budget, so one
oversized text costs the short ones nothing.
- Bounded at 4 halvings, so a pathological document cannot loop.
Tests cover all three paths: shrink-then-succeed, exhaust-then-fail-open, and
no-shrink for a category shrinking cannot fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 4366ef0 commit f93f483
2 files changed
Lines changed: 141 additions & 8 deletions
File tree
- backend/src
- main/java/com/dbaagent/service
- test/java/com/dbaagent/service
Lines changed: 72 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
93 | 111 | | |
94 | 112 | | |
95 | 113 | | |
| |||
98 | 116 | | |
99 | 117 | | |
100 | 118 | | |
101 | | - | |
102 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
103 | 165 | | |
104 | 166 | | |
105 | 167 | | |
| |||
110 | 172 | | |
111 | 173 | | |
112 | 174 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
116 | 180 | | |
117 | 181 | | |
118 | 182 | | |
| |||
Lines changed: 69 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
479 | 548 | | |
0 commit comments