The Index Hierarchy: Vector, Tree, Keyword
Compare VectorStoreIndex (default), TreeIndex (summarization), and KeywordTableIndex (sparse).
The Index Hierarchy: Vector, Tree, Keyword is a free AI Agents lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Indexes in LlamaIndex
LlamaIndex calls its retrieval data structures "Indexes". There are several types, each suited to different tasks.
VectorStoreIndex (Default)
The standard embedding-based index — your daily driver:
from llama_index.core import VectorStoreIndex
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
print(query_engine.query('What is in the handbook?'))TreeIndex
Builds a hierarchical summary tree — useful for summarisation queries:
from llama_index.core import TreeIndex
index = TreeIndex.from_documents(documents)
# Internal nodes are summaries of their children.
# Good for 'summarise the whole corpus' tasks.KeywordTableIndex
Classical keyword-based — for when embedding-based fails on rare terms:
from llama_index.core import KeywordTableIndex
index = KeywordTableIndex.from_documents(documents)
# Falls back to exact-match for rare technical terms.SummaryIndex (formerly ListIndex)
A flat list of every chunk — useful when you want the LLM to see ALL data:
from llama_index.core import SummaryIndex
index = SummaryIndex.from_documents(documents)
# Best for short corpora where you can stuff everything into context.KnowledgeGraphIndex
Extracts a knowledge graph (entities + relations) from documents:
from llama_index.core import KnowledgeGraphIndex
index = KnowledgeGraphIndex.from_documents(
documents,
max_triplets_per_chunk=10
)Choosing an Index
| Task | Index |
|---|---|
| Q&A by similarity | VectorStoreIndex |
| Summarise the whole corpus | TreeIndex / SummaryIndex |
| Rare exact terms | KeywordTableIndex |
| Relational facts | KnowledgeGraphIndex |
Composing Indexes
You can stack indexes — e.g. a summary tree over per-document vector indexes:
from llama_index.core import ComposableGraph
graph = ComposableGraph.from_indices(
TreeIndex,
[vector_index_doc_1, vector_index_doc_2, ...],
index_summaries=['Doc 1 summary', 'Doc 2 summary']
)Persisting an Index
index.storage_context.persist(persist_dir='./store')
# Reload later:
from llama_index.core import StorageContext, load_index_from_storage
ctx = StorageContext.from_defaults(persist_dir='./store')
index = load_index_from_storage(ctx)Using External Vector Stores
Pair LlamaIndex with Pinecone, Qdrant, Weaviate, etc.:
from llama_index.vector_stores.pinecone import PineconeVectorStore
from llama_index.core import StorageContext, VectorStoreIndex
vector_store = PineconeVectorStore(pinecone_index=pc_index)
storage = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage)Hybrid Retrieval
Combine vector + keyword via separate indexes + a query engine that fuses results.
Index Refresh
For doc updates, LlamaIndex supports incremental refresh:
index.refresh_ref_docs(updated_documents)Index for Summarisation
Which LlamaIndex type is best for "summarise the whole corpus"?
Recap
Pick the index that matches the task. Default to VectorStoreIndex; reach for TreeIndex, KeywordTableIndex, or KnowledgeGraphIndex for specialised needs.
Frequently asked questions
Is the “The Index Hierarchy: Vector, Tree, Keyword” lesson free?
Yes — the full text of “The Index Hierarchy: Vector, Tree, Keyword” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “The Index Hierarchy: Vector, Tree, Keyword”?
Compare VectorStoreIndex (default), TreeIndex (summarization), and KeywordTableIndex (sparse). You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Index Hierarchy: Vector, Tree, Keyword” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Document Loaders and Parsers
- The Index Hierarchy: Vector, Tree, Keyword
- Query Engines and Response Synthesis
- Sub-Question Decomposition Strategy