Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions docs/integrations/langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@
"nest_asyncio.apply()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8333f65e",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"id": "842e32dc",
Expand All @@ -62,7 +51,9 @@
"\n",
"llm = ChatOpenAI()\n",
"qa_chain = RetrievalQA.from_chain_type(\n",
" llm, retriever=index.vectorstore.as_retriever(), return_source_documents=True,\n",
" llm,\n",
" retriever=index.vectorstore.as_retriever(),\n",
" return_source_documents=True,\n",
")"
]
},
Expand Down Expand Up @@ -115,15 +106,17 @@
"]\n",
"\n",
"eval_answers = [\n",
" \"8,804,000\", # incorrect answer\n",
" \"Queens\", # incorrect answer\n",
" \"8,804,000\", # incorrect answer\n",
" \"Queens\", # incorrect answer\n",
" \"New York City's economic significance is vast, as it serves as the global financial capital, housing Wall Street and major financial institutions. Its diverse economy spans technology, media, healthcare, education, and more, making it resilient to economic fluctuations. NYC is a hub for international business, attracting global companies, and boasts a large, skilled labor force. Its real estate market, tourism, cultural industries, and educational institutions further fuel its economic prowess. The city's transportation network and global influence amplify its impact on the world stage, solidifying its status as a vital economic player and cultural epicenter.\",\n",
" \"New York City got its name when it came under British control in 1664. King Charles II of England granted the lands to his brother, the Duke of York, who named the city New York in his own honor.\",\n",
" 'The Statue of Liberty in New York City holds great significance as a symbol of the United States and its ideals of liberty and peace. It greeted millions of immigrants who arrived in the U.S. by ship in the late 19th and early 20th centuries, representing hope and freedom for those seeking a better life. It has since become an iconic landmark and a global symbol of cultural diversity and freedom.',\n",
" \"The Statue of Liberty in New York City holds great significance as a symbol of the United States and its ideals of liberty and peace. It greeted millions of immigrants who arrived in the U.S. by ship in the late 19th and early 20th centuries, representing hope and freedom for those seeking a better life. It has since become an iconic landmark and a global symbol of cultural diversity and freedom.\",\n",
"]\n",
"\n",
"examples = [{\"query\": q, \"ground_truths\": [eval_answers[i]]} \n",
" for i, q in enumerate(eval_questions)]"
"examples = [\n",
" {\"query\": q, \"ground_truths\": [eval_answers[i]]}\n",
" for i, q in enumerate(eval_questions)\n",
"]"
]
},
{
Expand Down Expand Up @@ -196,7 +189,12 @@
"outputs": [],
"source": [
"from ragas.langchain.evalchain import RagasEvaluatorChain\n",
"from ragas.metrics import faithfulness, answer_relevancy, context_relevancy, context_recall\n",
"from ragas.metrics import (\n",
" faithfulness,\n",
" answer_relevancy,\n",
" context_relevancy,\n",
" context_recall,\n",
")\n",
"\n",
"# create evaluation chains\n",
"faithfulness_chain = RagasEvaluatorChain(metric=faithfulness)\n",
Expand Down Expand Up @@ -469,10 +467,15 @@
"from langchain.smith import RunEvalConfig, run_on_dataset\n",
"\n",
"evaluation_config = RunEvalConfig(\n",
" custom_evaluators=[faithfulness_chain, answer_rel_chain, context_rel_chain, context_recall_chain],\n",
" custom_evaluators=[\n",
" faithfulness_chain,\n",
" answer_rel_chain,\n",
" context_rel_chain,\n",
" context_recall_chain,\n",
" ],\n",
" prediction_key=\"result\",\n",
")\n",
" \n",
"\n",
"result = run_on_dataset(\n",
" client,\n",
" dataset_name,\n",
Expand Down
Loading