Saturday, May 24, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Evaluate RAGs Rigorously or Perish | by Jarek Grygolec, Ph.D. | Apr, 2024

May 5, 2024
in AI Technology
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter



“`html

The results presented in the Table 1 seem very appealing, at least to me. The simple evolution performs very well. In the case of the reasoning evolution the first part of question is answered perfectly, but the second part is left unanswered. Inspecting the Wikipedia page [3] it is evident that there is no answer to the second part of the question in the actual document, so it can also be interpreted as the restraint from hallucinations, a good thing in itself. The multi-context question-answer pair seems very good. The conditional evolution type is acceptable if we look at the question-answer pair. One way of looking at these results is that there is always space for better prompt engineering that are behind evolutions. Another way is to use better LLMs, especially for the critic role as is the default in the ragas library.

Metrics

The ragas library is able to not only generate the synthetic evaluation sets, but also provides us with built-in metrics for component-wise evaluation as well as end-to-end evaluation of RAGs.

Picture 2: RAG Evaluation Metrics in RAGAS. Image created by the author in draw.io.

As of this writing RAGAS provides out-of-the-box eight metrics for RAG evaluation, see Picture 2, and likely new ones will be added in the future. In general you are about to choose the metrics most suitable for your use case. However, I recommend to select the one most important metric, i.e.:

  • Answer Correctness — the end-to-end metric with scores between 0 and 1, the higher the better, measuring the accuracy of the generated answer as compared to the ground truth.

Focusing on the one end-to-end metric helps to start the optimisation of your RAG system as fast as possible. Once you achieve some improvements in quality you can look at component-wise metrics, focusing on the most important one for each RAG component:

  • Faithfulness — the generation metric with scores between 0 and 1, the higher the better, measuring the factual consistency of the generated answer relative to the provided context. It is about grounding the generated answer as much as possible in the provided context, and by doing so prevent hallucinations.
  • Context Relevance — the retrieval metric with scores between 0 and 1, the higher the better, measuring the relevancy of retrieved context relative to the question.

RAG Factory

OK, so we have a RAG ready for optimisation… not so fast, this is not enough. To optimise RAG we need the factory function to generate RAG chains with given set of RAG hyperparameters. Here we define this factory function in 2 steps:

  1. Step 1: A function to store documents in the vector database.
<# Defining a function to get document collection from vector db with given hyperparemeters
# The function embeds the documents only if collection is missing
# This development version as for production one would rather implement document level check
def get_vectordb_collection(chroma_client,documents,embedding_model=\"text-embedding-ada-002\",chunk_size=None, overlap_size=0) -> ChromaCollection:
  if chunk_size is None:
    collection_name = \"full_text\"
    docs_pp = documents
  else:
    collection_name = f\"{embedding_model}_chunk{chunk_size}_overlap{overlap_size}\"
    text_splitter = CharacterTextSplitter(separator=\".\",chunk_size=chunk_size,chunk_overlap=overlap_size,length_function=len,is_separator_regex=False,)
    docs_pp = text_splitter.transform_documents(documents)
  embedding = OpenAIEmbeddings(model=embedding_model)
  langchain_chroma = Chroma(client=chroma_client,collection_name=collection_name,embedding_function=embedding,)
  existing_collections = [collection.name for collection in chroma_client.list_collections()]
  if chroma_client.get_collection(collection_name).count() == 0:
    langchain_chroma.from_documents(collection_name=collection_name,documents=docs_pp,embedding=embedding)
  return langchain_chroma
```
  1. Step 2: A function to generate RAG in LangChain with document collection, or the proper RAG factory function.
<# Defininig a function to get a simple RAG as Langchain chain with given hyperparemeters
# RAG returns also the context documents retrieved for evaluation purposes in RAGAs
def get_chain(chroma_client,documents,embedding_model=\"text-embedding-ada-002\",llm_model=\"gpt-3.5-turbo\",chunk_size=None,overlap_size=0,top_k=4,lambda_mult=0.25) -> RunnableSequence:
  vectordb_collection = get_vectordb_collection(chroma_client=chroma_client,documents=documents,embedding_model=embedding_model,chunk_size=chunk_size,overlap_size=overlap_size)
  retriever = vectordb_collection.as_retriever(top_k=top_k, lambda_mult=lambda_mult)
  template = \"\"\"Answer the question based only on the following context.
  If the context doesn't contain entities present in the question say you don't know.{context}Question: {question}\"\"\"
  prompt = ChatPromptTemplate.from_template(template)
  llm = ChatOpenAI(model=llm_model)
  def format_docs(docs):
    return \"\\n\\n\".join([doc.page_content for doc in docs])
  chain_from_docs = (RunnablePassthrough.assign(context=(lambda x: format_docs(x[\"context\"])))| prompt| llm| StrOutputParser())
  chain_with_context_and_ground_truth = RunnableParallel(context=itemgetter(\"question\") | retriever,question=itemgetter(\"question\"),ground_truth=itemgetter(\"ground_truth\"),).assign(answer=chain_from_docs)
  return chain_with_context_and_ground_truth
```

The former function get_vectordb_collection is incorporated into the latter function get_chain, which generates our RAG chain for given set of parameters, i.e: embedding_model, llm_model, chunk_size, overlap_size, top_k, lambda_mult. With our factory function we are just scratching the surface of possibilities what hyperparmeters of our RAG system we optimise. Note also that RAG chain will require 2 arguments: question and ground_truth, where the latter is just passed through the RAG chain as it is required for evaluation using RAGAs.

“`



Source link

Tags: AprEvaluateGrygolecJarekPerishPh.DRAGsRigorously
Previous Post

Buffett says Berkshire in good hands, lauds Apple despite lowering stake By Reuters

Next Post

Researchers at Kassel University Introduce a Machine Learning Approach Presenting Specific Target Topologies (Tts) as Actions

Related Posts

How insurance companies can use synthetic data to fight bias
AI Technology

How insurance companies can use synthetic data to fight bias

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset
AI Technology

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
How Game Theory Can Make AI More Reliable
AI Technology

How Game Theory Can Make AI More Reliable

June 9, 2024
Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper
AI Technology

Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper

June 9, 2024
Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs
AI Technology

Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs

June 9, 2024
Deciphering Doubt: Navigating Uncertainty in LLM Responses
AI Technology

Deciphering Doubt: Navigating Uncertainty in LLM Responses

June 9, 2024
Next Post
Researchers at Kassel University Introduce a Machine Learning Approach Presenting Specific Target Topologies (Tts) as Actions

Researchers at Kassel University Introduce a Machine Learning Approach Presenting Specific Target Topologies (Tts) as Actions

What is Artificial Intelligence ( AI) in 2024?- Great Learning

What is Artificial Intelligence ( AI) in 2024?- Great Learning

BounceBit Mainnet Launch Scheduled for May 13, $BB Airdrop to Follow

BounceBit Mainnet Launch Scheduled for May 13, $BB Airdrop to Follow

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

April 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
Implementing User Authentication in React Apps with Appwrite — SitePoint

Implementing User Authentication in React Apps with Appwrite — SitePoint

January 30, 2024
NousResearch Released Nous-Hermes-2-Mixtral-8x7B: An Open-Source LLM with SFT and DPO Versions

NousResearch Released Nous-Hermes-2-Mixtral-8x7B: An Open-Source LLM with SFT and DPO Versions

January 25, 2024
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In