LangChain ve Neo4j ile Graph RAG
Adam Cowley
Manager, Developer Education at Neo4j


time ile uçtan uca üretimi değerlendirmetiktoken ile token kullanımı ve maliyetleri değerlendirmeragas ile çıktı kalitesini değerlendirme

from ragas.metrics import NoiseSensitivitymetric = NoiseSensitivity( llm=evaluator_llm, mode="irrelevant" )
from ragas.metrics import LLMContextPrecisionWithReferencemetric = LLMContextPrecisionWithReference( llm=evaluator_llm, )
from ragas.metrics import LLMContextPrecisionWithoutReferencemetric = LLMContextPrecisionWithoutReference( llm=evaluator_llm, )
cypher_result = {"user_input": "Who is Romeo's love?","response": "Romeo loves Juliet","retrieved_contexts": [ { "source": "Romeo", "target": "Juliet", "relationship": "LOVES", "sentiment": 0.9837 }, ]}
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
}),
]
}
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!"] }
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"}}),# ...] }
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])
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)
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