| name | rag |
| description | RAG pipelines including document chunking, embedding, vector search, retrieval strategies, and reranking |
| layer | domain |
| category | ai-ml |
| triggers | ["RAG","retrieval augmented generation","vector search","embeddings","chunking","knowledge base","semantic search","reranking"] |
| inputs | [{"documents":"Source documents to index (PDFs, web pages, databases, etc.)"},{"query_patterns":"How users will search (natural language, keyword, hybrid)"},{"requirements":"Accuracy, latency, freshness, cost constraints"},{"infrastructure":"Vector database choice, embedding model preference"}] |
| outputs | [{"pipeline_design":"End-to-end RAG pipeline architecture"},{"chunking_strategy":"Document splitting approach with overlap"},{"embedding_config":"Model selection and dimension settings"},{"retrieval_strategy":"Search, filter, and reranking configuration"},{"evaluation_plan":"Metrics and test cases for RAG quality"}] |
| linksTo | ["ai-agents","prompt-engineering","postgresql","redis"] |
| linkedFrom | ["ai-agents","cook","research"] |
| preferredNextSkills | ["ai-agents","prompt-engineering"] |
| fallbackSkills | ["research"] |
| riskLevel | low |
| memoryReadPolicy | selective |
| memoryWritePolicy | none |
| sideEffects | ["May create vector store indexes","May process and embed documents","Consumes embedding API tokens"] |
RAG (Retrieval-Augmented Generation) Skill
Purpose
Design and implement RAG pipelines that ground LLM responses in relevant, up-to-date knowledge. This skill covers the full pipeline: document ingestion, chunking strategies, embedding model selection, vector storage, retrieval with filtering, reranking for precision, and prompt construction with retrieved context. RAG reduces hallucination by giving the model factual context to work with.
Key Concepts
RAG Pipeline Overview
INGESTION (offline):
Documents -> Chunking -> Embedding -> Vector Store
RETRIEVAL (at query time):
Query -> Embed Query -> Vector Search -> Rerank -> Top-K Context
GENERATION (at query time):
System Prompt + Retrieved Context + User Query -> LLM -> Response
EVALUATION:
Context Relevance | Answer Faithfulness | Answer Relevance
Chunking Strategies
FIXED SIZE:
Split at N characters/tokens with M overlap
Simple but may break mid-sentence
Good for: Uniform, well-structured documents
RECURSIVE CHARACTER:
Split on paragraphs, then sentences, then words
Respects document structure
Good for: General purpose, articles, documentation
SEMANTIC:
Split when embedding similarity between sentences drops
Each chunk is semantically coherent
Good for: Long documents with topic changes
DOCUMENT-AWARE:
Split on markdown headers, HTML tags, code blocks
Preserves structural meaning
Good for: Technical documentation, code, structured content
RULES OF THUMB:
Chunk size: 500-1000 tokens (sweet spot for most models)
Overlap: 50-200 tokens (prevents losing context at boundaries)
Smaller chunks = more precise retrieval, less context per chunk
Larger chunks = more context per chunk, less precise retrieval
Embedding Model Selection
MODEL DIMENSIONS SPEED QUALITY COST
text-embedding-3-small 1536 Fast Good Low
text-embedding-3-large 3072 Medium Best Medium
voyage-3 1024 Fast Great Medium
cohere-embed-v3 1024 Fast Great Medium
BGE-large (open source) 1024 Self-host Good Free (compute)
GUIDELINES:
- Start with text-embedding-3-small for prototyping
- Upgrade to text-embedding-3-large or voyage-3 for production
- Use the SAME model for document and query embeddings
- Matryoshka embeddings: can truncate dimensions for speed
Patterns
Document Ingestion Pipeline
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { OpenAIEmbeddings } ;
splitter = ({
: ,
: ,
: [, , , , , ],
});
chunks = splitter.(documents);
embeddings = ({
: ,
: ,
});
vectors = embeddings.(
chunks.( chunk.)
);
( i = ; i < chunks.; i++) {
vectorStore.({
: ,
: vectors[i],
: {
: chunks[i].,
: chunks[i]..,
: chunks[i]..,
: i,
},
});
}