Embedding-based Evaluator(embedding_distance)

Open in Colab Open in GitHub

Overview

The Embedding-based Evaluator (embedding_distance) part is designed to evaluate question-answering systems using various embedding models and distance metrics .

Table of Contents

References


Environment Setup

Setting up your environment is the first step. See the Environment Setup guide for more details.

[Note]

The langchain-opentutorial is a package of easy-to-use environment setup guidance, useful functions and utilities for tutorials. Check out the langchain-opentutorial for more details.

You can set API keys in a .env file or set them manually.

[Note] If you’re not using the .env file, no worries! Just enter the keys directly in the cell below, and you’re good to go.

Defining Functions for RAG Performance Testing

We will create a RAG system for testing purposes.

Create a function named ask_question to handle answering questions. The function takes a dictionary inputs as input and returns a dictionary answer as output.

Embedding Distance-based Evaluator

We will build a system for evaluating sentence similarity using various embedding models and distance metrics.

The code below defines configurations for each model and metric using the LangChainStringEvaluator.

[ Note ] For LangChainStringEvaluator, OpenAIEmbeddings is set as the default, but it can be changed.

When multiple embedding models are used for one metric , the results are averaged.

Example:

  • cosine : OpenAI

  • euclidean : OpenAI, Upstage

For euclidean , the average value across the models is calculated.

Last updated