Route through document structure while keeping answer citations on the smallest passage that actually proves the claim.
Hierarchical retrieval: find a section before selecting its evidence
Index two useful levels
Hierarchical retrieval searches a document tree before choosing answer-bearing passages. A maintenance manual's chapter heading may say 'hydraulic pressure', while the relevant sentence appears in a child paragraph about pump P-47. Store a parent summary and child passages with stable IDs, revision and access label. The parent helps locate the right region; the child proves the claim. A heading alone is not evidence for a numeric limit. Chunk identity should preserve the original section path rather than replacing it with a generated synopsis.
Route with reversible decisions
A top-level search can choose candidate manuals, then section headings, then paragraphs. Keep more than one plausible branch when the query is ambiguous, and record each routing decision in the trace. If the first branch fails an evidence test, a bounded sibling search can recover a missed section. Do not let a model invent a chapter name or crawl indefinitely. Corrective retrieval needs a named failure and a fixed search budget, not an open-ended promise to look harder.
Apply permissions at both levels
A parent section might be visible while a child appendix is restricted. Filtering only the parent can expose child text; filtering only the child can reveal restricted section names through the navigation path. Bind tenant, role and revision to every node. If a parent is revoked, descendant eligibility must be recomputed or removed. An index generation should publish its tree and its passage store together, so a parent does not point to a child from an older revision. Document lifecycle rules still govern tree traversal.
Avoid parent dominance
Long section summaries can match many queries and crowd out precise passages. Allocate a small number of candidate parents, then a separate child window per parent; finally merge child passages with diversity controls. The result should carry its route and its actual supporting span. If the answer requires two sections, preserve both branches instead of concatenating one chapter's unrelated paragraphs. Context packing should count evidence coverage, not just total tokens.
Judge routing and support separately
Evaluation should report whether the right document was found, whether the right section survived routing, whether the supporting child reached the candidate window, and whether the answer cited it. Include misleading headings, appendices, renamed chapters, cross-section questions and restricted child nodes. A router may have high document recall but poor child recall. Preserve first-loss traces to locate that gap before changing the model or the prompt.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class PassageNode:
passage_id: str
parent_id: str
tenant: str
revision: str
text: str
def children_for_section(nodes: list[PassageNode], section_id: str,
tenant: str, revision: str, term: str) -> list[str]:
return [node.passage_id for node in nodes
if node.parent_id == section_id and node.tenant == tenant
and node.revision == revision and term.casefold() in node.text.casefold()]
manual = [PassageNode("pump-47-limit", "hydraulics-r3", "plant-a", "r3",
"Pump P-47 relief limit is 83 kPa."),
PassageNode("pump-47-old", "hydraulics-r2", "plant-a", "r2",
"Pump P-47 relief limit is 71 kPa."),
PassageNode("private-limit", "hydraulics-r3", "plant-b", "r3",
"Pump P-47 relief limit is 99 kPa.")]
assert children_for_section(manual, "hydraulics-r3", "plant-a", "r3", "83 kPa") == [
"pump-47-limit"]
assert children_for_section(manual, "hydraulics-r3", "plant-a", "r3", "99 kPa") == []Performance and operating cost
This transparent child scan is O(N) time for N nodes and O(K) space for K matches. A production index keyed by parent, tenant and revision reduces the eligible scan, but tree traversal adds parent-search and child-search latency. Keep branch count and depth bounded; broad hierarchies can cost more than one flat retrieval call without improving support.
Common Mistakes
- Citing a section summary that does not contain the claimed number.
- Pruning every branch except the first plausible heading.
- Applying access control to a parent but not its children.
- Publishing a parent tree and child passages from different document revisions.
Validation drill
Index 23 manuals with three levels each. Judge 37 queries, including misleading headings and restricted appendices; report document, section and child-passage recall separately.
