12 Prompts for RAG Systems: Indexing, Search, and Generation
Retrieval-Augmented Generation (RAG) is one of the most powerful patterns in modern AI applications. It combines a retrieval step—typically using vector databases or hybrid search—with a generation step via large language models (LLMs). But the quality of a RAG pipeline depends heavily on how you prompt each stage: chunking, embedding, retrieval, and generation.
In this guide, I share 12 ready-to-use prompts for building and optimizing RAG systems. Each prompt is designed for a specific task, comes with a clear explanation, and includes a practical code example. Whether you are a beginner or an experienced engineer, these prompts will save you hours of trial and error.
1. Chunking Strategy Prompt
Task: Define the optimal chunk size and overlap for your document corpus.
Prompt:
Given a corpus of technical documents about [topic], recommend a chunk size and overlap strategy for RAG indexing. Consider document length, section structure, and the typical query length. Provide your reasoning in terms of retrieval precision and recall.
Explanation: Chunking is the foundation of good retrieval. Too small chunks lose context; too large chunks dilute relevance. This prompt forces the LLM to reason about your specific data.
Example usage:
prompt = """Given a corpus of legal contracts (average 5000 words per document, with clear clause headers), recommend a chunk size and overlap strategy for RAG indexing. Consider that queries are often short (3-10 words) and refer to specific clauses. Provide your reasoning."""
response = llm.invoke(prompt)
print(response)
2. Embedding Model Selection Prompt
Task: Choose the best embedding model for your domain and language.
Prompt:
Compare the following embedding models for a RAG system in [domain]: `text-embedding-3-small`, `text-embedding-3-large`, `BAAI/bge-base-en-v1.5`, and `intfloat/e5-mistral-7b-instruct`. Evaluate based on retrieval accuracy, latency, cost, and support for [language]. Suggest the best model and explain why.
Explanation: Embedding models vary in dimension, speed, and domain fit. This prompt helps you make an informed choice.
Example usage:
prompt = """Compare the following embedding models for a RAG system in medical research (PubMed abstracts, English): text-embedding-3-small, text-embedding-3-large, BAAI/bge-base-en-v1.5, and intfloat/e5-mistral-7b-instruct. Evaluate based on retrieval accuracy, latency, cost, and support for English. Suggest the best model and explain why."""
response = llm.invoke(prompt)
print(response)
3. Hybrid Search Weight Tuning Prompt
Task: Determine the optimal weight between dense (vector) and sparse (keyword) search.
Prompt:
For a RAG system that uses hybrid search (combining dense embeddings with BM25), suggest an initial weight `alpha` (0 to 1) where 1 = pure dense and 0 = pure sparse. Base your suggestion on the following data: [describe your queries and documents]. Explain how to iteratively tune this weight.
Explanation: Hybrid search often outperforms pure vector search, but the weight needs careful tuning. This prompt gives you a starting point.
Example usage:
prompt = """For a RAG system that uses hybrid search (combining dense embeddings with BM25), suggest an initial weight alpha (0 to 1) where 1 = pure dense and 0 = pure sparse. Base your suggestion on the following data: queries are short product descriptions, documents are e-commerce product pages with titles, specs, and reviews. Explain how to iteratively tune this weight."""
response = llm.invoke(prompt)
print(response)
4. Query Rewriting Prompt
Task: Rewrite a user query to improve retrieval.
Prompt:
Rewrite the following user query into a more precise, search-optimized version for a RAG system. Expand abbreviations, add synonyms, and clarify ambiguous terms. Output only the rewritten query.
User query: "{query}"
Explanation: Users often type vague or abbreviated queries. Rewriting them improves retrieval quality significantly.
Example usage:
query = "AI ethics guidelines 2024"
prompt = f"""Rewrite the following user query into a more precise, search-optimized version for a RAG system. Expand abbreviations, add synonyms, and clarify ambiguous terms. Output only the rewritten query.
User query: "{query}"
"""
response = llm.invoke(prompt)
print(response) # e.g., "artificial intelligence ethical guidelines published in 2024"
5. Query Decomposition Prompt
Task: Break a complex query into sub-queries for multi-hop retrieval.
Prompt:
Decompose the following complex question into 2-4 simpler sub-questions. Each sub-question should be answerable by a single document chunk. Output a numbered list.
Question: "{complex_question}"
Explanation: Complex questions require multi-hop reasoning. Decomposing them improves accuracy.
Example usage:
question = "What were the key findings of the 2023 IPCC report on methane emissions, and how do they compare to the 2021 report?"
prompt = f"""Decompose the following complex question into 2-4 simpler sub-questions. Each sub-question should be answerable by a single document chunk. Output a numbered list.
Question: "{question}"
"""
response = llm.invoke(prompt)
print(response)
6. Context Window Optimization Prompt
Task: Fit retrieved chunks into the LLM’s context window.
Prompt:
You have retrieved {num_chunks} chunks for a query. The LLM has a context window of {max_tokens} tokens. Summarize or truncate the chunks to fit within {target_tokens} tokens while preserving all key facts relevant to: "{query}". Output the condensed context.
Explanation: Chunks often exceed the context window. This prompt intelligently condenses them.
Example usage:
query = "What is the capital of France?"
prompt = f"""You have retrieved 5 chunks for a query. The LLM has a context window of 4096 tokens. Summarize or truncate the chunks to fit within 3000 tokens while preserving all key facts relevant to: "{query}". Output the condensed context."""
response = llm.invoke(prompt)
print(response)
7. Re-ranking Prompt
Task: Re-rank retrieved chunks by relevance.
Prompt:
Given the following query and a list of {num_chunks} retrieved chunks, re-rank them by relevance to the query. Output the chunks in order of relevance, with a brief reason for each.
Query: "{query}"
Chunks:
{chunks}
Explanation: Initial retrieval may not be perfect. Re-ranking improves the final context.
Example usage:
query = "Python list comprehension"
chunks = ["Lists are mutable in Python.", "List comprehensions provide a concise way to create lists.", "Tuples are immutable."]
prompt = f"""Given the following query and a list of 3 retrieved chunks, re-rank them by relevance to the query. Output the chunks in order of relevance, with a brief reason for each.
Query: "{query}"
Chunks:
{chunks}
"""
response = llm.invoke(prompt)
print(response)
8. Answer Generation Prompt with Citation
Task: Generate an answer with citations to source chunks.
Prompt:
Answer the user question using only the provided context. For each fact, cite the source chunk number in square brackets. If the context does not contain the answer, say "The context does not contain this information."
Context:
{context}
Question: {question}
Explanation: Citations build trust and allow users to verify answers.
Example usage:
context = "[1] Paris is the capital of France. [2] France is in Western Europe."
question = "What is the capital of France?"
prompt = f"""Answer the user question using only the provided context. For each fact, cite the source chunk number in square brackets. If the context does not contain the answer, say "The context does not contain this information."
Context:
{context}
Question: {question}
"""
response = llm.invoke(prompt)
# Expected: "The capital of France is Paris [1]."
print(response)
9. Hallucination Check Prompt
Task: Verify that the generated answer is grounded in the context.
Prompt:
Check if the following answer can be fully supported by the provided context. Output "SUPPORTED" if every claim is directly in the context, "PARTIALLY" if some claims are supported, or "NOT SUPPORTED" if no claims are supported. Provide a brief explanation.
Context: {context}
Answer: {answer}
Explanation: Hallucination is a major risk in RAG. This prompt helps you catch it.
Example usage:
context = "Paris is the capital of France."
answer = "Paris is the capital of France and has a population of 2 million."
prompt = f"""Check if the following answer can be fully supported by the provided context. Output "SUPPORTED" if every claim is directly in the context, "PARTIALLY" if some claims are supported, or "NOT SUPPORTED" if no claims are supported. Provide a brief explanation.
Context: {context}
Answer: {answer}
"""
response = llm.invoke(prompt)
print(response) # "PARTIALLY" because population is not in context
10. Feedback-Driven Refinement Prompt
Task: Improve retrieval based on user feedback.
Prompt:
The user rated the previous answer as unhelpful. The original query was "{query}". The retrieved chunks were: {chunks}. The generated answer was: "{answer}". Suggest how to modify the retrieval strategy (chunk size, embedding model, query rewriting, re-ranking) to improve future results.
Explanation: Continuous improvement is key. This prompt turns feedback into actionable changes.
Example usage:
prompt = f"""The user rated the previous answer as unhelpful. The original query was "How to install Python". The retrieved chunks were: ["Python is a programming language.", "Install Python by downloading from python.org."]. The generated answer was: "Python is a programming language." Suggest how to modify the retrieval strategy to improve future results.
"""
response = llm.invoke(prompt)
print(response)
11. Multi-Modal RAG Prompt
Task: Handle queries that mix text and image references.
Prompt:
You are a multi-modal RAG system. The user query refers to an image: "{image_description}". Your text context includes: {text_context}. Combine information from both to answer: "{query}". If the image is not referenced, ignore it.
Explanation: Many RAG systems now support images. This prompt handles cross-modal reasoning.
Example usage:
image_desc = "a bar chart showing sales growth from 2020 to 2025"
text_context = "Our company revenue increased steadily over the past five years."
query = "What does the chart show about revenue?"
prompt = f"""You are a multi-modal RAG system. The user query refers to an image: "{image_desc}". Your text context includes: {text_context}. Combine information from both to answer: "{query}". If the image is not referenced, ignore it.
"""
response = llm.invoke(prompt)
print(response)
12. End-to-End RAG Pipeline Prompt
Task: Design a complete RAG pipeline for a specific use case.
Prompt:
Design a complete RAG pipeline for [use case]. Include:
- Chunking strategy
- Embedding model
- Vector database choice
- Retrieval method (dense, sparse, hybrid)
- Query rewriting approach
- Re-ranking method
- LLM for generation
- Evaluation metrics
Justify each choice.
Explanation: This high-level prompt helps you architect a system from scratch.
Example usage:
use_case = "customer support chatbot for a SaaS platform"
prompt = f"""Design a complete RAG pipeline for {use_case}. Include:
- Chunking strategy
- Embedding model
- Vector database choice
- Retrieval method (dense, sparse, hybrid)
- Query rewriting approach
- Re-ranking method
- LLM for generation
- Evaluation metrics
Justify each choice.
"""
response = llm.invoke(prompt)
print(response)
Conclusion
These 12 prompts cover the entire RAG lifecycle—from indexing to generation to evaluation. Start by trying them on your own data. Remember that RAG is iterative: test, measure, refine. For deeper learning, refer to the LangChain documentation and the original RAG paper by Lewis et al. (2020). Happy building!
Sources: LangChain docs (https://python.langchain.com), "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (Lewis et al., 2020), Pinecone vector database documentation.
Comments