Build retrieval-augmented generation (RAG) applications using LlamaIndex core abstractions for LLMs, vector stores, embeddings, and data indexing.
Build production-ready retrieval-augmented generation (RAG) applications using LlamaIndex, the leading framework for connecting LLMs to your data. This skill guides you through using LlamaIndex core abstractions to create data-aware LLM applications.
This skill helps you leverage LlamaIndex core (v0.14.13+) to build RAG applications by:
First, install the core package:
```bash
pip install llama-index-core
```
For specific integrations (vector stores, LLMs, readers), install the needed packages:
```bash
pip install llama-index-llms-openai
pip install llama-index-vector-stores-pinecone
pip install llama-index-embeddings-huggingface
```
Create a basic RAG pipeline by loading documents and creating an index:
```python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
```
Set up a query engine to retrieve relevant context and generate responses:
```python
query_engine = index.as_query_engine()
response = query_engine.query("What is the main topic of these documents?")
print(response)
```
LlamaIndex core provides abstractions you can extend:
**Custom LLM:**
```python
from llama_index.core.llms import LLM
from llama_index.core import Settings
from llama_index.llms.openai import OpenAI
Settings.llm = OpenAI(model="gpt-4", temperature=0.1)
```
**Custom Embeddings:**
```python
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
Settings.embed_model = HuggingFaceEmbedding(
model_name="BAAI/bge-small-en-v1.5"
)
```
**Custom Vector Store:**
```python
from llama_index.vector_stores.pinecone import PineconeVectorStore
import pinecone
pc = pinecone.Pinecone(api_key="your-api-key")
index = pc.Index("your-index-name")
vector_store = PineconeVectorStore(pinecone_index=index)
index = VectorStoreIndex.from_documents(
documents,
vector_store=vector_store
)
```
Use LlamaIndex's retrieval abstractions for sophisticated patterns:
```python
from llama_index.core import QueryBundle
from llama_index.core.retrievers import VectorIndexRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
retriever = VectorIndexRetriever(
index=index,
similarity_top_k=5
)
query_engine = RetrieverQueryEngine(retriever=retriever)
```
Save your index to disk for reuse:
```python
index.storage_context.persist(persist_dir="./storage")
from llama_index.core import StorageContext, load_index_from_storage
storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)
```
Update your index as data changes:
```python
new_docs = SimpleDirectoryReader("./new_data").load_data()
for doc in new_docs:
index.insert(doc)
index.refresh_ref_docs(documents)
```
LlamaIndex core provides these foundational abstractions:
LlamaIndex follows an extensible architecture:
1. **Core** (`llama-index-core`): Base abstractions and interfaces
2. **Integrations** (`llama-index-{component}-{provider}`): Specific implementations
When building applications:
**Basic RAG app:**
```python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
docs = SimpleDirectoryReader("docs").load_data()
index = VectorStoreIndex.from_documents(docs)
response = index.as_query_engine().query("Summarize the key points")
```
**Multi-source RAG:**
```python
from llama_index.core import VectorStoreIndex
from llama_index.readers.file import PDFReader
from llama_index.readers.web import SimpleWebPageReader
pdf_docs = PDFReader().load_data("./reports")
web_docs = SimpleWebPageReader().load_data(["https://example.com"])
all_docs = pdf_docs + web_docs
index = VectorStoreIndex.from_documents(all_docs)
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/llamaindex-rag-application-builder/raw