| name | llamaindex-patterns |
| description | LlamaIndex data framework — ingestion, indexing, query engines, chat engines, agents. Use when working with llamaindex patterns. |
| domain | core |
| author | oyi77 |
| license | Apache-2.0 |
| subdomain | core-platform |
| tags | ["ai-agent","infrastructure","llamaindex","memory","patterns","self-improvement"] |
| version | 1.0.0 |
Overview
LlamaIndex is a data framework for connecting LLMs with external data. It provides document loaders, vector stores, query engines, and chat engines for building RAG applications and knowledge-augmented agents.
Capabilities
- Load documents from 160+ sources (PDF, Notion, Slack, databases)
- Build vector indices for semantic search
- Create query engines with retrieval and synthesis
- Build conversational chat engines with memory
- Use agents with tool use and multi-step reasoning
- Implement advanced RAG patterns (routing, fusion, recursive)
When to Use
Trigger phrases:
-
"llamaindex patterns"
-
"LlamaIndex data framework — ingestion, indexing, query engines, chat engines, ag"
-
Building RAG applications over custom data sources
-
Needing structured document ingestion pipelines
-
Wanting query engines with citations and source tracking
-
Building chatbots over knowledge bases
-
Implementing agentic RAG with tool use
When NOT to Use
- Task is outside your authorization scope
- You need to implement controls (use implementing-* skills)
- Task is about analysis, not action (use analyzing-* skills)
- You don't have access to target systems
- Task requires compliance expertise (consult professionals)
- Task is about defense, not offense (use defensive skills)
Pseudo Code
def execute(input_data):
if not input_data:
raise ValueError("Input data is required")
result = process(input_data)
validate_output(result)
return result
Document Ingestion
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
Query Engine
from llama_index.core import VectorStoreIndex
from llama_index.llms.openai import OpenAI
llm = OpenAI(model="gpt-4o", temperature=0)
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(
llm=llm,
similarity_top_k=5,
response_mode="compact",
)
response = query_engine.query("What are the company's revenue streams?")
print(response.response)
print(response.source_nodes)
Chat Engine
chat_engine = index.as_chat_engine(
chat_mode="condense_plus_context",
llm=llm,
similarity_top_k=3,
)
response1 = chat_engine.chat("What is the return policy?")
response2 = chat_engine.chat("What about international orders?")
Custom Document Loaders
from llama_index.core import Document
import pandas as pd
df = pd.read_sql("SELECT * FROM articles", con=engine)
documents = [
Document(text=row['content'], metadata={"id": row['id'], "title": row['title']})
for _, row in df.iterrows()
]
index = VectorStoreIndex.from_documents(documents)
Vector Store Integrations
from llama_index.vector_stores.pinecone import PineconeVectorStore
from llama_index.core import StorageContext
vector_store = PineconeVectorStore(
index_name="my-index",
environment="us-east1-gcp",
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
from llama_index.vector_stores.qdrant import QdrantVectorStore
import qdrant_client
client = qdrant_client.QdrantClient(host="localhost", port=6333)
vector_store = QdrantVectorStore(client=client, collection_name="docs")
Agent with Tools
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import QueryEngineTool, FunctionTool
query_tool = QueryEngineTool.from_defaults(
query_engine=query_engine,
name="document_search",
description="Search company documents for information",
)
def multiply(a: float, b: float) -> float:
return a * b
multiply_tool = FunctionTool.from_defaults(fn=multiply)
agent = ReActAgent.from_tools(
tools=[query_tool, multiply_tool],
llm=llm,
verbose=True,
)
response = agent.chat("Find the Q3 revenue and multiply by 1.1 for Q4 projection")
Advanced RAG: Router Query Engine
from llama_index.core.query_engine import RouterQueryEngine
from llama_index.core.selectors import LLMSingleSelector
vector_engine = index.as_query_engine()
summary_engine = index.as_query_engine(response_mode="tree_summarize")
router = RouterQueryEngine(
selector=LLMSingleSelector.from_defaults(),
query_engines=[vector_engine, summary_engine],
select_multi=False,
)
response = router.query("Summarize all quarterly reports")
Common Patterns
| Pattern | When to Use |
|---|
SimpleDirectoryReader | Load files from disk |
VectorStoreIndex | Build searchable index |
as_query_engine() | Single question + answer |
as_chat_engine() | Multi-turn conversation |
ReActAgent | Agent with tool reasoning |
RouterQueryEngine | Route to best engine automatically |
response_mode="compact" | Concise answers |
response_mode="tree_summarize" | Summarize across many documents |
Error Handling
| Error | Cause | Fix |
|---|
IndexEmpty | No documents loaded | Check directory path and file types |
Response incomplete | Too few source nodes | Increase similarity_top_k |
| Embedding dimension mismatch | Wrong model | Use consistent embedding model |
| Token limit during synthesis | Too many nodes retrieved | Reduce similarity_top_k or use compact mode |
How to Use
- Invoke the skill when relevant domain keywords appear in the request
- Provide required inputs as specified in the skill definition
- Review the output for correctness before delivering to the user
- Combine with related skills for complex multi-step workflows
Verification
After completing this skill, confirm:
Process
- Analyze the task requirements
- Apply domain expertise
- Verify output quality
Anti-Rationalization Table
| Rationalization | Reality |
|---|
| "I will add monitoring later" | Without monitoring, you cannot detect failures. Add it from day one. |
| "One model is enough" | Different tasks need different models. Route intelligently. |
| "Premature optimization" | Infrastructure decisions are hard to change later. Design for scale early. |