सरल भाषा में
कल्पना कीजिए कि किसी विशाल लाइब्रेरी की हर चीज़ सीखने के दो तरीके हैं। पहला तरीका: आप हर पन्ने की फ़ोटो खींच लेते हैं, और जब सवाल आता है तो दृश्य समानता के आधार पर खोजते हैं — यानी ऐसे पन्ने मिलते हैं जो आपके query से मिलते-जुलते दिखते हैं। यह vector RAG है। दूसरा तरीका: एक लाइब्रेरियन हर किताब पढ़ता है और हर व्यक्ति, जगह, concept और घटना को नाम से जोड़ते हुए एक विशाल नक्शा बनाता है — "Einstein worked at Princeton", "Princeton is in New Jersey", "E=mc2 was published in 1905"। जब आप सवाल पूछते हैं, तो लाइब्रेरियन सिर्फ़ मिलते-जुलते पन्ने नहीं देखता; वह connections को ट्रेस करता है। इसी को GraphRAG कहते हैं।

GraphRAG (Graph Retrieval-Augmented Generation) एक architecture है जो पहले आपके दस्तावेज़ों को एक knowledge graph में बदलता है — entities (लोग, संगठन, concepts, जगहें, products) का एक नेटवर्क, जो typed relationships से जुड़ा होता है — और फिर सिर्फ़ text chunks मिलाने के बजाय उस graph में traverse करके जवाब निकालता है। जहाँ vector RAG कहता है "सबसे ज़्यादा semantically मिलते-जुलते passages ढूँढो", वहीं GraphRAG कहता है "इसमें शामिल entities ढूँढो और उनके connections को फ़ॉलो करो"।
इस तरीके को Microsoft Research ने 2024 के paper From Local to Global: A Graph RAG Approach to Query-Focused Summarization में औपचारिक रूप दिया। इसके साथ एक open-source Python implementation भी आया (pip install graphrag), जिसे जुलाई 2024 में रिलीज़ होने के कुछ ही हफ़्तों में 20,000 से ज़्यादा GitHub stars मिले।
यह क्यों मायने रखता है
Standard vector RAG की एक अच्छी तरह समझी गई कमज़ोरी है: यह स्थानीय, single-hop सवालों ("Document X में Y के बारे में क्या लिखा है?") में अच्छा करता है, लेकिन ऐसे सवालों में अटक जाता है जिनमें कई documents में बिखरी जानकारी को जोड़ना पड़ता है। Embedding model ऐसे chunks ढूँढता है जो query से स्थानीय रूप से मिलते हों, लेकिन दर्जनों source documents तक फैली तथ्यों की श्रृंखला को जोड़ने का उसके पास कोई तरीका नहीं है।
ऐसे सवालों पर विचार कीजिए जो vector RAG को तोड़ देते हैं:
- Global sensemaking। "मुझे हमारी 500 quarterly reports में बताए गए सभी risk factors का थीमैटिक सारांश दीजिए।" किसी एक chunk में यह जवाब नहीं होता। Vector search सबसे मिलते-जुलते passages लौटाता है, लेकिन आपको पूरी तस्वीर चाहिए।
- Multi-hop relationship questions। "हमारे कौन-से engineers ने उस team के साथ सहयोग किया जिसने authentication module बनाया था?" इसका जवाब देने के लिए ट्रेसिंग करनी पड़ती है: person → team → project → module — यानी अलग-अलग documents में रहने वाली entities के बीच चार hops।
- Cross-document entity tracking। "remote work पर हमारे CEO की स्थिति पिछले तीन सालों में कैसे बदली है?" CEO ने जहाँ-जहाँ इस विषय पर बात की, वे सभी मौके ढूँढने, उन्हें सही तरीके से attribute करने और तुलना करने होंगे — सिर्फ़ query string से सबसे मिलता-जुलता passage काफ़ी नहीं है।
- Implicit connectivity। दो documents एक-दूसरे का नाम कभी नहीं लेते, लेकिन दोनों एक ही अनाम acquisition target की चर्चा करते हैं। एक graph जो उन्हें साझा entities के ज़रिए जोड़ता है, यह संबंध सामने ला देता है; अकेली vector similarity ऐसा नहीं कर पाएगी।
Research benchmarks इस अंतर की पुष्टि करते हैं: जटिल multi-hop कार्यों पर GraphRAG लगातार 80-85% accuracy तक पहुँचता है, जबकि vector RAG लगभग 45-50% पर अटक जाता है। Compliance और healthcare domains में, जहाँ queries को सचमुच multi-hop traversal चाहिए, baseline vector RAG की तुलना में 3-4x सुधार दर्ज किए गए हैं। Microsoft के मूल paper में दिखाया गया कि उसी corpus पर naive vector RAG की तुलना में multi-hop सवालों पर hallucination rate में 40% की कमी आई।
Builders के लिए व्यावहारिक संकेत यह है: अगर आपकी vector RAG pipeline evaluation में सरल lookups पर अच्छे अंक लाती है, लेकिन उन जटिल सवालों पर ढह जाती है जिनकी आपके users को सबसे ज़्यादा परवाह है, तो GraphRAG अगला स्वाभाविक कदम है जिसे जाँचना चाहिए।
यह कैसे काम करता है
GraphRAG अपना काम दो अलग चरणों में बाँटता है: offline indexing (आपके दस्तावेज़ों से graph बनाना) और online querying (सवाल के समय उसी से जानकारी लाना)। दोनों चरण LLM-heavy हैं — यह सिर्फ़ graph database की समस्या नहीं है।
Phase 1: Indexing — knowledge graph बनाना
Pipeline आपके source documents को छोटी text units में बाँटकर शुरू होती है — आमतौर पर हर unit 300 से 600 tokens की, लगभग सामान्य RAG chunking जैसी। फिर हर chunk के लिए एक LLM entity extraction चलाता है: वह सभी named entities (लोग, संगठन, स्थान, products, concepts) और उनके बीच के सभी relationships पहचानता है, और {"entity": "Alice", "type": "Person"} तथा {"source": "Alice", "relation": "works_at", "target": "Acme Corp"} जैसा structured output देता है। LLM token की लागत इसी extraction step में सबसे ज़्यादा जमा होती है — Microsoft GraphRAG की default configuration प्रति chunk 4-6 LLM calls करती है।
सभी entities और relationships निकल जाने के बाद, एक जैसी entities chunks के पार merge कर दी जाती हैं ("Alice" अगर 50 अलग documents में आती है, तो वह एक node बनती है जिसके 50 source edges होते हैं) और सब मिलकर एक knowledge graph बनता है, जो nodes और edges के रूप में संग्रहित होता है। Graph को Neo4j जैसे graph database में रखा जा सकता है, या open-source implementation की default व्यवस्था की तरह flat Parquet files में।
आख़िरी indexing step है community detection। GraphRAG Leiden algorithm लगाता है — एक hierarchical graph-clustering method — ताकि entity graph को निकट से जुड़े nodes के communities में समूहित किया जा सके। Community को ऐसे cluster की तरह समझिए जैसे "हमारे authentication system से जुड़ी सभी entities" या "यूरोपीय sales team के सभी लोग"। Hierarchy के हर स्तर पर हर community के लिए LLM एक community summary report बनाता है — एक paragraph जो बताता है कि उस entity cluster में क्या है। ये summaries global सवालों का जवाब देने का मुख्य आधार हैं।
Phase 2: Querying — दो अलग search modes
Query के समय Microsoft GraphRAG सवाल की प्रकृति के आधार पर दो मुख्य modes देता है:
Local search उन सवालों के लिए है जो किसी विशिष्ट, नामित entity के बारे में हों। सिस्टम graph में प्रासंगिक entities ढूँढता है, फिर उनके तत्काल पड़ोसियों और relationships तक फैलता है, और उन entities से जुड़े मूल source text chunks भी लाता है। यह structured graph data और unstructured source text को मिलाकर जवाब को आधार देता है — specific entity सवालों पर सटीक, और तेज़।
Global search उन सवालों के लिए है जिनमें पूरे corpus की जानकारी को संश्लेषित करना पड़ता है — वे "थीमैटिक overview" और "cross-document" सवाल, जिन पर vector RAG विफल होता है। अलग-अलग chunks मिलाने के बजाय, global search पहचानता है कि कौन-से community summaries सवाल से प्रासंगिक हैं, और LLM को निर्देश देता है कि उन summaries को context मानकर जवाब दे। चूँकि community summaries पहले ही हर entity cluster का सार पकड़ने के लिए लिखी गई हैं, मॉडल हर source document पढ़े बिना पूरे corpus पर एक सुसंगत जवाब संश्लेषित कर सकता है।
DRIFT search (Microsoft Research ने 2024 के अंत में पेश किया) एक हाइब्रिड है जो खुद को दिशा देने के लिए global community context से शुरू करता है, फिर विशिष्ट बातों के लिए local entity traversal से zoom in करता है — global कवरेज को entity-स्तर के lookup की सटीकता के साथ जोड़ते हुए।
GraphRAG बनाम vector RAG: कब कौन जीतता है
यह मूल रूप से इस पर निर्भर करता है कि आपके users किस तरह के सवाल पूछते हैं। कोई भी तरीका सार्वभौमिक रूप से बेहतर नहीं है — वे accuracy बनाम cost के tradeoff curve पर अलग-अलग स्थानों पर हैं।
| पैमाना | Vector RAG | GraphRAG |
|---|---|---|
| सबसे अच्छा सवाल प्रकार | Single-hop, विशिष्ट lookup | Multi-hop, संबंध-आधारित, global संश्लेषण |
| Indexing लागत | कम — केवल embedding calls | ज़्यादा — हर chunk पर LLM calls, 20-100x ज़्यादा |
| Indexing समय | मिनट से घंटे | बड़े corpus के लिए घंटों से दिनों तक |
| Query लागत | कम — एक embedding + ANN search | मध्यम से ज़्यादा — summaries पर LLM संश्लेषण |
| Multi-hop accuracy | Benchmarks पर 45-50% | Benchmarks पर 80-85% |
| Global sensemaking | कमज़ोर — मिलते-जुलते chunks लौटाता है, संश्लेषण नहीं | मज़बूत — community summaries पूरे corpus पर जवाब संभव बनाती हैं |
| Setup की जटिलता | कम — खड़ा करने में कुछ दिन | ज़्यादा — ontology के काम में हफ़्ते से महीने |
| Update लागत | सस्ता — बदले chunks को फिर से embed करें | महँगा — entity बदलावों के लिए graph rebuild |
एक व्यावहारिक निर्णय नियम: vector RAG से शुरू करें और मापें। एक evaluation suite चलाएँ जिसमें सरल lookups और जटिल multi-hop सवाल, दोनों शामिल हों। अगर सरल सवालों पर आपकी accuracy मज़बूत है लेकिन जटिल सवालों पर तेज़ी से गिरती है, तो यही वह अंतर है जिसे GraphRAG भरता है। अगर आपका traffic ज़्यादातर सरल lookups हैं, तो GraphRAG बिना किसी लाभ के लागत बढ़ाता है।
Hybrid approach production में तेज़ी से मानक बनता जा रहा है: ज़्यादातर सरल queries के लिए vector retrieval इस्तेमाल करें (तेज़, सस्ता, काफ़ी सटीक), और जिन विशिष्ट सवाल प्रकारों को relational reasoning चाहिए, उनके लिए GraphRAG को ऊपर लगाएँ। एक query classifier हर आने वाले सवाल को complexity संकेतों के आधार पर सही pipeline पर भेजता है — सरल factoid सवाल तेज़ vector path पर जाते हैं; जटिल संबंध और संश्लेषण वाले सवाल GraphRAG पर।
Tools और ecosystem
GraphRAG का एक बढ़ता हुआ tooling ecosystem है, जो तीन परतों पर केंद्रित है: graph extraction pipeline, graph database, और query interface।
Microsoft GraphRAG (open source)
Microsoft Research का reference implementation एक Python package है (pip install graphrag) जो पूरी indexing pipeline को बॉक्स से बाहर सँभालता है — chunking, LLM के ज़रिए entity extraction, graph construction, Leiden clustering, और community summary generation। यह graph को Parquet files में संग्रहित करता है और indexing व querying दोनों के लिए CLI commands देता है। Configuration एक YAML file से होती है, जहाँ आप अपना LLM (डिफ़ॉल्ट रूप से Azure OpenAI के ज़रिए या OpenAI API पर कोई OpenAI model), chunk sizes, और निकालने वाले entity types निर्दिष्ट करते हैं।
pip install graphrag
# Initialize a new project
python -m graphrag init --root ./my-project
# Place your .txt/.pdf source files in ./my-project/input/
# Edit ./my-project/settings.yaml to configure your LLM
# Run the full indexing pipeline (this will call the LLM for every chunk)
python -m graphrag index --root ./my-project
# Query with global search (corpus-wide synthesis)
python -m graphrag query --root ./my-project --method global "What are the main themes across all documents?"
# Query with local search (specific entity lookup)
python -m graphrag query --root ./my-project --method local "Who is responsible for the authentication module?"Neo4j + LangChain / LlamaIndex
Neo4j GraphRAG deployments के लिए सबसे व्यापक रूप से अपनाया गया graph database है। Neo4j एक GraphRAG Python package और एक Knowledge Graph Builder भेजता है — एक UI tool जो LLM extraction के ज़रिए unstructured documents को Neo4j graph में बदलता है। LangChain Neo4jGraph और GraphCypherQAChain के ज़रिए Neo4j से जुड़ता है, जिससे natural-language queries को Cypher graph queries में बदला जा सकता है। LlamaIndex एक PropertyGraphIndex देता है, जिसका Neo4jPropertyGraphStore backend GraphRAG वाले community detection और summarization pattern को लागू करता है।
वैकल्पिक graph databases
FalkorDB खुद को GraphRAG-native database के रूप में पेश करता है, जिसकी indexing लागत Neo4j से कम है। ArangoDB एक hybrid graph + vector store देता है, जो combined GraphRAG queries सपोर्ट करता है। Production deployments के लिए, जिन्हें बार-बार अपडेट करना पड़ता है, ये खास तौर पर बने विकल्प graph rebuild की उस लागत को घटा सकते हैं जो standard GraphRAG को बनाए रखने में महँगी पड़ती है।
गहराई से समझें
लागत का समीकरण ही अपनाने की मुख्य बाधा है। GraphRAG से indexing करना embedding-only indexing से 20-100x ज़्यादा महँगा है, क्योंकि हर source chunk के लिए कई LLM calls लगते हैं। 2,000 chunks में बँटे 1 million tokens वाले corpus के लिए, केवल entity और relationship extraction में 8,000-12,000 LLM calls लगेंगे, साथ ही community summarization के अतिरिक्त calls। Frontier-model pricing पर, एक मध्यम आकार के enterprise corpus के लिए यह सैकड़ों डॉलर तक जा सकता है। उभरता हुआ समाधान: extraction के लिए एक सस्ता, तेज़ model (जैसे GPT-5 mini या Claude Haiku जैसा छोटा tier, या कोई fine-tuned local model) इस्तेमाल करें, और मज़बूत model केवल community summarization के लिए रखें, जहाँ output की गुणवत्ता ज़्यादा मायने रखती है।
Graph की ताज़गी सबसे बड़ी operational चुनौती है। जब आपके documents अपडेट होते हैं — नई reports, बदली नीतियाँ, नए लोग जुड़ते हैं — तो knowledge graph को उन बदलावों को दर्शाना होता है। Vector store के उलट, जहाँ आप बदले chunks को अलग से फिर embed कर सकते हैं, graph अपडेट के लिए पूरे graph पर entity deduplication और community detection फिर से चलाने पड़ सकते हैं, जिससे पूरा rebuild हो सकता है। Production systems इसका हल incremental graph updates से करते हैं: नई entities को delta nodes के रूप में जोड़ा जाता है, community detection केवल प्रभावित subgraph पर दोबारा चलता है, और community summaries केवल बदली communities के लिए फिर से बनती हैं। Microsoft GraphRAG के roadmap में incremental indexing support शामिल है, और FalkorDB जैसे third-party graph databases ने इसे अपने core offering में बना लिया है।
Leiden algorithm समझने लायक है। Leiden clustering — community detection के लिए Louvain algorithm का एक सुधार — hierarchical ढंग से काम करता है: यह पहले मोटे स्तर पर communities पहचानता है, फिर हर community को तब तक recursively उप-विभाजित करता है जब तक leaf clusters न मिल जाएँ जिन्हें और नहीं बाँटा जा सकता। यही बहु-स्तरीय hierarchy GraphRAG को अलग-अलग granularity पर सवालों का जवाब देने की क्षमता देती है: बहुत व्यापक सवाल का जवाब सबसे ऊपर के community summaries (पूरे corpus का सार देने वाले कुछ दर्जन clusters) से मिलता है; संकीर्ण सवाल किसी खास sub-community के summary में गहराई से जा सकता है। Hierarchy की गहराई एक tunable parameter है — गहरी hierarchies बारीक granularity देती हैं, लेकिन बनाने और संग्रह करने में ज़्यादा लागत लगती है।
Adaptive RAG की ओर ही क्षेत्र बढ़ रहा है। Pure GraphRAG और pure vector RAG, दोनों असली production traffic के लिए अनुकूलतम नहीं हैं, जो सरल और जटिल सवालों का मिश्रण होता है। उभरता architecture — जिसे कभी-कभी Adaptive RAG कहा जाता है — हर सवाल को रूट करने के लिए एक हल्का query classifier इस्तेमाल करता है: सरल factoid lookups तेज़ vector pipeline पर जाते हैं, जटिल multi-hop या संश्लेषण वाले सवाल GraphRAG पर। Classifier खुद एक छोटा fine-tuned model हो सकता है, या केवल एक rules-based heuristic भी (संबंध बताने वाले keywords की मौजूदगी, सवाल की लंबाई, named-entity की संख्या)। यह hybrid pattern आसान 80% queries पर vector-RAG की गति और कठिन 20% पर GraphRAG की सटीकता देता है।
Schema-free बनाम schema-guided extraction एक सक्रिय शोध बहस है। Microsoft का डिफ़ॉल्ट GraphRAG schema-free extraction इस्तेमाल करता है: LLM तय करता है कि हर chunk से कौन-सी entities और relationships निकालनी हैं। यह लचीला है, लेकिन शोर वाला — वही concept अलग-अलग chunks में अलग नामों से निकल सकता है, जिसके लिए बाद में entity resolution करना पड़ता है। Schema-guided extraction LLM को किन entity types और relationship types को खोजना है, यह पहले से परिभाषित करता है (जैसे केवल Person, Organization, Product और EmployedBy, Produces edges निकालना)। Schema-guided अधिक सटीक है, deduplication की लागत घटाता है और साफ़ graph देता है, लेकिन पहले ontology design का काम माँगता है — वही हफ़्तों से महीनों का निवेश, जो GraphRAG को vector RAG से अपनाने में कठिन बनाता है।
अक्सर पूछे जाने वाले प्रश्न
GraphRAG और सामान्य RAG में क्या अंतर है?
सामान्य RAG आपके documents को text segments में बाँटता है, उन्हें vectors के रूप में embed करता है, और query के समय सबसे अधिक semantically मिलते-जुलते chunks लाता है। इसके विपरीत GraphRAG आपके documents से एक knowledge graph बनाता है — nodes entities (लोग, संगठन, concepts) होते हैं, edges उनके बीच के relationships — और उसी graph को traverse करके जानकारी लाता है। इसका मुख्य फ़ायदा यह है कि GraphRAG कई documents में multi-hop reasoning माँगने वाले सवालों का जवाब दे सकता है, जहाँ अकेली vector similarity विफल होती है।
GraphRAG को index करना कितना महँगा है?
Vector embedding से काफ़ी ज़्यादा महँगा। Indexing pipeline entities और relationships निकालने के लिए हर text chunk पर LLM को कई बार call करती है, जिससे यह embedding-only indexing से 20-100x महँगी हो जाती है। लगभग 100,000 chunks वाले मध्यम आकार के enterprise corpus में लाखों LLM tokens खप सकते हैं, और उसे प्रोसेस करने में घंटों से दिन लग सकते हैं। लागत घटाने की रणनीतियों में extraction के लिए छोटा model इस्तेमाल करना (जैसे GPT-5 mini या Claude Haiku जैसा सस्ता tier, या कोई fine-tuned local model) और पूरे model का उपयोग केवल community summarization के लिए करना शामिल है।
GraphRAG कब vector RAG के बजाय इस्तेमाल करूँ?
GraphRAG तब इस्तेमाल करें जब आपके सवालों को multi-hop reasoning (संबंधों की श्रृंखला को ट्रेस करना), cross-document entity tracking, या पूरे corpus पर global synthesis चाहिए — यानी वे सवाल प्रकार जहाँ vector RAG 45-50% accuracy पर अटकता है, जबकि GraphRAG 80-85% तक पहुँचता है। सरल single-hop lookups के लिए vector RAG पर टिकें, जहाँ वह तेज़, सस्ता और उतना ही सटीक है। व्यावहारिक नियम: अपने query logs का ऑडिट करें, और GraphRAG में निवेश तभी करें जब आपके असली traffic का एक बड़ा हिस्सा multi-hop या synthesis श्रेणियों में हो।
Leiden algorithm क्या है, और GraphRAG इसे क्यों इस्तेमाल करता है?
Leiden एक graph community-detection algorithm है, जो घनी जुड़ी nodes को clusters (communities) में समूहित करता है। GraphRAG इसे entity graph को सुसंगत विषय-clusters में बाँटने के लिए लगाता है — उदाहरण के लिए "हमारी Q3 financials से जुड़ी सभी entities"। फिर वह हर community के लिए LLM-लिखी summary reports बनाता है। ये summaries ही GraphRAG के global search mode को शक्ति देती हैं, जिससे सिस्टम हर source document पढ़े बिना पूरे corpus से जुड़े सवालों का जवाब दे सकता है।
क्या GraphRAG को OpenAI के अलावा दूसरे models के साथ इस्तेमाल किया जा सकता है?
हाँ। Microsoft की open-source GraphRAG implementation किसी भी OpenAI-compatible API endpoint को स्वीकार करती है, इसलिए settings.yaml config बदलकर आप कोई दूसरा OpenAI model, Ollama के ज़रिए local होस्ट किए गए models, या कोई और compatible provider लगा सकते हैं। Entity extraction के लिए छोटे models इस्तेमाल किए जा सकते हैं (कम लागत, थोड़ी गुणवत्ता में कमी), जबकि community summarization के लिए मज़बूत model रखा जा सकता है, जहाँ output की गुणवत्ता ज़्यादा मायने रखती है।
क्या GraphRAG vector databases की जगह ले लेता है?
नहीं। GraphRAG आमतौर पर vector store की जगह लेने के बजाय उसका पूरक होता है। GraphRAG में local search mode वास्तव में graph traversal को vector retrieval के साथ जोड़ता है — यह graph के ज़रिए प्रासंगिक entities और उनके पड़ोसियों को ढूँढता है, फिर मूल source text chunks (जो vector या document store में संग्रहित हैं) लाता है ताकि जवाब को आधार मिल सके। Hybrid deployments में एक graph database और एक vector database साथ-साथ चलते हैं, और query router तय करता है कि किसे कब बुलाना है।
