LangSmith-Dataset

Open in Colabarrow-up-right Open in GitHubarrow-up-right

Overview

The notebook demonstrates how to create a dataset for evaluating Retrieval-Augmented Generation (RAG) models using LangSmith. It includes steps for setting up environment variables, creating datasets with questions and answers, and uploading examples to LangSmith for testing. Additionally, it provides instructions on using HuggingFace datasets and updating datasets with new examples.

Table of Contents

References


Environment Setup

Setting up your environment is the first step. See the Environment Setuparrow-up-right 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-opentutorialarrow-up-right 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.

You can alternatively set API keys such as OPENAI_API_KEY in a .env file and load them.

[Note] This is not necessary if you've already set the required API keys in previous steps.

Creating a LangSmith Dataset

Let's learn how to build a custom RAG evaluation dataset.

To construct a dataset, you need to understand three main processes:

Case: Evaluating whether the retrieval is relevant to the question

Question - Retrieval

Case: Evaluating whether the answer is relevant to the question

Question - Answer

Case: Checking if the answer is based on the retrieved documents (Hallucination Check)

Retrieval - Answer

Thus, you typically need Question, Retrieval, and Answer information. However, it is practically challenging to construct ground truth for Retrieval.

If ground truth for Retrieval exists, you can save and use it all in your dataset. Otherwise, you can create and use a dataset with only Question and Answer

Creating Examples for LangSmith Dataset

Use inputs and outputs to create a dataset.

The dataset consists of questions and answers.

question
answer

0

What is the name of the generative AI created ...

The name of the generative AI created by Samsu...

1

On what date did U.S. President Biden issue an...

On October 30, 2023, U.S. President Biden issu...

2

Please briefly describe Cohere's data provenan...

Cohere's data provenance explorer is a platfor...

Alternatively, you can use the Synthetic Dataset generated in a previous tutorial.

The code below shows an example of using an uploaded HuggingFace Dataset.

After installing the package, you may need to restart the kernel for the changes to take effect. This is because newly installed packages might not be recognized immediately in the current session.

In Google Colab, you must run %pip install each time you start a new session, even if you installed the package before. Colab environments are temporary, so installed packages are lost when the session restarts.

user_input
reference_contexts
reference
synthesizer_name

0

Wht is an API?

["Agents\nThis combination of reasoning,\nlogi...

An API can be used by a model to make various ...

single_hop_specifc_query_synthesizer

1

What are the three essential components in an ...

['Agents\nWhat is an agent?\nIn its most funda...

The three essential components in an agent's c...

single_hop_specifc_query_synthesizer

2

What Chain-of-Thought do in agent model, how i...

['Agents\nFigure 1. General agent architecture...

Chain-of-Thought is a reasoning and logic fram...

single_hop_specifc_query_synthesizer

3

Waht is the DELETE method used for?

['Agents\nThe tools\nFoundational models, desp...

The DELETE method is a common web API method t...

single_hop_specifc_query_synthesizer

4

How do foundational components contribute to t...

['<1-hop>\n\nAgents\ncombining specialized age...

Foundational components contribute to the cogn...

NewMultiHopQuery

Creating a Dataset for LangSmith Testing

  • Create a new dataset under Datasets & Testing.

You can also create a dataset directly using the LangSmith UI from a CSV file.

For more details, refer to the documentation below:

You can add examples to the dataset later.

Congratulations! The dataset is now ready.

Last updated