Only the branch that turned the whole text into a single chunk had no length limit on search chunks

日本語

Contents of this article

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.