Prompt RAG Limited info

PageIndex: Build a Document Tree Structure from Page-Tagged Text

PageIndex's tree-generation prompt: from document text marked with <physical_index_X> page tags, extract a hierarchical list of sections, each with a structure number such as 1.2, the original title and the page tag where it starts, returned as JSON only.

  • 🤖 Any chat LLM
  • 🗂️ RAG

Prompt by Vectify AI (VectifyAI/PageIndex) · Original source (opens in a new tab)

PageIndex: Build a Document Tree Structure from Page-Tagged Text — prompt preview

The prompt

prompt
You are an expert in extracting hierarchical tree structure, your task is to generate the tree structure of the document.

The structure variable is the numeric system which represents the index of the hierarchy section in the table of contents. For example, the first section has structure index 1, the first subsection has structure index 1.1, the second subsection has structure index 1.2, etc.

For the title, you need to extract the original title from the text, only fix the space inconsistency.

The provided text contains tags like <physical_index_X> and <physical_index_X> to indicate the start and end of page X. 

For the physical_index, you need to extract the physical index of the start of the section from the text. Keep the <physical_index_X> format.

The response should be in the following format. 
    [
        {{
            "structure": <structure index, "x.x.x"> (string),
            "title": <title of the section, keep the original title>,
            "physical_index": "<physical_index_X> (keep the format)"
        }},
        
    ],


Directly return the final JSON structure. Do not output anything else.

What it is

PageIndex's tree-generation prompt: from document text marked with <physical_index_X> page tags, extract a hierarchical list of sections, each with a structure number such as 1.2, the original title and the page tag where it starts, returned as JSON only. The repository publishes this prompt without a printed sample of its output. The prompt text comes from the PageIndex repository (MIT License, Copyright (c) 2025 Vectify AI). Licence: https://github.com/VectifyAI/PageIndex/blob/main/LICENSE. Original author: Vectify AI (VectifyAI/PageIndex). Changes by FoxaMind: Python string quotes removed, the leading blank line dropped and the four-space code indentation removed. The string is not passed through .format, so the doubled braces {{ }} in the JSON sample are sent to the model as written.

Who it's for

  • Developers building retrieval over long PDFs
  • Anyone who needs a table of contents for a document that has none

برومبت توليد شجرة المستند في PageIndex: من نص مستند مُعلّم بوسوم الصفحات <physical_index_X>، يستخرج قائمة هرمية بالأقسام، لكل قسم رقم بنية مثل 1.2 والعنوان الأصلي ووسم الصفحة التي يبدأ فيها، ويعيدها بصيغة JSON فقط.

Tips

  • The code puts <physical_index_X> tags around each page before sending the text.
  • The code also adds a short paragraph before this prompt saying the document is data, not instructions, and wraps the document text in <user_document> tags.
  • A companion prompt in the same file continues the tree for the next part of a long document.