Skip to content
项目

关于

Production-ready prompt templates for Retrieval-Augmented Generation — grounded answers, no hallucination

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
正在收集历史
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

RAG Prompt Templates

Stars License

Production-ready prompt templates for Retrieval-Augmented Generation systems.


What is RAG?

RAG (Retrieval-Augmented Generation) combines document retrieval with LLM generation. Instead of relying solely on training data, the model receives relevant document chunks at query time.

User Query
    ↓
Vector Search (retrieve top-k documents)
    ↓
Prompt = System + Retrieved Documents + User Query
    ↓
LLM generates answer grounded in retrieved content

Why RAG needs specialized prompts:

  • Must instruct the model to use ONLY retrieved content
  • Must handle cases where retrieved content is insufficient
  • Must prevent hallucination when documents don't contain the answer
  • Must handle contradictions between multiple retrieved documents

Core Templates

Basic RAG Template

You are a question-answering assistant. Answer the user's question using ONLY the provided context.

RULES:
1. Use only information from the CONTEXT section
2. If the context does not contain enough information to answer, say: "I don't have enough information to answer this question."
3. Do not use prior knowledge beyond what is in the context
4. Cite the source document when possible

CONTEXT:
{retrieved_documents}

QUESTION: {user_question}

ANSWER:

Multi-Document RAG Template

You are an expert assistant. Answer the question based on the provided documents.

DOCUMENTS:
[Document 1 - {source_1}]: {content_1}
[Document 2 - {source_2}]: {content_2}
[Document 3 - {source_3}]: {content_3}

INSTRUCTIONS:
- Synthesize information from multiple documents when relevant
- If documents contradict each other, note the contradiction and explain both perspectives
- Always cite which document(s) support each claim: (Source: Document N)
- If none of the documents answer the question, state this clearly

QUESTION: {question}

Conversational RAG Template

You are a helpful assistant with access to a knowledge base.
Previous conversation is provided for context, but base your answer on the RETRIEVED CONTEXT.

CONVERSATION HISTORY:
{chat_history}

RETRIEVED CONTEXT:
{context}

CURRENT QUESTION: {question}

Answer based on the retrieved context. If the context doesn't address the question,
acknowledge this and suggest what information would be needed.

Strict RAG Template (No Hallucination)

SYSTEM: You are a document-based Q&A system.
CRITICAL RULE: You may ONLY use information explicitly stated in the provided documents.
You must NOT:
- Infer beyond what is written
- Use general knowledge
- Make assumptions
- Extrapolate from similar situations

If the exact answer is not in the documents, respond with:
"The provided documents do not contain information about [specific topic]."

DOCUMENTS:
{documents}

QUERY: {query}

RAG with Confidence Scoring

Answer the following question based on the provided context.
After your answer, provide a confidence score (0-100) based on how well the context supports your answer.

Confidence scale:
- 90-100: Answer is explicitly stated in context
- 70-89: Answer is strongly implied by context
- 50-69: Answer can be inferred with some uncertainty
- Below 50: Context is insufficient; answer may be unreliable

CONTEXT: {context}
QUESTION: {question}

Answer: [your answer]
Confidence: [0-100]
Reasoning: [why this confidence level]

Anti-Patterns in RAG Prompts

Anti-Pattern Problem Fix
No explicit "use only context" instruction Model mixes context with training data Add strict "ONLY use provided context" rule
No insufficient-context handler Model hallucinates when context is empty Add explicit fallback instruction
Mixing system context with documents Model confuses instructions with content Use clear structural delimiters
No citation requirement Unverifiable answers Require source citation

Multilingual

TR: RAG, belge getirme ile dil modeli üretimini birleştiren bir yapay zeka tekniğidir. DE: RAG kombiniert Dokumentenabfrage mit LLM-Generierung für fundierte Antworten. FR: RAG combine la récupération de documents avec la génération LLM pour des réponses fondées. ES: RAG combina recuperación de documentos con generación LLM para respuestas fundamentadas. ZH: RAG将文档检索与LLM生成相结合,提供基于文档的答案。 RU: RAG сочетает поиск документов с генерацией LLM для обоснованных ответов. JA: RAGは文書検索とLLM生成を組み合わせた根拠のある回答技術です。 KO: RAG는 문서 검색과 LLM 생성을 결합하여 근거 있는 답변을 제공합니다.


License

MIT — Free to use, modify, and distribute.

Keywords

RAG prompts retrieval augmented generation RAG templates document QA prompts LLM RAG vector search prompts grounded generation no hallucination prompts RAG system design document retrieval prompts knowledge base QA RAG prompt şablonları RAG-Vorlagen modèles RAG plantillas RAG RAG提示模板 RAG промпты RAGプロンプト RAG 프롬프트 템플릿

探索相关项目

加载中…