HeadlinesBriefing favicon HeadlinesBriefing.com

Hierarchical Retrieval for Long Documents

Towards Data Science •
×

A new approach to retrieving information from lengthy documents, particularly those with extensive tables of contents, employs a "loop engineering" technique. This method tackles the challenge posed by documents like the 492-page NIST SP 800-53, which has a 358-entry table of contents, making traditional full-document embedding and top-k retrieval inefficient and imprecise. The proposed solution mimics expert human behavior by navigating the document's structure hierarchically.

Instead of processing all pages or the entire table of contents at once, the system processes the table of contents level by level. It presents the LLM with only the current level's headings, allowing it to select the most relevant branch. This process repeats, descending through the document's structure until a specific leaf node, a sufficiently small section, or a required listing is identified. This bounded loop within the retrieval process significantly reduces the number of tokens processed and enhances precision.

The system uses a parsed table of contents, structured as a DataFrame, to guide the retrieval. At each step, the LLM evaluates the current level's entries and decides whether to delve deeper. This controlled descent prevents overwhelming the LLM with too much information and ensures that only relevant sections are read. The approach is demonstrated with runnable code paths utilizing OpenAI services and is part of a broader series on building enterprise RAG systems.