RAGAS ile Graph RAG Değerlendirme

LangChain ve Neo4j ile Graph RAG

Adam Cowley

Manager, Developer Education at Neo4j

Metinden Cypher'a

 

Sonuçlar, LLM'e gönderilmeye hazır şekilde isteme eklenir

Vektör arama

 

İnceleme, ekran adı @emileifrem olan bir Kişi tarafından gönderildi

LangChain ve Neo4j ile Graph RAG

Graph RAG Değerlendirme

 

  1. time ile uçtan uca üretimi değerlendirme
  2. tiktoken ile token kullanımı ve maliyetleri değerlendirme
  3. ragas ile çıktı kalitesini değerlendirme
    • Bağlam kesinliği
    • Gürültü duyarlılığı

 

performans ödünleşimleri

1 Görsel GPT-4o ile oluşturuldu
LangChain ve Neo4j ile Graph RAG

Gürültü Duyarlılığı

  • Getirilen belgelerdeki alakasız bilgi miktarını ölçer
  • Yalnız vektör aramada daha yüksektir
  • İlgili bilgiye göre bir skor döndürür
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 ve Neo4j ile Graph RAG

Bağlam Kesinliği

  • Getirilen belgelerdeki ilgili parçaların oranını ölçer
  • Yüksek skor, getirilen bilginin daha ilgili olduğunu gösterir
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 ve Neo4j ile Graph RAG

Bağlam Kesinliği

  • Getirilen belgelerdeki ilgili parçaların oranını ölçer
  • Yüksek skor, getirilen bilginin daha ilgili olduğunu gösterir
from ragas.metrics import LLMContextPrecisionWithoutReference


metric = LLMContextPrecisionWithoutReference( llm=evaluator_llm, )
LangChain ve Neo4j ile Graph RAG

Text-to-Cypher sonuç yapısı

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 ve Neo4j ile Graph RAG

Text-to-Cypher sonuç yapısı

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 ve Neo4j ile Graph RAG

Yalnızca vektör sonuç yapısı

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 ve Neo4j ile Graph RAG

Hibrit sonuç yapısı

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 ve Neo4j ile Graph RAG

Değerlendirme veri kümesi oluşturma

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 ve Neo4j ile Graph RAG

Değerlendirme için LLM seçimi

from langchain.chat_models import init_chat_model

# Değerlendirme için bir LLM seçin
llm = init_chat_model(
    "gpt-4o-mini",
    model_provider="openai",
    api_key="...",
    temperature=0
)


# LangchainLLMWrapper ile sarmalayın from ragas.llms import LangchainLLMWrapper evaluator_llm = LangchainLLMWrapper(llm)
LangChain ve Neo4j ile Graph RAG

Yanıtları değerlendirme

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 ve Neo4j ile Graph RAG

Hadi pratik yapalım!

LangChain ve Neo4j ile Graph RAG

Preparing Video For Download...