A summary node is an LLM-written abstraction over related source chunks or lower-level nodes. It adds a higher-resolution retrieval target to a hierarchy: leaves preserve specific facts, while summary nodes express themes and broader conditions. section 10.2 section 10.0
Summary nodes participate in a recursively built retrieval structure:
- Related chunks are clustered and summarized into mid-level nodes; those summaries can be clustered again until a root summary covers the corpus. section 10.2
- A thematic query can match a summary node, while a granular factual query can match a leaf through the same retrieval system. section 10.2 section 10.5.1
- Soft clustering may let one chunk inform several summaries, making the hierarchy a directed acyclic graph rather than a strict tree. section 10.8
- Summary generation moves cost to indexing: each summary requires an LLM call once, while later queries can use the resulting retrieval targets. section 10.8
One index, two resolutions
A question about a contract’s broad termination conditions can retrieve a summary node describing the termination clause. A question asking for the specific termination fee can retrieve the underlying leaf chunk instead. section 10.2
Flattening all levels into one vector index preserves summary and leaf content while retaining level, leaf status, and child-count metadata. This is a practical default below about 100,000 chunks; root-down traversal is slower but scales to much larger collections. Cross-document clustering requires boundaries or provenance, because a summary can otherwise merge similar content from different products or tenants. section 10.8 section 10.5.3
Listing 10.7 Collapsed Tree Indexing.
from langchain_core.documents import Document
from langchain_community.vectorstores import Chroma
def index_collapsed_tree(nodes: Dict[str, RaptorNode],
persist_directory: str) -> Chroma:
documents = []
for node_id, node in nodes.items():
metadata = {
"id": node.id,
"level": node.level,
"is_leaf": node.is_leaf(),
"children_count": len(node.children) #A
}
doc = Document(
page_content=node.text,
metadata=metadata
)
documents.append(doc)
vectorstore = Chroma.from_documents(
documents=documents,
embedding=get_embeddings(),
collection_name="raptor_collapsed",
persist_directory=persist_directory
)
return vectorstore
The listing shows how to store summary nodes and leaves together in a collapsed Chroma index, including level, leaf status, and child-count metadata. section 10.5.1
