{"name":"llamaindex-development","url":"https://skills.sh/mindrally/skills/llamaindex-development","install":"npx skills add mindrally/skills --skill llamaindex-development","sdk":"llamaindex","key":"llamaindex/llamaindex-development","description":"Expert guidance for LlamaIndex development including RAG applications, vector stores, document processing, query engines, and building production AI applications.","hasContent":true,"content":"---\nname: llamaindex-development\ndescription: Expert guidance for LlamaIndex development including RAG applications, vector stores, document processing, query engines, and building production AI applications.\n---\n\n# LlamaIndex Development\n\nYou are an expert in LlamaIndex for building RAG (Retrieval-Augmented Generation) applications, data indexing, and LLM-powered applications with Python.\n\n## Key Principles\n\n- Write concise, technical responses with accurate Python examples\n- Use functional, declarative programming; avoid classes where possible\n- Prioritize code quality, maintainability, and performance\n- Use descriptive variable names that reflect their purpose\n- Follow PEP 8 style guidelines\n\n## Code Organization\n\n### Directory Structure\n\n```\nproject/\n├── data/                 # Source documents and data\n├── indexes/              # Persisted index storage\n├── loaders/              # Custom document loaders\n├── retrievers/           # Custom retriever implementations\n├── query_engines/        # Query engine configurations\n├── prompts/              # Custom prompt templates\n├── transformations/      # Document transformations\n├── callbacks/            # Custom callback handlers\n├── utils/                # Utility functions\n├── tests/                # Test files\n└── config/               # Configuration files\n```\n\n### Naming Conventions\n\n- Use snake_case for files, functions, and variables\n- Use PascalCase for classes\n- Prefix private functions with underscore\n- Use descriptive names (e.g., `create_vector_index`, `build_query_engine`)\n\n## Document Loading\n\n### Using Document Loaders\n\n```python\nfrom llama_index.core import SimpleDirectoryReader\nfrom llama_index.readers.file import PDFReader, DocxReader\n\n# Load from directory\ndocuments = SimpleDirectoryReader(\n    input_dir=\"./data\",\n    recursive=True,\n    required_exts=[\".pdf\", \".txt\", \".md\"]\n).load_data()\n\n# Load specific file types\npdf_reader = PDFReader()\ndocuments = pdf_reader.load_data(file=\"document.pdf\")\n```\n\n### Custom Loaders\n\n```python\nfrom llama_index.core.readers.base import BaseReader\nfrom llama_index.core import Document\n\nclass CustomLoader(BaseReader):\n    def load_data(self, file_path: str) -> list[Document]:\n        # Custom loading logic\n        with open(file_path, 'r') as f:\n            content = f.read()\n\n        return [Document(\n            text=content,\n            metadata={\"source\": file_path}\n        )]\n```\n\n## Text Splitting and Processing\n\n### Node Parsing\n\n```python\nfrom llama_index.core.node_parser import (\n    SentenceSplitter,\n    SemanticSplitterNodeParser,\n    MarkdownNodeParser\n)\n\n# Simple sentence splitting\nsplitter = SentenceSplitter(\n    chunk_size=1024,\n    chunk_overlap=200\n)\nnodes = splitter.get_nodes_from_documents(documents)\n\n# Semantic splitting (preserves meaning)\nfrom llama_index.embeddings.openai import OpenAIEmbedding\n\nsemantic_splitter = SemanticSplitterNodeParser(\n    embed_model=OpenAIEmbedding(),\n    breakpoint_percentile_threshold=95\n)\n\n# Markdown-aware splitting\nmarkdown_splitter = MarkdownNodeParser()\n```\n\n### Best Practices for Chunking\n\n- Choose chunk size based on your embedding model's context window\n- Use overlap to maintain context between chunks\n- Preserve document structure when possible\n- Include metadata for filtering and retrieval\n- Use semantic splitting for better coherence\n\n## Vector Stores and Indexing\n\n### Creating Indexes\n\n```python\nfrom llama_index.core import VectorStoreIndex, StorageContext\nfrom llama_index.vector_stores.chroma import ChromaVectorStore\nimport chromadb\n\n# In-memory index\nindex = VectorStoreIndex.from_documents(documents)\n\n# With persistent vector store\nchroma_client = chromadb.PersistentClient(path=\"./chroma_db\")\nchroma_collection = chroma_client.get_or_create_collection(\"my_collection\")\n\nvector_store = ChromaVectorStore(chroma_collection=chroma_collection)\nstorage_context = StorageContext.from_defaults(vector_store=vector_store)\n\nindex = VectorStoreIndex.from_documents(\n    documents,\n    storage_context=storage_context\n)\n```\n\n### Supported Vector Stores\n\n- Chroma (local development)\n- Pinecone (production, managed)\n- Weaviate (production, self-hosted or managed)\n- Qdrant (production, self-hosted or managed)\n- PostgreSQL with pgvector\n- MongoDB Atlas Vector Search\n\n### Index Persistence\n\n```python\nfrom llama_index.core import StorageContext, load_index_from_storage\n\n# Persist index\nindex.storage_context.persist(persist_dir=\"./storage\")\n\n# Load index\nstorage_context = StorageContext.from_defaults(persist_dir=\"./storage\")\nindex = load_index_from_storage(storage_context)\n```\n\n## Query Engines\n\n### Basic Query Engine\n\n```python\nfrom llama_index.core import VectorStoreIndex\n\nindex = VectorStoreIndex.from_documents(documents)\nquery_engine = index.as_query_engine(\n    similarity_top_k=5,\n    response_mode=\"compact\"\n)\n\nresponse = query_engine.query(\"What is the main topic?\")\nprint(response.response)\n```\n\n### Response Modes\n\n- `refine`: Iteratively refine answer through each node\n- `compact`: Combine chunks before sending to LLM\n- `tree_summarize`: Build tree and summarize\n- `simple_summarize`: Truncate and summarize\n- `accumulate`: Accumulate responses from each node\n\n### Advanced Query Engine\n\n```python\nfrom llama_index.core.query_engine import RetrieverQueryEngine\nfrom llama_index.core.postprocessor import SimilarityPostprocessor\n\nquery_engine = RetrieverQueryEngine.from_args(\n    retriever=index.as_retriever(similarity_top_k=10),\n    node_postprocessors=[\n        SimilarityPostprocessor(similarity_cutoff=0.7)\n    ],\n    response_mode=\"compact\"\n)\n```\n\n## Retrievers\n\n### Custom Retrievers\n\n```python\nfrom llama_index.core.retrievers import VectorIndexRetriever\n\n# Basic retriever\nretriever = VectorIndexRetriever(\n    index=index,\n    similarity_top_k=10\n)\n\n# Retrieve nodes\nnodes = retriever.retrieve(\"search query\")\n```\n\n### Hybrid Search\n\n```python\nfrom llama_index.core.retrievers import QueryFusionRetriever\n\n# Combine multiple retrieval strategies\nretriever = QueryFusionRetriever(\n    [\n        index.as_retriever(similarity_top_k=5),\n        bm25_retriever,  # Keyword-based\n    ],\n    num_queries=4,\n    use_async=True\n)\n```\n\n## Embeddings\n\n### Embedding Models\n\n```python\nfrom llama_index.embeddings.openai import OpenAIEmbedding\nfrom llama_index.embeddings.huggingface import HuggingFaceEmbedding\nfrom llama_index.core import Settings\n\n# OpenAI embeddings\nSettings.embed_model = OpenAIEmbedding(\n    model=\"text-embedding-3-small\",\n    dimensions=512  # Optional dimension reduction\n)\n\n# Local embeddings\nSettings.embed_model = HuggingFaceEmbedding(\n    model_name=\"BAAI/bge-small-en-v1.5\"\n)\n```\n\n## LLM Configuration\n\n### Setting Up LLMs\n\n```python\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.llms.anthropic import Anthropic\nfrom llama_index.core import Settings\n\n# OpenAI\nSettings.llm = OpenAI(\n    model=\"gpt-4o\",\n    temperature=0.1\n)\n\n# Anthropic\nSettings.llm = Anthropic(\n    model=\"claude-sonnet-4-20250514\",\n    temperature=0.1\n)\n```\n\n## Agents\n\n### Building Agents\n\n```python\nfrom llama_index.core.agent import ReActAgent\nfrom llama_index.core.tools import QueryEngineTool, ToolMetadata\n\n# Create tools from query engines\ntools = [\n    QueryEngineTool(\n        query_engine=documents_query_engine,\n        metadata=ToolMetadata(\n            name=\"documents\",\n            description=\"Search through documents\"\n        )\n    ),\n    QueryEngineTool(\n        query_engine=code_query_engine,\n        metadata=ToolMetadata(\n            name=\"codebase\",\n            description=\"Search through code\"\n        )\n    )\n]\n\n# Create agent\nagent = ReActAgent.from_tools(\n    tools,\n    llm=llm,\n    verbose=True\n)\n\nresponse = agent.chat(\"Find information about X\")\n```\n\n## Performance Optimization\n\n### Caching\n\n```python\nfrom llama_index.core import Settings\nfrom llama_index.core.llms import LLMCache\n\n# Enable LLM response caching\nSettings.llm = OpenAI(model=\"gpt-4o\")\nSettings.llm_cache = LLMCache()\n```\n\n### Async Operations\n\n```python\n# Use async for better performance\nresponse = await query_engine.aquery(\"question\")\n\n# Batch processing\nresponses = await asyncio.gather(*[\n    query_engine.aquery(q) for q in questions\n])\n```\n\n### Embedding Optimization\n\n- Batch embeddings when possible\n- Use smaller embedding dimensions when accuracy allows\n- Cache embeddings for repeated documents\n- Use local models for cost-sensitive applications\n\n## Error Handling\n\n```python\nfrom llama_index.core.callbacks import CallbackManager, LlamaDebugHandler\n\n# Debug handler for troubleshooting\ndebug_handler = LlamaDebugHandler()\ncallback_manager = CallbackManager([debug_handler])\n\nSettings.callback_manager = callback_manager\n```\n\n## Testing\n\n- Unit test document loaders and transformations\n- Test retrieval quality with known queries\n- Validate index persistence and loading\n- Test query engine responses\n- Monitor retrieval metrics (precision, recall)\n\n## Dependencies\n\n- llama-index\n- llama-index-embeddings-openai\n- llama-index-llms-openai\n- llama-index-vector-stores-chroma\n- chromadb\n- python-dotenv\n- pydantic\n","contentSource":"skills.sh/api/download/mindrally/skills/llamaindex-development","contentFetchedAt":"2026-07-27T08:59:35.510Z"}