Skip to content
AI

RAG Cheat Sheet in Hindi: Retrieval-Augmented Generation

Updated 28 Oct 2026 5 min scan

RAG (Retrieval-Augmented Generation) एक AI technique है जिसकी मदद से Large Language Models (LLMs) को external documents, websites, databases और private knowledge से relevant information देकर बेहतर answers generate करवाए जा सकते हैं।

अगर आप AI chatbot, customer support assistant, documentation search या अपने educational platform के लिए AI-powered question-answering system बनाना चाहते हैं, तो RAG एक important concept है।

इस guide में हम RAG architecture, indexing pipeline, query pipeline, embeddings, vector databases, practical examples, security और interview questions को आसान Hinglish में समझेंगे।

1. RAG क्या है?#

RAG का full form है Retrieval-Augmented Generation.

यह एक approach है जिसमें AI model answer generate करने से पहले किसी external knowledge source से relevant information retrieve करता है। इसके बाद retrieved information को prompt के context में शामिल किया जाता है, ताकि model उस information के आधार पर answer दे सके।

Simple words में:

  • Retrieval: Relevant information search करना।
  • Augmented: Retrieved information से prompt को additional context देना।
  • Generation: LLM से final answer generate करवाना।

Real-world example

मान लीजिए आपने TheEasyMaster पर programming और AI से संबंधित सैकड़ों articles publish किए हैं।

एक user पूछता है:

“RAG और fine-tuning में क्या difference है?”

एक सामान्य LLM अपने learned knowledge के आधार पर जवाब देगा। लेकिन RAG-enabled chatbot पहले आपके published articles में relevant content search कर सकता है और फिर उन्हीं sources के आधार पर answer generate कर सकता है।

इससे chatbot आपके own content के साथ काम कर सकता है और users को संबंधित articles के links भी दे सकता है।

याद रखने वाली बात: RAG model को automatically retrain नहीं करता। यह inference के समय relevant external information retrieve करके model को context देता है।

2. RAG की जरूरत क्यों पड़ती है?#

LLMs powerful होते हैं, लेकिन हर application के लिए केवल model की existing knowledge पर्याप्त नहीं होती।

ProblemRAG कैसे मदद करता है?
Private data की जानकारी नहीं हैAuthorized internal documents retrieve कर सकता है
Knowledge बार-बार update होती हैUpdated documents को index करके नई information उपलब्ध कराई जा सकती है
Company-specific questionsInternal policies और documentation से relevant context मिल सकता है
Source verification जरूरी हैRetrieved documents के references answer के साथ दिए जा सकते हैं
बहुत सारे documents हैंRelevant passages search करके पूरा document पढ़ने की जरूरत कम हो सकती है
Domain-specific chatbot बनाना हैSelected knowledge base पर question-answering system बनाया जा सकता है

ध्यान रखें कि RAG hallucinations को पूरी तरह समाप्त नहीं करता। अगर retrieval गलत है, relevant information missing है या model context को गलत समझता है, तो answer फिर भी गलत हो सकता है।

3. RAG Architecture कैसे काम करता है?#

RAG system को समझने के लिए इसे दो major pipelines में divide करें:

  1. Indexing Pipeline — documents को search के लिए तैयार करना।
  2. Query Pipeline — user के question के आधार पर information retrieve करके answer generate करना।

3.1 Indexing Pipeline

इस stage में documents को process करके search index या vector database में store किया जाता है। यह आम तौर पर initial setup और document updates के समय चलता है।

Code
Documents / Website / PDFs
          |
          v
Extract, Clean & Chunk
          |
          v
Generate Embeddings
          |
          v
Search Index / Vector Database

हर step का काम:

  • Documents / Website / PDFs: Knowledge sources collect करना।
  • Extract: PDF, HTML या अन्य supported formats से text निकालना।
  • Clean: Unnecessary markup, duplicate content और unwanted text साफ करना।
  • Chunk: बड़े documents को छोटे passages में divide करना।
  • Generate Embeddings: Text को numerical vectors में convert करना।
  • Search Index: Vectors, text और metadata को searchable format में store करना।

3.2 Query Pipeline

जब user question पूछता है, तब query pipeline relevant information search करती है और LLM को context देती है।

Code
User Question
      |
      v
Retrieve Relevant Chunks
      |
      v
Add Context to Prompt
      |
      v
LLM Generates Answer
      |
      v
Answer + Source References

हर step का काम:

  • User Question: User अपना question submit करता है।
  • Retrieve Relevant Chunks: Search system संबंधित passages ढूँढता है।
  • Add Context to Prompt: Retrieved information को prompt में शामिल किया जाता है।
  • LLM Generates Answer: Model question और retrieved context के आधार पर response बनाता है।
  • Answer + Source References: Application answer के साथ supporting documents के links या references दिखा सकती है।

यह एक simplified architecture है। Production systems में query rewriting, metadata filtering, reranking, permission checks, caching और answer validation जैसे additional steps भी हो सकते हैं।

4. RAG के Important Components#

4.1 Data Ingestion

Data ingestion वह process है जिसमें knowledge sources से information collect करके processing pipeline में भेजी जाती है।

Sources के examples:

  • PDF और Word documents
  • Websites और documentation
  • MySQL या PostgreSQL databases
  • Company knowledge bases
  • Product catalogs
  • Support tickets
  • Approved internal APIs

उदाहरण के लिए, अगर आपको programming documentation पर chatbot बनाना है, तो ingestion process आपके approved documentation pages से content extract कर सकती है।

Important: हर source को blindly ingest नहीं करना चाहिए। Content quality, update frequency, access permissions और source reliability check करना जरूरी है।

4.2 Chunking

Chunking का मतलब बड़े document को छोटे text sections में divide करना है।

मान लीजिए एक article में 3,000 words हैं। User को उस article के केवल authentication वाले section की जरूरत है। पूरे article को retrieve करने के बजाय system relevant chunks retrieve कर सकता है।

Chunking के common approaches:

Approachकैसे काम करता है?कब उपयोगी है?
Fixed-size chunkingText को निर्धारित size के chunks में divide करता हैSimple documents और initial prototypes
Overlapping chunkingAdjacent chunks के बीच कुछ text repeat करता हैजब concepts या sentences chunk boundaries के पार जाते हों
Structure-based chunkingHeadings, paragraphs या sections के आधार पर split करता हैDocumentation और educational articles
Semantic chunkingMeaning या topic changes के आधार पर boundaries चुनता हैजब document की logical structure महत्वपूर्ण हो

एक chunk बहुत छोटा होगा, तो context अधूरा रह सकता है। बहुत बड़ा होगा, तो irrelevant information बढ़ सकती है।

इसलिए chunk size और overlap को अपने documents, embedding model और retrieval evaluation के अनुसार test करना चाहिए। कोई एक chunk size हर use case के लिए best नहीं होता।

4.3 Embeddings

Embedding text का numerical representation है, जिसे model semantic similarity और दूसरे supported operations के लिए इस्तेमाल कर सकता है।

उदाहरण:

  • “How can I reset my password?”
  • “Password reset करने का तरीका क्या है?”

इन दोनों sentences की wording अलग है, लेकिन meaning मिलता-जुलता है। एक suitable embedding model इनके semantic relationship को represent कर सकता है।

Embeddings का उपयोग semantic search में किया जाता है, जहाँ system केवल exact keywords नहीं बल्कि meaning के आधार पर भी relevant content खोजने की कोशिश करता है।

एक simplified flow:

Code
Text Chunk
    |
    v
Embedding Model
    |
    v
Numerical Vector
    |
    v
Vector Index

याद रखें: Embedding model और LLM अलग roles निभाते हैं। Embedding model text representation बनाता है; LLM final natural-language answer generate कर सकता है।

Related topic: Embeddings / Vector Database Cheat Sheet

4.4 Vector Database

Vector database या vector store embeddings को store और search करने के लिए इस्तेमाल किया जाता है।

Common options में शामिल हैं:

  • PostgreSQL with pgvector
  • Qdrant
  • Weaviate
  • Milvus
  • Pinecone

इनमें से किसी एक का चुनाव project की requirements, deployment model, budget, scale, filtering needs और operational complexity पर निर्भर करता है।

एक RAG system में केवल vectors ही नहीं, बल्कि source IDs, document URLs, headings, timestamps और access-control metadata भी store करना उपयोगी होता है।

4.5 Retrieval

Retrieval वह step है जिसमें user question के लिए सबसे relevant documents या chunks खोजे जाते हैं।

उदाहरण:

User question: “Symfony में environment variables कहाँ configure होते हैं?”

Search system उन passages को retrieve करने की कोशिश करेगा जिनमें Symfony configuration और environment variables की relevant जानकारी हो।

Common retrieval approaches:

  • Keyword search: Exact words और text matching पर आधारित।
  • Vector search: Embeddings के आधार पर semantic similarity search।
  • Hybrid search: Keyword और vector search को combine करना।

4.6 Top-K Retrieval

Top-K का मतलब search results में से सबसे relevant माने गए K results चुनना है।

उदाहरण के लिए, अगर K = 5 है, तो retrieval system पाँच candidate chunks return कर सकता है।

लेकिन अधिक chunks हमेशा बेहतर नहीं होते। बहुत सारे irrelevant chunks model को confuse कर सकते हैं और prompt में अनावश्यक content बढ़ा सकते हैं।

इसलिए Top-K को retrieval quality, context window और application requirements के आधार पर evaluate करें।

4.7 Metadata Filtering

Metadata document के बारे में additional information होती है।

उदाहरण:

Code
{
  "document_id": "article-101",
  "title": "RAG Cheat Sheet",
  "category": "AI",
  "language": "Hindi",
  "source_url": "https://theeasymaster.com/"
}

इस example में metadata search को AI category या Hindi content तक सीमित करने में मदद कर सकता है, यदि search system इन fields पर filtering support करता हो।

Production applications में tenant ID, document permissions और classification जैसे security-related metadata भी आवश्यक हो सकते हैं।

4.8 Context Construction

Relevant chunks retrieve होने के बाद application उन्हें LLM prompt में जोड़ती है।

एक simplified prompt example:

Code
System:
Answer the user's question using the supplied context.
If the context does not contain enough information,
say that the answer is not available in the provided sources.

Context:
[Retrieved document passages]

Question:
What is Retrieval-Augmented Generation?

Instructions:
Provide a clear explanation and cite the relevant sources.

यह केवल एक illustrative prompt है। वास्तविक implementation में model-specific formatting, source identifiers, context limits और security instructions की जरूरत हो सकती है।

4.9 Answer Generation and Citations

LLM question और retrieved context के आधार पर final response generate करता है।

Application source references को retrieved documents से जोड़ सकती है, ताकि user original content खोलकर information verify कर सके।

ध्यान दें: Model द्वारा बनाया गया citation अपने आप सही साबित नहीं हो जाता। Application को verify करना चाहिए कि cited source वास्तव में retrieve किया गया था और उसमें संबंधित claim मौजूद है।

5. RAG का Practical Example#

मान लीजिए आप TheEasyMaster के लिए AI learning assistant बना रहे हैं।

User question:

“JavaScript में Promise क्या होता है?”

Knowledge base में JavaScript के articles पहले से मौजूद हैं।

System का flow कुछ ऐसा होगा:

  1. User question submit करता है।
  2. Application question को search के लिए तैयार करती है।
  3. Search index से Promise और asynchronous JavaScript से जुड़े relevant chunks retrieve होते हैं।
  4. Application retrieved chunks और source metadata को prompt में जोड़ती है।
  5. LLM आसान Hinglish में explanation generate करता है।
  6. Application answer के साथ relevant article links दिखाती है।

इस तरह chatbot केवल generic answer देने के बजाय आपके learning content से grounded answer दे सकता है।

Practical use cases:

  • Educational website assistant
  • Company documentation chatbot
  • Customer support knowledge assistant
  • Product information assistant
  • Internal policy search
  • Technical documentation Q&A

6. RAG vs Fine-Tuning vs Normal LLM#

इन तीनों approaches के purposes अलग-अलग हैं।

FeatureNormal LLMRAGFine-tuning
External documents retrieve करता हैBy default नहींहाँBy default नहीं
Frequently updated knowledgeExternal retrieval के बिना सीमितIndex update करके उपलब्ध कराई जा सकती हैTraining data और process के अनुसार फिर से fine-tuning की जरूरत हो सकती है
Private knowledge accessExplicit integration के बिना नहींAuthorized data retrieve कर सकता हैTraining में शामिल information model behavior को प्रभावित कर सकती है, लेकिन यह document retrieval का substitute नहीं है
Output style या task behavior बदलनाPrompting से कुछ हद तकPrompting और context से कुछ हद तककुछ tasks में उपयोगी
Source citationsApplication को implement करना पड़ता हैRetrieved sources से जोड़े जा सकते हैंFine-tuning अपने आप source citations नहीं देती
Main complexityPrompt और model selectionIngestion, search, permissions और evaluationTraining data, training process और evaluation

कौन-सा चुनें?

  • Latest या private documents से answers चाहिए: RAG पर विचार करें।
  • Consistent output style या specialized task behavior चाहिए: Fine-tuning उपयोगी हो सकती है।
  • General questions के लिए simple assistant चाहिए: Normal LLM और prompting पर्याप्त हो सकते हैं।

कुछ applications में RAG और fine-tuning दोनों का उपयोग किया जा सकता है।

7. RAG Evaluation कैसे करें?#

सिर्फ यह देखना पर्याप्त नहीं है कि chatbot answer दे रहा है। आपको यह भी check करना चाहिए कि सही documents retrieve हो रहे हैं और final answer grounded है।

Retrieval Evaluation

  • Precision@K: Retrieved top-K results में relevant results का अनुपात।
  • Recall@K: उपलब्ध relevant results में से top-K में कितने retrieve हुए।
  • MRR (Mean Reciprocal Rank): Relevant result कितनी जल्दी search ranking में दिखाई देता है।
  • NDCG: Search ranking में relevant results की position और relevance को ध्यान में रखने वाला metric।

इन metrics के लिए कई मामलों में labelled evaluation queries या expected relevant documents की जरूरत होती है।

Answer Evaluation

  • Groundedness: क्या answer supplied context से supported है?
  • Relevance: क्या answer user के question को address करता है?
  • Completeness: क्या जरूरी information शामिल है?
  • Citation accuracy: क्या citations वास्तव में संबंधित claims को support करते हैं?

एक छोटी evaluation dataset बनाएँ जिसमें सामान्य questions, difficult questions, ambiguous queries और ऐसे questions शामिल हों जिनके answers knowledge base में मौजूद नहीं हैं।

हर change के बाद retrieval और answer quality को दोबारा test करें।

Reference: Microsoft — RAG Evaluators

8. Advanced RAG Techniques#

Basic RAG हर situation में पर्याप्त नहीं होता। Complex systems में retrieval quality और answer reliability सुधारने के लिए additional techniques इस्तेमाल की जा सकती हैं।

8.1 Hybrid Search

Keyword search और vector search को combine किया जाता है।

यह तब उपयोगी हो सकता है जब query में exact product IDs, error codes, function names या technical terms हों और semantic meaning भी महत्वपूर्ण हो।

8.2 Reranking

पहले search system candidate chunks retrieve करता है। फिर reranker उन candidates को query के हिसाब से दोबारा score और reorder करता है।

इससे final context में अधिक relevant passages लाने में मदद मिल सकती है।

8.3 Query Rewriting

कभी user का question vague या incomplete होता है।

उदाहरण:

“इसमें error क्यों आ रहा है?”

अगर conversation में पहले Symfony की बात हुई थी, तो system question को अधिक specific search query में rewrite कर सकता है।

8.4 Metadata Enrichment

Documents के साथ headings, topics, summaries, timestamps और source information जोड़ने से filtering और retrieval बेहतर हो सकते हैं।

8.5 Agentic RAG

Agentic RAG में AI system एक से अधिक retrieval steps या tools का उपयोग कर सकता है। वह जरूरत के अनुसार query rewrite कर सकता है, अलग sources search कर सकता है या initial results के बाद additional retrieval कर सकता है।

लेकिन agentic approach की complexity अधिक हो सकती है। इसलिए इसे तभी चुनें जब simple retrieval pipeline आपके use case के लिए पर्याप्त न हो।

More details: Microsoft — RAG and Indexes

9. RAG Security और Best Practices#

RAG में external content LLM के context में आता है। इसलिए security केवल chatbot prompt तक सीमित नहीं रहनी चाहिए।

Important security practices

  1. Access control: User को केवल वही documents retrieve करने दें जिन्हें देखने की उसे permission है।
  2. Trusted sources: Approved data sources से ही ingestion करें और document provenance track करें।
  3. Prompt injection protection: Retrieved documents में malicious instructions हो सकती हैं। Retrieved content को untrusted data की तरह handle करें।
  4. Sensitive data protection: Secrets, credentials और personal information को अनावश्यक रूप से context या logs में expose न करें।
  5. Output validation: High-risk workflows में generated output को validate किए बिना execute न करें।
  6. Tenant isolation: Multi-tenant applications में एक customer का data दूसरे customer को retrieve नहीं होना चाहिए।
  7. Document updates and deletion: Source document update या delete होने पर संबंधित chunks, embeddings और caches को भी update या invalidate करें।
  8. Monitoring: Retrieval errors, access-control failures और unusual query patterns की monitoring करें।
  9. Source verification: Answer में दिखाए गए references को actual retrieved documents से validate करें।
  10. Evaluation: Prompt injection, unauthorized retrieval और incorrect citations के लिए tests शामिल करें।

Important: Retrieved document के अंदर लिखी instruction को automatically trusted system instruction नहीं मानना चाहिए। Prompting अकेले complete security solution नहीं है; permissions और validation application level पर enforce होने चाहिए।

Official security guide: OWASP — RAG Security Cheat Sheet

10. Common RAG Mistakes#

MistakeProblemBetter approach
Poor chunkingRelevant information split या lost हो सकती हैStructure और content के अनुसार chunking test करें
केवल vector search पर निर्भर रहनाExact identifiers या terms miss हो सकते हैंजरूरत के अनुसार hybrid search evaluate करें
बहुत अधिक chunks retrieve करनाIrrelevant context और latency बढ़ सकती हैTop-K और reranking tune करें
Outdated indexAnswer पुरानी information पर आधारित हो सकता हैDocument update और re-indexing workflow बनाएँ
Missing access controlsUnauthorized information leak हो सकती हैRetrieval से पहले permissions enforce करें
Citations verify न करनाIncorrect references दिख सकते हैंSource IDs और claims validate करें
केवल answer quality test करनाRetrieval problems छिप सकती हैंRetrieval और generation दोनों evaluate करें
RAG को hallucination-proof माननागलत या unsupported answers फिर भी आ सकते हैंGrounding checks और fallback behavior implement करें

11. Quick Reference#

TermMeaning
RAGRetrieval-Augmented Generation
LLMLarge Language Model
IngestionData collect और process करना
ChunkingDocuments को छोटे passages में divide करना
EmbeddingText का numerical representation
Vector DatabaseVector storage और similarity search के लिए system
RetrievalRelevant documents या chunks खोजना
Top-Kचुने गए top K search results
MetadataDocument से संबंधित additional information
Contextवह information जो model को answer बनाने के लिए दी जाती है
RerankingRetrieved results को दोबारा score और reorder करना
Hybrid SearchKeyword और vector search को combine करना
GroundednessAnswer का provided context से supported होना
Agentic RAGRetrieval और related steps में agent-driven decisions का उपयोग

12. RAG Interview Questions#

Beginner Level

1. RAG का full form क्या है?

Retrieval-Augmented Generation. यह external information retrieve करके LLM के answer-generation process को augment करता है।

2. RAG की जरूरत क्यों होती है?

जब application को private, domain-specific या frequently updated information के आधार पर answers देने हों, तब RAG उपयोगी हो सकता है।

3. Chunking क्या है?

बड़े documents को छोटे passages में divide करने की प्रक्रिया, ताकि search system relevant information retrieve कर सके।

4. Embeddings क्या हैं?

Text की numerical representations, जिनका उपयोग semantic similarity और vector search जैसे tasks में किया जा सकता है।

5. Vector database का क्या काम है?

यह embeddings को store और search करने में मदद करता है। कई systems metadata और source information भी store करते हैं।

Intermediate Level

6. RAG और fine-tuning में क्या difference है?

RAG answer generate करते समय external information retrieve करता है। Fine-tuning model के behavior को training के माध्यम से adapt करती है। दोनों अलग purposes serve करते हैं।

7. Top-K retrieval क्या है?

Search results में से चुने गए K candidates return करना। सही K value को evaluate करके तय करना चाहिए।

8. Hybrid search क्या है?

Keyword-based search और vector-based search को combine करना।

9. RAG में hallucinations कैसे कम कर सकते हैं?

Relevant retrieval, clear prompts, source validation, groundedness evaluation और insufficient-context handling से risk कम किया जा सकता है। इसे पूरी तरह eliminate करने की guarantee नहीं है।

10. RAG application को secure कैसे करेंगे?

Access control, trusted ingestion, tenant isolation, prompt-injection defenses, output validation, monitoring और data deletion workflows implement करेंगे।

13. Practice Exercises#

इन exercises को करके RAG architecture की practical understanding develop करें।

  • Exercise 1: पाँच programming articles collect करें और उनकी headings तथा paragraphs identify करें।
  • Exercise 2: एक article को structure-based chunks में divide करें और देखें कि हर chunk अपने आप में कितना meaningful है।
  • Exercise 3: दो similar questions लिखें और समझें कि semantic search क्यों उपयोगी हो सकती है।
  • Exercise 4: एक RAG chatbot का architecture diagram बनाएँ जिसमें ingestion, embeddings, retrieval और generation शामिल हों।
  • Exercise 5: दस test questions तैयार करें और evaluate करें कि सही sources retrieve हो रहे हैं या नहीं।
  • Exercise 6: ऐसे questions भी test करें जिनका answer आपके knowledge base में मौजूद नहीं है।
  • Exercise 7: Source citations जोड़ने का design बनाएँ और verify करें कि हर reference सही document को point करता है।

14. Summary#

RAG एक practical AI architecture है जो LLMs को external knowledge sources से relevant information retrieve करके grounded answers generate करने में मदद करता है।

इसके core components हैं:

  • Data ingestion और cleaning
  • Chunking और embeddings
  • Search index या vector database
  • Retrieval और context construction
  • LLM-based answer generation
  • Source attribution और evaluation
  • Security, permissions और monitoring

अगर आप RAG सीख रहे हैं, तो पहले basic indexing और query pipeline समझें। उसके बाद chunking, embeddings, vector search और evaluation को practical examples के साथ implement करें।

याद रखें: एक अच्छा RAG system केवल अच्छा LLM नहीं होता — उसकी retrieval quality, data quality, security और evaluation भी उतनी ही महत्वपूर्ण होती हैं।

RAG को बेहतर समझने के लिए ये topics भी पढ़ें: