Using gpt-4 API to Semantically Chunk Documents

Here is modified process flow:

So now:

  1. export the pdf (or whatever) document to txt.
  2. run code to prepend linenoxxxx:
  3. send this numbered file to model along with instructions to create hierarchy json file
  4. process this file with code to add end_line numbers and output that json file.
    new: also add token_count to the json file
  5. run code on json output to create the chunks.

I am programmatically adding the token_count for each chunk. * This will make the prompt more efficient, and reduce token output on API call. Also, because it’s being done programmatically, the token count will be accurate!

It is amazing to me that large language models seem to be able to do everything EXCEPT count characters, words, lines or even tokens from the text they “read” and “analyze”. Maybe GPT-5 will overcome these limitations.

Otherwise, Rumors of the Demise of Software Engineers are highly exaggerated. I’m talking to you Nvidia CEO and Devin.