Tree Summarize
If you’re opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
!pip install llama-indexDownload Data
Section titled “Download Data”!mkdir -p 'data/paul_graham/'!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'Load Data
Section titled “Load Data”from llama_index.core import SimpleDirectoryReaderreader = SimpleDirectoryReader( input_files=["./data/paul_graham/paul_graham_essay.txt"])docs = reader.load_data()text = docs[0].textSummarize
Section titled “Summarize”from llama_index.core.response_synthesizers import TreeSummarizesummarizer = TreeSummarize(verbose=True)response = await summarizer.aget_response("who is Paul Graham?", [text])6 text chunks after repacking1 text chunks after repackingprint(response)Paul Graham is a computer scientist, writer, artist, entrepreneur, investor, and essayist. He is best known for his work in artificial intelligence, Lisp programming, and writing the book On Lisp, as well as for co-founding the startup accelerator Y Combinator and for his essays on technology, business, and start-ups. He is also the creator of the programming language Arc and the Lisp dialect Bel.Note for AI agents: this documentation is built for programmatic access.
- Overview of all docs: https://developers.llamaindex.ai/llms.txt
- Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md
- Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters.
- A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/python/shared/mcp/