Corrective RAG (CRAG) क्या है?
Corrective retrieval-augmented generation (CRAG) RAG का उन्नत संस्करण है, जिसका उद्देश्य भाषा मॉडलों को अधिक सटीक बनाना है।
जहाँ पारंपरिक RAG केवल प्राप्त दस्तावेज़ों का उपयोग कर पाठ जनरेट करता है, वहीं CRAG एक कदम आगे बढ़कर इन दस्तावेज़ों की सक्रिय रूप से जाँच और परिष्करण करता है ताकि वे प्रासंगिक और सटीक हों। यह त्रुटियों या hallucinations को कम करने में मदद करता है, जहाँ मॉडल गलत या भ्रामक जानकारी उत्पन्न कर सकता है।

स्रोत: Shi-Qi Yan et al., 2024
CRAG फ़्रेमवर्क कुछ प्रमुख चरणों से होकर गुजरता है, जिनमें एक retrieval evaluator और विशिष्ट corrective क्रियाएँ शामिल हैं।
किसी भी इनपुट क्वेरी के लिए, एक मानक retriever पहले नॉलेज बेस से दस्तावेज़ों का एक सेट निकालता है। इसके बाद इन दस्तावेज़ों की समीक्षा retrieval evaluator करता है ताकि प्रत्येक दस्तावेज़ की क्वेरी से प्रासंगिकता तय की जा सके।
CRAG में retrieval evaluator एक fine-tuned T5-large मॉडल होता है। यह evaluator प्रत्येक दस्तावेज़ को एक confidence स्कोर देता है और उन्हें तीन स्तरों में वर्गीकृत करता है:
- Correct: यदि कम से कम एक दस्तावेज़ ऊपरी थ्रेशहोल्ड से ऊपर स्कोर करता है, तो उसे सही माना जाता है। सिस्टम तब knowledge refinement प्रक्रिया लागू करता है, जिसमें decompose-then-recompose एल्गोरिद्म का उपयोग कर सबसे महत्वपूर्ण और प्रासंगिक knowledge strips निकाली जाती हैं तथा दस्तावेज़ों में मौजूद अप्रासंगिक या शोर डेटा को फ़िल्टर कर दिया जाता है। इससे केवल सबसे सटीक और प्रासंगिक जानकारी ही जनरेशन प्रक्रिया के लिए रखी जाती है।
- Incorrect: यदि सभी दस्तावेज़ निचले थ्रेशहोल्ड से नीचे आते हैं, तो उन्हें गलत चिह्नित किया जाता है। इस स्थिति में, CRAG सभी प्राप्त दस्तावेज़ों को त्याग देता है और इसके बजाय वेब खोज करता है ताकि नया, संभावित रूप से अधिक सटीक बाहरी ज्ञान इकट्ठा किया जा सके। यह चरण स्थिर या सीमित नॉलेज बेस से आगे बढ़कर वेब पर उपलब्ध व्यापक और गतिशील जानकारी का लाभ उठाता है, जिससे प्रासंगिक और सटीक डेटा मिलने की संभावना बढ़ती है।
- Ambiguous: जब प्राप्त दस्तावेज़ों में मिश्रित परिणाम होते हैं, तो इसे संदिग्ध माना जाएगा। ऐसे में, CRAG दोनों रणनीतियाँ मिलाकर काम करता है: यह प्रारंभिक प्राप्त दस्तावेज़ों से जानकारी को परिष्कृत करता है और वेब खोज से प्राप्त अतिरिक्त ज्ञान को भी शामिल करता है।
इन कार्रवाइयों में से किसी एक के बाद, परिष्कृत ज्ञान का उपयोग अंतिम उत्तर जनरेट करने के लिए किया जाता है।
CRAG बनाम पारंपरिक RAG
CRAG, पारंपरिक RAG की तुलना में कई महत्वपूर्ण सुधार लाता है। इसका एक बड़ा लाभ यह है कि यह प्राप्त जानकारी में त्रुटियों को सुधारने में सक्षम है। CRAG का retrieval evaluator तब पहचानने में मदद करता है जब जानकारी गलत या अप्रासंगिक हो, ताकि उसे अंतिम आउटपुट को प्रभावित करने से पहले दुरुस्त किया जा सके। इसका मतलब है कि CRAG अधिक सटीक और भरोसेमंद जानकारी प्रदान करता है, जिससे त्रुटियाँ और गलत सूचना कम होती हैं।
CRAG यह सुनिश्चित करने में भी उत्कृष्ट है कि जानकारी प्रासंगिक होने के साथ-साथ सटीक भी हो। जहाँ पारंपरिक RAG केवल प्रासंगिकता स्कोर की जाँच कर सकता है, वहीं CRAG दस्तावेज़ों का परिष्करण करके आगे बढ़ता है ताकि वे सिर्फ प्रासंगिक ही नहीं बल्कि सटीक भी हों। यह अप्रासंगिक विवरणों को फ़िल्टर करता है और सबसे महत्वपूर्ण बिंदुओं पर ध्यान केंद्रित करता है, जिससे जनरेट किया गया पाठ सटीक जानकारी पर आधारित रहता है।
LangGraph का उपयोग कर CRAG का इम्प्लीमेंटेशन
इस खंड में, हम LangGraph का उपयोग करके CRAG लागू करने की चरण-दर-चरण गाइड से गुजरेंगे। आप जानेंगे कि परिवेश कैसे सेटअप करना है, एक बेसिक नॉलेज वेक्टर स्टोर कैसे बनाना है, और CRAG के लिए ज़रूरी मुख्य घटक—जैसे retrieval evaluator, question rewriter, और वेब सर्च टूल—कैसे कॉन्फ़िगर करने हैं।
हम यह भी सीखेंगे कि इन सभी हिस्सों को साथ लाने वाला LangGraph वर्कफ़्लो कैसे बनाया जाए, जो यह दिखाता है कि अधिक सटीक और भरोसेमंद परिणामों के लिए CRAG विभिन्न प्रकार की क्वेरीज़ को कैसे संभाल सकता है।
चरण 1: सेटअप और इंस्टॉलेशन
पहले आवश्यक पैकेज इंस्टॉल करें। यह चरण CRAG पाइपलाइन चलाने के लिए परिवेश सेट करता है।
pip install langchain_community tiktoken langchain-openai langchainhub chromadb langchain langgraph tavily-python
इसके बाद, Tavily और OpenAI के लिए अपनी API keys कॉन्फ़िगर करें:
import os
os.environ["TAVILY_API_KEY"] = "YOUR_TAVILY_API_KEY"
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"
चरण 2: एक प्रॉक्सी नॉलेज बेस सेटअप करें
RAG करने के लिए हमें पहले दस्तावेज़ों से भरा एक नॉलेज बेस चाहिए। इस चरण में, हम एक Substack न्यूज़लेटर से कुछ सैंपल दस्तावेज़ स्क्रैप करेंगे ताकि एक वेक्टर स्टोर बनाया जा सके, जो हमारे प्रॉक्सी नॉलेज बेस के रूप में काम करेगा। यह वेक्टर स्टोर उपयोगकर्ता की क्वेरी के आधार पर प्रासंगिक दस्तावेज़ खोजने में मदद करता है।
हम दिए गए URLs से दस्तावेज़ लोड करके और उन्हें टेक्स्ट स्प्लिटर से छोटे हिस्सों में बाँटकर शुरू करते हैं। इन हिस्सों को फिर embedded किया जाता है OpenAIEmbeddings का उपयोग करके और एक वेक्टर डेटाबेस (Chroma) में स्टोर किया जाता है ताकि दस्तावेज़ों को कुशलता से प्राप्त किया जा सके।
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import WebBaseLoader
from langchain_community.vectorstores import Chroma
from langchain_openai import OpenAIEmbeddings
urls = [
"<https://ryanocm.substack.com/p/mystery-gift-box-049-law-1-fill-your>",
"<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>",
"<https://ryanocm.substack.com/p/098-i-have-read-100-productivity>",
]
docs = [WebBaseLoader(url).load() for url in urls]
docs_list = [item for sublist in docs for item in sublist]
text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
chunk_size=250, chunk_overlap=0
)
doc_splits = text_splitter.split_documents(docs_list)
# Add to vectorDB
vectorstore = Chroma.from_documents(
documents=doc_splits,
collection_name="rag-chroma",
embedding=OpenAIEmbeddings(),
)
retriever = vectorstore.as_retriever()
चरण 3: एक RAG चेन सेटअप करें
इस चरण में, हम एक बेसिक RAG चेन सेट करते हैं जो उपयोगकर्ता के प्रश्न और दस्तावेज़ों के सेट को लेकर उत्तर जनरेट करता है।
RAG चेन एक पूर्वनिर्धारित प्रॉम्प्ट और भाषा मॉडल (GPT 4-o mini) का उपयोग करके प्राप्त दस्तावेज़ों के आधार पर उत्तर बनाती है। एक आउटपुट पार्सर फिर जनरेट किए गए टेक्स्ट को पढ़ने में आसान फ़ॉर्मेट में ढालता है।
### Generate
from langchain import hub
from langchain_core.output_parsers import StrOutputParser
# Prompt
rag_prompt = hub.pull("rlm/rag-prompt")
# LLM
rag_llm = ChatOpenAI(model_name="gpt-4o-mini", temperature=0)
# Post-processing
def format_docs(docs):
return "\\n\\n".join(doc.page_content for doc in docs)
# Chain
rag_chain = rag_prompt | rag_llm | StrOutputParser()
print(rag_prompt.messages[0].prompt.template)
You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise.
Question: {question}
Context: {context}
Answer:
generation = rag_chain.invoke({"context": docs, "question": question})
print("Question: %s" % question)
print("----")
print("Documents:\\n")
print('\\n\\n'.join(['- %s' % x.page_content for x in docs]))
print("----")
print("Final answer: %s" % generation)
Question: what is the bagel method
----
Documents:
- the book was called The Bagel Method.The Bagel Method is designed to help partners be on the same team when dealing with differences and trying to find a compromise.The idea behind the method is that, to truly compromise, we need to figure out a way to include both partners’ dreams and core needs; things that are super important to us that giving up on them is too much.Let’s dive into the bagel 😜🚀 If you are new here…Hi, I’m Ryan 👋� I am passionate about lifestyle gamification � and I am obsesssssssss with learning things that can help me live a happy and fulfilling life.And so, with The Limitless Playbook newsletter, I will share with you 1 actionable idea from the world's top thinkers every Sunday �So visit us weekly for highly actionable insights :)…or even better, subscribe below and have all these information send straight to your inbox every Sunday 🥳Subscribe🥯
- #105 | The Bagel Method in Relationships 🥯
- The Limitless Playbook 🧬SubscribeSign inShare this post#105 | The Bagel Method in Relationships 🥯ryanocm.substack.comCopy linkFacebookEmailNoteOther#105 | The Bagel Method in Relationships 🥯A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��Ryan Ong �Feb 25, 2024Share this post#105 | The Bagel Method in Relationships 🥯ryanocm.substack.comCopy linkFacebookEmailNoteOtherShareHello curious minds 🧠I recently finished the book Fight Right: How Successful Couples Turn Conflict into Connection and oh my days, I love every chapter of it!There were many repeating concepts but this time, it was applied in the context of conflicts in relationships. As usual with the Gottman’s books, I highlighted the hell out of the entire book 😄One of the cool exercises in
- The Bagel MethodThe Bagel Method involves mapping out your core needs and areas of flexibility so that you and your partner understand what's important and where there's room for flexibility.It’s called The Bagel Method because, just like a bagel, it has both the inner and outer circles representing your needs.Here are the steps:In the inner circle, list all the aspects of an issue that you can’t give in on. These are your non-negotiables that are usually very closely related to your core needs and dreams.In the outer circle, list all the aspects of an issue that you are able to compromise on IF you are able to have what’s in your inner circle.Now, talk to your partners about your inner and outer circle. Ask each other:Why are the things in your inner circle so important to you?How can I support your core needs here?Tell me more about your areas of flexibility. What does it look like to be flexible?Compare both your “bagel� of needsWhat do we agree on?What feelings do we have in common?What shared goals do we have?How might we accomplish these goals
----
Final answer: The Bagel Method is a relationship strategy that helps partners identify their core needs and areas where they can be flexible. It involves mapping out non-negotiables in the inner circle and compromise areas in the outer circle, facilitating open communication about each partner's priorities. This method aims to foster understanding and collaboration in resolving differences.
चरण 4: एक retrieval evaluator सेटअप करें
जनरेट की गई सामग्री की शुद्धता बढ़ाने के लिए, हम एक retrieval evaluator सेट करते हैं। यह टूल प्रत्येक प्राप्त दस्तावेज़ की प्रासंगिकता जाँचता है ताकि केवल सबसे उपयोगी जानकारी का उपयोग हो।
retrieval evaluator को एक प्रॉम्प्ट और भाषा मॉडल के साथ कॉन्फ़िगर किया जाता है। यह तय करता है कि दस्तावेज़ प्रासंगिक हैं या नहीं, और उत्तर जनरेट होने से पहले किसी भी अप्रासंगिक सामग्री को फ़िल्टर कर देता है।
### Retrieval Evaluator
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_openai import ChatOpenAI
# Data model
class RetrievalEvaluator(BaseModel):
"""Classify retrieved documents based on how relevant it is to the user's question."""
binary_score: str = Field(
description="Documents are relevant to the question, 'yes' or 'no'"
)
# LLM with function call
retrieval_evaluator_llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
structured_llm_evaluator = retrieval_evaluator_llm.with_structured_output(RetrievalEvaluator)
# Prompt
system = """You are a document retrieval evaluator that's responsible for checking the relevancy of a retrieved document to the user's question. \\n
If the document contains keyword(s) or semantic meaning related to the question, grade it as relevant. \\n
Output a binary score 'yes' or 'no' to indicate whether the document is relevant to the question."""
retrieval_evaluator_prompt = ChatPromptTemplate.from_messages(
[
("system", system),
("human", "Retrieved document: \\n\\n {document} \\n\\n User question: {question}"),
]
)
retrieval_grader = retrieval_evaluator_prompt | structured_llm_evaluator
चरण 5: एक question rewriter सेटअप करें
हम उपयोगकर्ता क्वेरीज़ को और स्पष्ट और विशिष्ट बनाने के लिए एक question rewriter जोड़ेंगे, जो खोज प्रक्रिया को बेहतर करता है।
rewriter मूल क्वेरी को परिष्कृत करता है ताकि खोज और केंद्रित हो, जिससे बेहतर और अधिक प्रासंगिक परिणाम मिलें।
### Question Re-writer
# LLM
question_rewriter_llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
# Prompt
system = """You are a question re-writer that converts an input question to a better version that is optimized \\n
for web search. Look at the input and try to reason about the underlying semantic intent / meaning."""
re_write_prompt = ChatPromptTemplate.from_messages(
[
("system", system),
(
"human",
"Here is the initial question: \\n\\n {question} \
Formulate an improved question.",
),
]
)
question_rewriter = re_write_prompt | question_rewriter_llm | StrOutputParser()
चरण 6: Tavily वेब सर्च टूल इनिशियलाइज़ करें
यदि नॉलेज बेस में पर्याप्त जानकारी नहीं है, तो CRAG अंतराल भरने के लिए वेब सर्च का सहारा लेता है। इससे संभावित स्रोतों की रेंज बढ़ती है। इस चरण में, हम वेब पर खोज करने और अतिरिक्त दस्तावेज़ ढूँढने के लिए Tavily API का उपयोग करते हैं।
### Search
from langchain_community.tools.tavily_search import TavilySearchResults
web_search_tool = TavilySearchResults(k=3)
चरण 7: LangGraph वर्कफ़्लो सेटअप करें
LangGraph के साथ CRAG वर्कफ़्लो बनाने के लिए, इन तीन मुख्य चरणों का पालन करें:
- ग्राफ स्टेट परिभाषित करें
- फ़ंक्शन नोड्स परिभाषित करें
- सभी फ़ंक्शन नोड्स को जोड़ें
ग्राफ स्टेट परिभाषित करें
वर्कफ़्लो के दौरान नोड्स के बीच डेटा चलते समय उसे स्टोर करने के लिए एक साझा स्टेट बनाएँ। यह स्टेट सभी वेरिएबल—जैसे उपयोगकर्ता का प्रश्न, प्राप्त दस्तावेज़, और जनरेट किए गए उत्तर—रखेगा।
from typing import List
from typing_extensions import TypedDict
class GraphState(TypedDict):
"""
Represents the state of our graph.
Attributes:
question: question
generation: LLM generation
web_search: whether to add search
documents: list of documents
"""
question: str
generation: str
web_search: str
documents: List[str]
फ़ंक्शन नोड्स परिभाषित करें
LangGraph वर्कफ़्लो में, प्रत्येक फ़ंक्शन नोड CRAG पाइपलाइन में एक विशिष्ट कार्य संभालता है, जैसे दस्तावेज़ प्राप्त करना, उत्तर जनरेट करना, प्रासंगिकता का मूल्यांकन, क्वेरी रूपांतरित करना, और वेब खोजना। यहाँ प्रत्येक फ़ंक्शन का विवरण है:
retrieve फ़ंक्शन नॉलेज बेस से उपयोगकर्ता के प्रश्न से संबंधित दस्तावेज़ ढूँढता है। यह आमतौर पर पूर्व-प्रक्रिया किए गए दस्तावेज़ों से बने वेक्टर स्टोर का उपयोग करने वाले retriever ऑब्जेक्ट का उपयोग करता है। यह फ़ंक्शन वर्तमान स्टेट लेता है, जिसमें उपयोगकर्ता का प्रश्न शामिल होता है, और retriever का उपयोग करके प्रासंगिक दस्तावेज़ प्राप्त करता है। फिर यह इन दस्तावेज़ों को स्टेट में जोड़ता है।
from langchain.schema import Document
def retrieve(state):
"""
Retrieve documents
Args:
state (dict): The current graph state
Returns:
state (dict): New key added to state, documents, that contains retrieved documents
"""
print("---RETRIEVE---")
question = state["question"]
# Retrieval
documents = retriever.get_relevant_documents(question)
return {"documents": documents, "question": question}
generate फ़ंक्शन प्राप्त दस्तावेज़ों का उपयोग करके उपयोगकर्ता के प्रश्न का उत्तर बनाता है। यह RAG चेन के साथ काम करता है, जो एक प्रॉम्प्ट को भाषा मॉडल से जोड़ती है। यह फ़ंक्शन प्राप्त दस्तावेज़ों और उपयोगकर्ता के प्रश्न को लेता है, उन्हें RAG चेन से गुज़ारता है, और फिर उत्तर को स्टेट में जोड़ता है।
def generate(state):
"""
Generate answer
Args:
state (dict): The current graph state
Returns:
state (dict): New key added to state, generation, that contains LLM generation
"""
print("---GENERATE---")
question = state["question"]
documents = state["documents"]
# RAG generation
generation = rag_chain.invoke({"context": documents, "question": question})
return {"documents": documents, "question": question, "generation": generation}
evaluate_documents फ़ंक्शन retrieval evaluator का उपयोग करके प्रत्येक प्राप्त दस्तावेज़ की उपयोगकर्ता के प्रश्न से प्रासंगिकता जाँचता है। इससे सुनिश्चित होता है कि अंतिम उत्तर के लिए केवल उपयोगी जानकारी का उपयोग हो। यह फ़ंक्शन प्रत्येक दस्तावेज़ की प्रासंगिकता रेट करता है और गैर-उपयोगी को फ़िल्टर करता है। यह स्टेट में web_search फ़्लैग भी अपडेट करता है ताकि दिखाया जा सके कि जब अधिकांश दस्तावेज़ प्रासंगिक नहीं हों तो वेब खोज की ज़रूरत है।
def evaluate_documents(state):
"""
Determines whether the retrieved documents are relevant to the question.
Args:
state (dict): The current graph state
Returns:
state (dict): Updates documents key with only filtered relevant documents
"""
print("---CHECK DOCUMENT RELEVANCE TO QUESTION---")
question = state["question"]
documents = state["documents"]
# Score each doc
filtered_docs = []
web_search = "No"
for d in documents:
score = retrieval_grader.invoke(
{"question": question, "document": d.page_content}
)
grade = score.binary_score
if grade == "yes":
print("---GRADE: DOCUMENT RELEVANT---")
filtered_docs.append(d)
else:
print("---GRADE: DOCUMENT NOT RELEVANT---")
continue
if len(filtered_docs) / len(documents) <= 0.7:
web_search = "Yes"
return {"documents": filtered_docs, "question": question, "web_search": web_search}
transform_query फ़ंक्शन उपयोगकर्ता के प्रश्न को बेहतर खोज परिणाम पाने के लिए सुधारता है, खासकर तब जब मूल क्वेरी प्रासंगिक दस्तावेज़ नहीं ढूँढ पाती। यह question rewriter का उपयोग करके प्रश्न को और स्पष्ट व विशिष्ट बनाता है। बेहतर प्रश्न नॉलेज बेस और वेब खोज—दोनों से उपयोगी दस्तावेज़ मिलने की संभावना बढ़ाता है।
def transform_query(state):
"""
Transform the query to produce a better question.
Args:
state (dict): The current graph state
Returns:
state (dict): Updates question key with a re-phrased question
"""
print("---TRANSFORM QUERY---")
question = state["question"]
documents = state["documents"]
# Re-write question
better_question = question_rewriter.invoke({"question": question})
return {"documents": documents, "question": better_question}
web_search फ़ंक्शन परिष्कृत क्वेरी का उपयोग करके ऑनलाइन अतिरिक्त जानकारी ढूँढता है। यह तब उपयोग किया जाता है जब नॉलेज बेस में पर्याप्त जानकारी नहीं होती, ताकि और सामग्री इकट्ठी की जा सके। यह फ़ंक्शन Tavily वेब सर्च टूल का उपयोग करके वेब पर अतिरिक्त दस्तावेज़ ढूँढता है, जिन्हें फिर मौजूदा दस्तावेज़ों में जोड़ दिया जाता है ताकि नॉलेज बेस बेहतर हो सके।
def web_search(state):
"""
Web search based on the re-phrased question.
Args:
state (dict): The current graph state
Returns:
state (dict): Updates documents key with appended web results
"""
print("---WEB SEARCH---")
question = state["question"]
documents = state["documents"]
# Web search
docs = web_search_tool.invoke({"query": question})
web_results = "\\n".join([d["content"] for d in docs])
web_results = Document(page_content=web_results)
documents.append(web_results)
return {"documents": documents, "question": question}
decide_to_generate फ़ंक्शन अगला कदम तय करता है: मौजूदा दस्तावेज़ों से उत्तर जनरेट करना या क्वेरी को परिष्कृत करके फिर से खोज करना। यह निर्णय पहले आंकी गई दस्तावेज़-प्रासंगिकता के आधार पर लिया जाता है।
def decide_to_generate(state):
"""
Determines whether to generate an answer, or re-generate a question.
Args:
state (dict): The current graph state
Returns:
str: Binary decision for next node to call
"""
print("---ASSESS GRADED DOCUMENTS---")
state["question"]
web_search = state["web_search"]
state["documents"]
if web_search == "Yes":
# All documents have been filtered check_relevance
# We will re-generate a new query
print(
"---DECISION: ALL DOCUMENTS ARE NOT RELEVANT TO QUESTION, TRANSFORM QUERY---"
)
return "transform_query"
else:
# We have relevant documents, so generate answer
print("---DECISION: GENERATE---")
return "generate"
सभी फ़ंक्शन नोड्स को जोड़ें
जब सभी फ़ंक्शन नोड्स परिभाषित हो जाएँ, तो अब हम इन्हें LangGraph वर्कफ़्लो में जोड़कर CRAG पाइपलाइन बना सकते हैं। इसका अर्थ है नोड्स को edges से कनेक्ट करना ताकि जानकारी और निर्णयों का प्रवाह मैनेज हो, और यह सुनिश्चित करना कि प्रत्येक चरण के नतीजों के आधार पर वर्कफ़्लो सही ढंग से चले।
from langgraph.graph import END, StateGraph, START
workflow = StateGraph(GraphState)
# Define the nodes
workflow.add_node("retrieve", retrieve) # retrieve
workflow.add_node("grade_documents", evaluate_documents) # evaluate documents
workflow.add_node("generate", generate) # generate
workflow.add_node("transform_query", transform_query) # transform_query
workflow.add_node("web_search_node", web_search) # web search
# Build graph
workflow.add_edge(START, "retrieve")
workflow.add_edge("retrieve", "grade_documents")
workflow.add_conditional_edges(
"grade_documents",
decide_to_generate,
{
"transform_query": "transform_query",
"generate": "generate",
},
)
workflow.add_edge("transform_query", "web_search_node")
workflow.add_edge("web_search_node", "generate")
workflow.add_edge("generate", END)
# Compile
app = workflow.compile()
from IPython.display import Image, display
try:
display(Image(app.get_graph(xray=True).draw_mermaid_png()))
except Exception:
# This requires some extra dependencies and is optional
pass

चरण 8: वर्कफ़्लो का परीक्षण
हमारे सेटअप का परीक्षण करने के लिए, हम वर्कफ़्लो को सैंपल क्वेरीज़ के साथ चलाते हैं ताकि यह जाँचा जा सके कि यह जानकारी कैसे प्राप्त करता है, दस्तावेज़-प्रासंगिकता का मूल्यांकन करता है, और उत्तर जनरेट करता है।
पहली क्वेरी यह जाँचती है कि CRAG अपने नॉलेज बेस के भीतर कितनी अच्छी तरह उत्तर ढूँढता है।
from pprint import pprint
# Run
inputs = {"question": "What's the bagel method?"}
for output in app.stream(inputs):
for key, value in output.items():
# Node
pprint(f"Node '{key}':")
# Optional: print full state at each node
pprint(value, indent=2, width=80, depth=None)
pprint("\\n---\\n")
# Final generation
pprint(value["generation"])
---RETRIEVE---
"Node 'retrieve':"
{ 'documents': [ Document(page_content="the book was called The Bagel Method.The Bagel Method is designed to help partners be on the same team when dealing with differences and trying to find a compromise.The idea behind the method is that, to truly compromise, we need to figure out a way to include both partners’ dreams and core needs; things that are super important to us that giving up on them is too much.Let’s dive into the bagel 😜🚀 If you are new here…Hi, I’m Ryan 👋� I am passionate about lifestyle gamification � and I am obsesssssssss with learning things that can help me live a happy and fulfilling life.And so, with The Limitless Playbook newsletter, I will share with you 1 actionable idea from the world's top thinkers every Sunday �So visit us weekly for highly actionable insights :)…or even better, subscribe below and have all these information send straight to your inbox every Sunday 🥳Subscribe🥯", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content='#105 | The Bagel Method in Relationships 🥯', metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content='The Limitless Playbook 🧬SubscribeSign inShare this post#105 | The Bagel Method in Relationships 🥯ryanocm.substack.comCopy linkFacebookEmailNoteOther#105 | The Bagel Method in Relationships 🥯A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life â�¤ï¸�Ryan Ong ğŸ�®Feb 25, 2024Share this post#105 | The Bagel Method in Relationships 🥯ryanocm.substack.comCopy linkFacebookEmailNoteOtherShareHello curious minds ğŸ§\\xa0I recently finished the book Fight Right: How Successful Couples Turn Conflict into Connection and oh my days, I love every chapter of it!There were many repeating concepts but this time, it was applied in the context of conflicts in relationships. As usual with the Gottman’s books, I highlighted the hell out of the entire book 😄One of the cool exercises in', metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life â�¤ï¸�', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content="The Bagel MethodThe Bagel Method involves mapping out your core needs and areas of flexibility so that you and your partner understand what's important and where there's room for flexibility.It’s called The Bagel Method because, just like a bagel, it has both the inner and outer circles representing your needs.Here are the steps:In the inner circle, list all the aspects of an issue that you can’t give in on. These are your non-negotiables that are usually very closely related to your core needs and dreams.In the outer circle, list all the aspects of an issue that you are able to compromise on IF you are able to have what’s in your inner circle.Now, talk to your partners about your inner and outer circle. Ask each other:Why are the things in your inner circle so important to you?How can I support your core needs here?Tell me more about your areas of flexibility. What does it look like to be flexible?Compare both your “bagel� of needsWhat do we agree on?What feelings do we have in common?What shared goals do we have?How might we accomplish these goals", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'})],
'question': "What's the bagel method?"}
'\\n---\\n'
---CHECK DOCUMENT RELEVANCE TO QUESTION---
---GRADE: DOCUMENT RELEVANT---
---GRADE: DOCUMENT RELEVANT---
---GRADE: DOCUMENT NOT RELEVANT---
---GRADE: DOCUMENT RELEVANT---
---ASSESS GRADED DOCUMENTS---
---DECISION: GENERATE---
"Node 'evaluate_documents':"
{ 'documents': [ Document(page_content="the book was called The Bagel Method.The Bagel Method is designed to help partners be on the same team when dealing with differences and trying to find a compromise.The idea behind the method is that, to truly compromise, we need to figure out a way to include both partners’ dreams and core needs; things that are super important to us that giving up on them is too much.Let’s dive into the bagel 😜🚀 If you are new here…Hi, I’m Ryan 👋� I am passionate about lifestyle gamification � and I am obsesssssssss with learning things that can help me live a happy and fulfilling life.And so, with The Limitless Playbook newsletter, I will share with you 1 actionable idea from the world's top thinkers every Sunday �So visit us weekly for highly actionable insights :)…or even better, subscribe below and have all these information send straight to your inbox every Sunday 🥳Subscribe🥯", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content='#105 | The Bagel Method in Relationships 🥯', metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content="The Bagel MethodThe Bagel Method involves mapping out your core needs and areas of flexibility so that you and your partner understand what's important and where there's room for flexibility.It’s called The Bagel Method because, just like a bagel, it has both the inner and outer circles representing your needs.Here are the steps:In the inner circle, list all the aspects of an issue that you can’t give in on. These are your non-negotiables that are usually very closely related to your core needs and dreams.In the outer circle, list all the aspects of an issue that you are able to compromise on IF you are able to have what’s in your inner circle.Now, talk to your partners about your inner and outer circle. Ask each other:Why are the things in your inner circle so important to you?How can I support your core needs here?Tell me more about your areas of flexibility. What does it look like to be flexible?Compare both your “bagel� of needsWhat do we agree on?What feelings do we have in common?What shared goals do we have?How might we accomplish these goals", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'})],
'question': "What's the bagel method?",
'web_search': 'No'}
'\\n---\\n'
---GENERATE---
"Node 'generate':"
{ 'documents': [ Document(page_content="the book was called The Bagel Method.The Bagel Method is designed to help partners be on the same team when dealing with differences and trying to find a compromise.The idea behind the method is that, to truly compromise, we need to figure out a way to include both partners’ dreams and core needs; things that are super important to us that giving up on them is too much.Let’s dive into the bagel 😜🚀 If you are new here…Hi, I’m Ryan 👋� I am passionate about lifestyle gamification � and I am obsesssssssss with learning things that can help me live a happy and fulfilling life.And so, with The Limitless Playbook newsletter, I will share with you 1 actionable idea from the world's top thinkers every Sunday �So visit us weekly for highly actionable insights :)…or even better, subscribe below and have all these information send straight to your inbox every Sunday 🥳Subscribe🥯", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content='#105 | The Bagel Method in Relationships 🥯', metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'}),
Document(page_content="The Bagel MethodThe Bagel Method involves mapping out your core needs and areas of flexibility so that you and your partner understand what's important and where there's room for flexibility.It’s called The Bagel Method because, just like a bagel, it has both the inner and outer circles representing your needs.Here are the steps:In the inner circle, list all the aspects of an issue that you can’t give in on. These are your non-negotiables that are usually very closely related to your core needs and dreams.In the outer circle, list all the aspects of an issue that you are able to compromise on IF you are able to have what’s in your inner circle.Now, talk to your partners about your inner and outer circle. Ask each other:Why are the things in your inner circle so important to you?How can I support your core needs here?Tell me more about your areas of flexibility. What does it look like to be flexible?Compare both your “bagel� of needsWhat do we agree on?What feelings do we have in common?What shared goals do we have?How might we accomplish these goals", metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'})],
'generation': 'The Bagel Method is a framework designed to help partners '
'navigate differences and find compromises by mapping out '
'their core needs and areas of flexibility. It involves '
'creating two circles: the inner circle for non-negotiable '
'needs and the outer circle for aspects where compromise is '
'possible. This method encourages open communication about '
"each partner's priorities and shared goals.",
'question': "What's the bagel method?"}
'\\n---\\n'
('The Bagel Method is a framework designed to help partners navigate '
'differences and find compromises by mapping out their core needs and areas '
'of flexibility. It involves creating two circles: the inner circle for '
'non-negotiable needs and the outer circle for aspects where compromise is '
"possible. This method encourages open communication about each partner's "
'priorities and shared goals.')
और दूसरी क्वेरी यह परखती है कि जब नॉलेज बेस में प्रासंगिक दस्तावेज़ नहीं होते, तब CRAG अतिरिक्त जानकारी के लिए वेब पर खोजने में कितना सक्षम है।
from pprint import pprint
# Run
inputs = {"question": "What is prompt engineering?"}
for output in app.stream(inputs):
for key, value in output.items():
# Node
pprint(f"Node '{key}':")
# Optional: print full state at each node
pprint(value, indent=2, width=80, depth=None)
pprint("\\n---\\n")
# Final generation
pprint(value["generation"])
---RETRIEVE---
"Node 'retrieve':"
{ 'documents': [ Document(page_content='Mystery Gift Box #049 | Law 1: Fill your Five Buckets in the Right Order (The Diary of a CEO)', metadata={'description': "The best hidden gems I've found; interesting ideas and concepts, thought-provoking questions, mind-blowing books/podcasts, cool animes/films, and other mysteries ��", 'language': 'en', 'source': '<https://ryanocm.substack.com/p/mystery-gift-box-049-law-1-fill-your>', 'title': 'Mystery Gift Box #049 | Law 1: Fill your Five Buckets in the Right Order (The Diary of a CEO)'}),
Document(page_content='ğŸ�¦Â\\xa0Twitter, 👨ğŸ�»â€�💻Â\\xa0LinkedIn, ğŸŒ�Â\\xa0Personal Website, and 📸Â\\xa0InstagramShare this postMystery Gift Box #049 | Law 1: Fill your Five Buckets in the Right Order (The Diary of a CEO)ryanocm.substack.comCopy linkFacebookEmailNoteOtherSharePreviousNextCommentsTopLatestDiscussionsNo postsReady for more?Subscribe© 2024 Ryan Ong ğŸ�®Privacy ∙ Terms ∙ Collection notice Start WritingGet the appSubstack is the home for great cultureShareCopy linkFacebookEmailNoteOther', metadata={'description': "The best hidden gems I've found; interesting ideas and concepts, thought-provoking questions, mind-blowing books/podcasts, cool animes/films, and other mysteries â�¤ï¸�", 'language': 'en', 'source': '<https://ryanocm.substack.com/p/mystery-gift-box-049-law-1-fill-your>', 'title': 'Mystery Gift Box #049 | Law 1: Fill your Five Buckets in the Right Order (The Diary of a CEO)'}),
Document(page_content='skills are the foundation of which you build your life and career and it’s truly yours to own; you can lose your network, resources, and reputation but you will never lose your knowledge and skills.Never try to skip the first two buckets. If you try to jump straight to network, resources, and / or reputation bucket, you might “succeed� in the short-run but in the long run, your lack of knowledge and skill will catch on to you.There is no skipping the first two buckets of knowledge and skills if you’re playing long-term sustainable results. Any attempt to do so is equivalent to building your house on sand.💥 Key takeawayFocus on using your knowledge and skills to create lots of values in the world and the world will reward you with growing network (people will come to you), resources (people will pay for your services), and reputation (people will know what you are capable of).⛰ 4-4-4 Exploration ProjectEach month, I would explore one new thing; a skill, a subject, or an experience.January 2023: Writing and Storytelling (Subject)', metadata={'description': "The best hidden gems I've found; interesting ideas and concepts, thought-provoking questions, mind-blowing books/podcasts, cool animes/films, and other mysteries ��", 'language': 'en', 'source': '<https://ryanocm.substack.com/p/mystery-gift-box-049-law-1-fill-your>', 'title': 'Mystery Gift Box #049 | Law 1: Fill your Five Buckets in the Right Order (The Diary of a CEO)'}),
Document(page_content='This site requires JavaScript to run correctly. Please turn on JavaScript or unblock scripts', metadata={'description': 'A collection of the best hidden gems, mental models, and frameworks from the world’s top thinkers; to help you become 1% better and live a happier life ��', 'language': 'en', 'source': '<https://ryanocm.substack.com/p/105-the-bagel-method-in-relationships>', 'title': '#105 | The Bagel Method in Relationships 🥯'})],
'question': 'What is prompt engineering?'}
'\\n---\\n'
---CHECK DOCUMENT RELEVANCE TO QUESTION---
---GRADE: DOCUMENT NOT RELEVANT---
---GRADE: DOCUMENT NOT RELEVANT---
---GRADE: DOCUMENT NOT RELEVANT---
---GRADE: DOCUMENT NOT RELEVANT---
---ASSESS GRADED DOCUMENTS---
---DECISION: ALL DOCUMENTS ARE NOT RELEVANT TO QUESTION, TRANSFORM QUERY---
"Node 'evaluate_documents':"
{ 'documents': [],
'question': 'What is prompt engineering?',
'web_search': 'Yes'}
'\\n---\\n'
---TRANSFORM QUERY---
"Node 'transform_query':"
{ 'documents': [],
'question': 'What is the concept of prompt engineering and how is it applied '
'in artificial intelligence?'}
'\\n---\\n'
---WEB SEARCH---
"Node 'web_search_node':"
{ 'documents': [ Document(page_content="Prompt engineering is the method to ask generative AI to produce what the individual needs. There are two main principles of building a successful prompt for any AI, specificity and iteration. The box below includes one example of a framework that can be applied when prompting any generative AI.\\nPrompt Engineering is the process of designing and refining text inputs (prompts) to achieve specific application objectives with AI models. Think of it as a two-step journey: Designing the Initial Prompt: Creating the initial input for the model to achieve the desired result. Refining the Prompt: Continuously adjusting the prompt to enhance ...\\nPrompt engineering is the process of designing and refining the inputs given to language models, like those in AI, to achieve desired outputs more effectively. It involves creatively crafting prompts that guide the model in generating responses that are accurate, relevant, and aligned with the user's intentions.. For students and researchers in higher education, mastering prompt engineering is ...\\nJune 25, 2024. Prompt engineering means writing precise instructions for AI models. These instructions are different from coding because they use natural language. And today, everybody does it—from software developers to artists and content creators. Prompt engineering can help you improve productivity and save time by automating repetitive ...\\nMaster Prompt Engineering - The (AI) Prompt\\nAI Takes Wall Street by Storm: C3.ai's Strong Forecast Sparks a Surge in AI Stocks\\nAsk Me Anything (AMA) Prompting\\nHow Self-Critique Improves Logic and Reasoning in LLMs Like ChatGPT\\nOptimizing Large Language Models to Maximize Performance\\nThe Black Box Problem: Opaque Inner Workings of Large Language Models\\nHow to Evaluate Large Language Models for Business Tasks\\nIntroduction to the AI Prompt Development Process\\nSubscribe to new posts\\nThe Official Source For Everything Prompt Engineering & Generative AI Defining Prompt Engineering\\nGiven that the prompt is the singular input channel to large language models, prompt engineering can be defined as:\\nPrompt Engineering can be thought of as any process that contributes to the development of a well-crafted prompt to generate quality, useful outputs from an AI system.\\n A Simplified Approach to Defining Prompt Engineering\\nThe Prompt is the Sole Input\\nWhen interacting with Generative AI Models such as large language models (LLMs), the prompt is the only thing that gets input into the AI system. Its applications cut across diverse sectors, from healthcare and education to business, securing its place as a cornerstone of our interactions with AI.\\nExploration of Essential Prompt Engineering Techniques and Concepts\\nIn the rapidly evolving landscape of Artificial Intelligence (AI), mastering key techniques of Prompt Engineering has become increasingly vital. The key concepts of Prompt Engineering include prompts and prompting the AI, training the AI, developing and maintaining a prompt library, and testing, evaluation, and categorization.\\n")],
'question': 'What is the concept of prompt engineering and how is it applied '
'in artificial intelligence?'}
'\\n---\\n'
---GENERATE---
"Node 'generate':"
{ 'documents': [ Document(page_content="Prompt engineering is the method to ask generative AI to produce what the individual needs. There are two main principles of building a successful prompt for any AI, specificity and iteration. The box below includes one example of a framework that can be applied when prompting any generative AI.\\nPrompt Engineering is the process of designing and refining text inputs (prompts) to achieve specific application objectives with AI models. Think of it as a two-step journey: Designing the Initial Prompt: Creating the initial input for the model to achieve the desired result. Refining the Prompt: Continuously adjusting the prompt to enhance ...\\nPrompt engineering is the process of designing and refining the inputs given to language models, like those in AI, to achieve desired outputs more effectively. It involves creatively crafting prompts that guide the model in generating responses that are accurate, relevant, and aligned with the user's intentions.. For students and researchers in higher education, mastering prompt engineering is ...\\nJune 25, 2024. Prompt engineering means writing precise instructions for AI models. These instructions are different from coding because they use natural language. And today, everybody does it—from software developers to artists and content creators. Prompt engineering can help you improve productivity and save time by automating repetitive ...\\nMaster Prompt Engineering - The (AI) Prompt\\nAI Takes Wall Street by Storm: C3.ai's Strong Forecast Sparks a Surge in AI Stocks\\nAsk Me Anything (AMA) Prompting\\nHow Self-Critique Improves Logic and Reasoning in LLMs Like ChatGPT\\nOptimizing Large Language Models to Maximize Performance\\nThe Black Box Problem: Opaque Inner Workings of Large Language Models\\nHow to Evaluate Large Language Models for Business Tasks\\nIntroduction to the AI Prompt Development Process\\nSubscribe to new posts\\nThe Official Source For Everything Prompt Engineering & Generative AI Defining Prompt Engineering\\nGiven that the prompt is the singular input channel to large language models, prompt engineering can be defined as:\\nPrompt Engineering can be thought of as any process that contributes to the development of a well-crafted prompt to generate quality, useful outputs from an AI system.\\n A Simplified Approach to Defining Prompt Engineering\\nThe Prompt is the Sole Input\\nWhen interacting with Generative AI Models such as large language models (LLMs), the prompt is the only thing that gets input into the AI system. Its applications cut across diverse sectors, from healthcare and education to business, securing its place as a cornerstone of our interactions with AI.\\nExploration of Essential Prompt Engineering Techniques and Concepts\\nIn the rapidly evolving landscape of Artificial Intelligence (AI), mastering key techniques of Prompt Engineering has become increasingly vital. The key concepts of Prompt Engineering include prompts and prompting the AI, training the AI, developing and maintaining a prompt library, and testing, evaluation, and categorization.\\n")],
'generation': 'Prompt engineering is the process of designing and refining '
'text inputs to guide AI models in generating desired outputs. '
'It focuses on specificity and iteration to create effective '
'prompts that align with user intentions. This technique is '
'widely applicable across various sectors, enhancing '
'productivity and automating tasks.',
'question': 'What is the concept of prompt engineering and how is it applied '
'in artificial intelligence?'}
'\\n---\\n'
('Prompt engineering is the process of designing and refining text inputs to '
'guide AI models in generating desired outputs. It focuses on specificity and '
'iteration to create effective prompts that align with user intentions. This '
'technique is widely applicable across various sectors, enhancing '
'productivity and automating tasks.')
CRAG की सीमाएँ
यद्यपि CRAG पारंपरिक RAG में सुधार लाता है, फिर भी इसमें कुछ सीमाएँ हैं जिन पर ध्यान देना आवश्यक है।
एक बड़ा मुद्दा retrieval evaluator की गुणवत्ता पर निर्भरता है। यह evaluator यह आँकने में महत्वपूर्ण है कि प्राप्त दस्तावेज़ प्रासंगिक और सटीक हैं या नहीं। हालाँकि, evaluator का प्रशिक्षण और fine-tuning करना चुनौतीपूर्ण हो सकता है, जिसमें बहुत-सा उच्च-गुणवत्ता डेटा और कंप्यूटेशनल शक्ति की आवश्यकता होती है। नए प्रकार की क्वेरीज़ और डेटा स्रोतों के साथ evaluator को अद्यतन रखना जटिलता और लागत बढ़ाता है।
एक और सीमा यह है कि गलत या संदिग्ध दस्तावेज़ों को ढूँढने या बदलने के लिए CRAG वेब सर्च का उपयोग करता है। यद्यपि यह तरीका अधिक हालिया और विविध जानकारी प्रदान कर सकता है, यह पक्षपातपूर्ण या अविश्वसनीय डेटा लाने का जोखिम भी पैदा करता है। वेब सामग्री की गुणवत्ता बहुत भिन्न होती है, और सबसे सटीक जानकारी ढूँढने के लिए उसे छाँटना चुनौतीपूर्ण हो सकता है। इसका मतलब है कि एक अच्छे से प्रशिक्षित evaluator भी निम्न-गुणवत्ता या पक्षपातपूर्ण जानकारी के शामिल होने को पूरी तरह नहीं रोक सकता।
ये चुनौतियाँ निरंतर शोध और विकास की आवश्यकता को रेखांकित करती हैं।
निष्कर्ष
कुल मिलाकर, CRAG, प्राप्त जानकारी की जाँच और परिष्करण जोड़कर पारंपरिक RAG सिस्टम्स में सुधार करता है, जिससे भाषा मॉडल अधिक सटीक और भरोसेमंद बनते हैं। यह CRAG को कई अलग-अलग अनुप्रयोगों के लिए उपयोगी टूल बनाता है।
CRAG के बारे में अधिक जानने के लिए मूल शोध-पत्र देखें यहाँ।
यदि आप RAG पर और सीखने के संसाधन ढूँढ रहे हैं, तो मैं ये ब्लॉग्स सुझाता हूँ:
रायन एक लीड डेटा साइंटिस्ट हैं जो LLMs का उपयोग करके एआई अनुप्रयोग बनाने में विशेषज्ञता रखते/रखती हैं। वे इम्पीरियल कॉलेज लंदन में नैचुरल लैंग्वेज प्रोसेसिंग और नॉलेज ग्राफ्स में पीएचडी उम्मीदवार हैं, जहाँ से उन्होंने कंप्यूटर साइंस में अपना मास्टर’स भी पूरा किया है। डेटा साइंस के अलावा, वे साप्ताहिक Substack न्यूज़लेटर The Limitless Playbook लिखते हैं, जिसमें वे दुनिया के अग्रणी विचारकों से एक क्रियान्वयन योग्य विचार साझा करते हैं और समय-समय पर मूलभूत एआई अवधारणाओं पर भी लिखते हैं।

Retrieval-augmented generation (RAG) बाहरी स्रोत से प्रासंगिक दस्तावेज़ लाकर पाठ जनरेशन को सपोर्ट करके large language models में सुधार करता है। हालांकि, RAG पूर्ण नहीं है—यदि प्राप्त दस्तावेज़ सटीक या प्रासंगिक नहीं हैं, तो यह अभी भी भ्रामक सामग्री उत्पन्न कर सकता है।
इन समस्याओं से निपटने के लिए corrective retrieval-augmented generation (CRAG) प्रस्तावित किया गया। CRAG, जनरेशन से पहले प्राप्त जानकारी की जाँच और परिष्करण का एक चरण जोड़कर काम करता है। इससे भाषा मॉडल अधिक सटीक बनते हैं और भ्रामक सामग्री जनरेट होने की संभावना कम होती है।
इस लेख में, मैं CRAG का परिचय दूँगा और LangGraph का उपयोग करके चरण-दर-चरण इम्प्लीमेंटेशन कराऊँगा।