Summary
When you add a branch to the process that builds chunks for search, you need to apply the chunk length limit to that branch as well, with the same function as the other paths, check the length of every chunk, and stop processing if any chunk exceeds the limit. In a service developed at my own company, only the exception path, which makes the whole text of a long public document into one chunk when no conclusion section is found in it, did not go through the function that applies the limit. The conclusion section is the part where the issuing institution itself wrote its conclusion and reasons, and only this part is used for vector search.
Before the fix, of the 1,172 documents that went through the exception path, 691 had a whole-text chunk over the limit. The embedding API returned no errors, and the number of missing embeddings was recorded as 0. The AI agent assumed that the portion over the input limit had been truncated, and estimated that 39% of the body text sent through the exception path was not reflected in the vectors.
This estimate is based on the documents counted as exceeding the input limit by converting character counts into token counts. The service’s records do not count tokens document by document. The official documentation did not state explicitly whether the embedding API truncates text input.
What you can take away
This article is based on the code, commit messages, and design documents of a service developed at my own company, and the memory written by the AI agent. Developers who add branches to a process that builds chunks for vector search will find four things here.
- You learn how to apply the limit to the exception path as well with the same function, check the length of every chunk, and stop processing.
- You learn how far the 90th percentile and the maximum exceeded the limit when the length of the exception chunks was reported only as a median.
- You learn about a case in which an embedding request over the input limit returned no error, and how far the truncation behavior could be confirmed in the official documentation.
- You learn the three causes of the dropped text, and the procedure the AI agent wrote in its memory for each cause.
The rest of this article is paid
You can read the rest by buying this article on its own, or with a subscription that covers every paid article.
The paid part is about 12,200 characters, roughly a 24-minute read.
Read just this article
From 300 JPY
Buy this article on its own. The exact price is shown at checkout. Purchased articles stay readable whenever you sign in with the email used at purchase.
Read every paid article
Standard is 490 JPY / month
Four new paid articles ship every month. For yearly billing and the full comparison, see the plans.
Add dialogue and columns
Premium is 980 JPY / month
Premium adds the subscriber-only columns and dialogue with matsumotory-kun on top of every paid article. See the plans for details.
Prices include tax. Purchases and subscriptions start after you sign in. Subscribers and readers who already bought this article can sign in and read the full article; for the plans, see the plans page.
Sales are available in supported regions only; the Terms list where we sell. All charges are in Japanese yen.