RAGAS के साथ Graph RAG का मूल्यांकन

LangChain और Neo4j के साथ Graph RAG

Adam Cowley

Manager, Developer Education at Neo4j

Text-to-Cypher

 

परिणाम prompt में जोड़े जाते हैं और LLM को भेजने के लिए तैयार रहते हैं

 

रिव्यू @emileifrem स्क्रीन नेम वाले Person द्वारा पोस्ट किया गया है

LangChain और Neo4j के साथ Graph RAG

Graph RAG का मूल्यांकन

 

  1. time से एंड-टू-एंड जेनरेशन का मूल्यांकन
  2. tiktoken से टोकन उपयोग और लागत का मूल्यांकन
  3. ragas से आउटपुट गुणवत्ता का मूल्यांकन
    • Context precision
    • Noise sensitivity

 

performance_tradeoffs.jpg

1 Image generated with GPT-4o
LangChain और Neo4j के साथ Graph RAG

Noise Sensitivity

  • प्राप्त डॉक्यूमेंट्स में अप्रासंगिक जानकारी की मात्रा मापता है
  • केवल vector search में यह अधिक होता है
  • प्रासंगिक जानकारी के आधार पर स्कोर देता है
from ragas.metrics import NoiseSensitivity


metric = NoiseSensitivity( llm=evaluator_llm, mode="irrelevant" )
1 https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/noise_sensitivity/
LangChain और Neo4j के साथ Graph RAG

Context Precision

  • प्राप्त डॉक्यूमेंट्स में प्रासंगिक chunks का अनुपात मापता है
  • स्कोर अधिक होने का अर्थ, प्राप्त जानकारी अधिक प्रासंगिक है
from ragas.metrics import LLMContextPrecisionWithReference


metric = LLMContextPrecisionWithReference( llm=evaluator_llm, )
1 https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/context_precision/#llm-based-context-precision
LangChain और Neo4j के साथ Graph RAG

Context Precision

  • प्राप्त डॉक्यूमेंट्स में प्रासंगिक chunks का अनुपात मापता है
  • स्कोर अधिक होने का अर्थ, प्राप्त जानकारी अधिक प्रासंगिक है
from ragas.metrics import LLMContextPrecisionWithoutReference


metric = LLMContextPrecisionWithoutReference( llm=evaluator_llm, )
LangChain और Neo4j के साथ Graph RAG

Text-to-Cypher परिणाम संरचना

cypher_result = {

"user_input": "Who is Romeo's love?",
"response": "Romeo loves Juliet",
"retrieved_contexts": [ { "source": "Romeo", "target": "Juliet", "relationship": "LOVES", "sentiment": 0.9837 }, ]
}
LangChain और Neo4j के साथ Graph RAG

Text-to-Cypher परिणाम संरचना

cypher_result = {
    "user_input": "Who is Romeo's love?",
    "response": "Romeo loves Juliet",
    "retrieved_contexts": [
        json.dumps({
            "source": "Romeo",
            "target": "Juliet",
            "relationship": "LOVES",
            "sentiment": 0.9837
        }),
    ]
}
LangChain और Neo4j के साथ Graph RAG

केवल Vector परिणाम संरचना

vector_result = { 
    "user_input": "Who is Romeo's love?",
    "response": "Romeo loves Juliet",
    "retrieved_contexts": [

"But, soft! what light through yonder window breaks?..." "O, she doth teach the forches to burn bright!"
] }
LangChain और Neo4j के साथ Graph RAG

हाइब्रिड परिणाम संरचना

hybrid_result = {
    "user_input": "Who is Romeo's love?",
    "response": "Romeo loves Juliet",

"retrieved_contexts": [
json.dumps({ "page_content": "But, soft! what light through yonder window breaks? ...",
"metadata": {
"act": 2, "scene": 2, "spoken_to": "Juliet"
}
}),
# ...
] }
LangChain और Neo4j के साथ Graph RAG

मूल्यांकन डेटासेट बनाना

cypher_result = {
    "user_input": "Who is Romeo's love?",
    "retrieved_contexts": [
        json.dumps({
            "source": "Romeo",
            "target": "Juliet",
            "relationship": "LOVES",
            "sentiment": 0.9837
        }),
    ]
}


cypher_dataset = EvaluationDataset.from_list([cypher_result])
LangChain और Neo4j के साथ Graph RAG

मूल्यांकन के लिए LLM चुनना

from langchain.chat_models import init_chat_model

# मूल्यांकन के लिए एक LLM चुनें
llm = init_chat_model(
    "gpt-4o-mini",
    model_provider="openai",
    api_key="...",
    temperature=0
)


# LangchainLLMWrapper में लपेटें from ragas.llms import LangchainLLMWrapper evaluator_llm = LangchainLLMWrapper(llm)
LangChain और Neo4j के साथ Graph RAG

रेस्पॉन्स का मूल्यांकन

from ragas import evaluate, EvaluationDataset
from ragas.metrics import LLMContextPrecisionWithoutReference, NoiseSensitivity

cypher_scores = evaluate(

dataset=cypher_dataset,
metrics=[
LLMContextPrecisionWithoutReference(llm=evaluator_llm),
NoiseSensitivity(llm=evaluator_llm, mode="irrelevant")
]
)
{'llm_context_precision_without_reference': 1.0000,
'noise_sensitivity(mode=irrelevant)': 0.0000}
LangChain और Neo4j के साथ Graph RAG

अभ्यास करते हैं!

LangChain और Neo4j के साथ Graph RAG

Preparing Video For Download...