name: rag-implementation
description: Build Retrieval-Augmented Generation (RAG) systems for LLM applications with vector databases and semantic search. Use when implementing knowledge-grounded AI, building document Q&A systems, or integrating LLMs with external knowledge bases.
RAG Implementation
Master Retrieval-Augmented Generation (RAG) to build LLM applications that provide accurate, grounded responses using external knowledge sources.
When to Use This Skill
- Building Q&A systems over proprietary documents
- Creating chatbots with current, factual information
- Implementing semantic search with natural language queries
- Reducing hallucinations with grounded responses
- Enabling LLMs to access domain-specific knowledge
- Building documentation assistants
- Creating research tools with source citation
Core Components
1. Vector Databases
Purpose: Store and retrieve document embeddings efficiently
Options:
- Pinecone: Managed, scalable, serverless
- Weaviate: Open-source, hybrid search, GraphQL
- Milvus: High performance, on-premise
- Chroma: Lightweight, easy to use, local development
- Qdrant: Fast, filtered search, Rust-based
- pgvector: PostgreSQL extension, SQL integration
2. Embeddings
Purpose: Convert text to numerical vectors for similarity search
Models (2026):
| Model |
Dimensions |
Best For |
| voyage-3-large |
1024 |
Claude apps (Anthropic recommended) |
| voyage-code-3 |
1024 |
Code search |
| text-embedding-3-large |
3072 |
OpenAI apps, high accuracy |
| text-embedding-3-small |
1536 |
OpenAI apps, cost-effective |
| bge-large-en-v1.5 |
1024 |
Open source, local deployment |
| multilingual-e5-large |
1024 |
Multi-language support |
3. Retrieval Strategies
Approaches:
- Dense Retrieval: Semantic similarity via embeddings
- Sparse Retrieval: Keyword matching (BM25, TF-IDF)
- Hybrid Search: Combine dense + sparse with weighted fusion
- Multi-Query: Generate multiple query variations
- HyDE: Generate hypothetical documents for better retrieval
4. Reranking
Purpose: Improve retrieval quality by reordering results
Methods:
- Cross-Encoders: BERT-based reranking (ms-marco-MiniLM)
- Cohere Rerank: API-based reranking
- Maximal Marginal Relevance (MMR): Diversity + relevance
- LLM-based: Use LLM to score relevance
Quick Start with LangGraph
from langgraph.graph import StateGraph, START, END
from langchain_anthropic import ChatAnthropic
from langchain_voyageai import VoyageAIEmbeddings
from langchain_pinecone import PineconeVectorStore
from langchain_core.documents import Document
from langchain_core.prompts import ChatPromptTemplate
from langchain_text_splitters import RecursiveCharacterTextSplitter
from typing import TypedDict, Annotated
class RAGState(TypedDict):
question: str
context: list[Document]
answer: str
# Initialize components
llm = ChatAnthropic(model="claude-sonnet-4-6")
embeddings = VoyageAIEmbeddings(model="voyage-3-large")
vectorstore = PineconeVectorStore(index_name="docs", embedding=embeddings)
retriever = vectorstore.as_retriever(search_kwargs={"k": 4})
# RAG prompt
rag_prompt = ChatPromptTemplate.from_template(
"""Answer based on the context below. If you cannot answer, say so.
Context:
{context}
Question: {question}
Answer:"""
)
async def retrieve(state: RAGState) -> RAGState:
"""Retrieve relevant documents."""
docs = await retriever.ainvoke(state["question"])
return {"context": docs}
async def generate(state: RAGState) -> RAGState:
"""Generate answer from context."""
context_text = "\n\n".join(doc.page_content for doc in state["context"])
messages = rag_prompt.format_messages(
context=context_text,
question=state["question"]
)
response = await llm.ainvoke(messages)
return {"answer": response.content}
# Build RAG graph
builder = StateGraph(RAGState)
builder.add_node("retrieve", retrieve)
builder.add_node("generate", generate)
builder.add_edge(START, "retrieve")
builder.add_edge("retrieve", "generate")
builder.add_edge("generate", END)
rag_chain = builder.compile()
# Use
result = await rag_chain.ainvoke({"question": "What are the main features?"})
print(result["answer"])
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
1---2name: wshobson-rag-implementation3description: <!-- source: wshobson-rag-implementation — https://raw.githubusercontent.com/wshobson/agents/main/plugins/llm-application-dev/skills/rag-implementation/SKILL.md -->4---5<!-- source: wshobson-rag-implementation — https://raw.githubusercontent.com/wshobson/agents/main/plugins/llm-application-dev/skills/rag-implementation/SKILL.md -->6---7name: rag-implementation8description: Build Retrieval-Augmented Generation (RAG) systems for LLM applications with vector databases and semantic search. Use when implementing knowledge-grounded AI, building document Q&A systems, or integrating LLMs with external knowledge bases.9---1011# RAG Implementation1213Master Retrieval-Augmented Generation (RAG) to build LLM applications that provide accurate, grounded responses using external knowledge sources.1415## When to Use This Skill1617- Building Q&A systems over proprietary documents18- Creating chatbots with current, factual information19- Implementing semantic search with natural language queries20- Reducing hallucinations with grounded responses21- Enabling LLMs to access domain-specific knowledge22- Building documentation assistants23- Creating research tools with source citation2425## Core Components2627### 1. Vector Databases2829**Purpose**: Store and retrieve document embeddings efficiently3031**Options:**3233- **Pinecone**: Managed, scalable, serverless34- **Weaviate**: Open-source, hybrid search, GraphQL35- **Milvus**: High performance, on-premise36- **Chroma**: Lightweight, easy to use, local development37- **Qdrant**: Fast, filtered search, Rust-based38- **pgvector**: PostgreSQL extension, SQL integration3940### 2. Embeddings4142**Purpose**: Convert text to numerical vectors for similarity search4344**Models (2026):**45| Model | Dimensions | Best For |46|-------|------------|----------|47| **voyage-3-large** | 1024 | Claude apps (Anthropic recommended) |48| **voyage-code-3** | 1024 | Code search |49| **text-embedding-3-large** | 3072 | OpenAI apps, high accuracy |50| **text-embedding-3-small** | 1536 | OpenAI apps, cost-effective |51| **bge-large-en-v1.5** | 1024 | Open source, local deployment |52| **multilingual-e5-large** | 1024 | Multi-language support |5354### 3. Retrieval Strategies5556**Approaches:**5758- **Dense Retrieval**: Semantic similarity via embeddings59- **Sparse Retrieval**: Keyword matching (BM25, TF-IDF)60- **Hybrid Search**: Combine dense + sparse with weighted fusion61- **Multi-Query**: Generate multiple query variations62- **HyDE**: Generate hypothetical documents for better retrieval6364### 4. Reranking6566**Purpose**: Improve retrieval quality by reordering results6768**Methods:**6970- **Cross-Encoders**: BERT-based reranking (ms-marco-MiniLM)71- **Cohere Rerank**: API-based reranking72- **Maximal Marginal Relevance (MMR)**: Diversity + relevance73- **LLM-based**: Use LLM to score relevance7475## Quick Start with LangGraph7677```python78from langgraph.graph import StateGraph, START, END79from langchain_anthropic import ChatAnthropic80from langchain_voyageai import VoyageAIEmbeddings81from langchain_pinecone import PineconeVectorStore82from langchain_core.documents import Document83from langchain_core.prompts import ChatPromptTemplate84from langchain_text_splitters import RecursiveCharacterTextSplitter85from typing import TypedDict, Annotated8687class RAGState(TypedDict):88 question: str89 context: list[Document]90 answer: str9192# Initialize components93llm = ChatAnthropic(model="claude-sonnet-4-6")94embeddings = VoyageAIEmbeddings(model="voyage-3-large")95vectorstore = PineconeVectorStore(index_name="docs", embedding=embeddings)96retriever = vectorstore.as_retriever(search_kwargs={"k": 4})9798# RAG prompt99rag_prompt = ChatPromptTemplate.from_template(100 """Answer based on the context below. If you cannot answer, say so.101102 Context:103 {context}104105 Question: {question}106107 Answer:"""108)109110async def retrieve(state: RAGState) -> RAGState:111 """Retrieve relevant documents."""112 docs = await retriever.ainvoke(state["question"])113 return {"context": docs}114115async def generate(state: RAGState) -> RAGState:116 """Generate answer from context."""117 context_text = "\n\n".join(doc.page_content for doc in state["context"])118 messages = rag_prompt.format_messages(119 context=context_text,120 question=state["question"]121 )122 response = await llm.ainvoke(messages)123 return {"answer": response.content}124125# Build RAG graph126builder = StateGraph(RAGState)127builder.add_node("retrieve", retrieve)128builder.add_node("generate", generate)129builder.add_edge(START, "retrieve")130builder.add_edge("retrieve", "generate")131builder.add_edge("generate", END)132133rag_chain = builder.compile()134135# Use136result = await rag_chain.ainvoke({"question": "What are the main features?"})137print(result["answer"])138```139140## Detailed patterns and worked examples141142Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.143