RAG Evaluation (Document Relevance) | LangSmith Evaluations - Part 14

LangChain
30 Apr 202406:46

Summary

TLDRランチェインのLanceが14回目のビデオで、ランチェイン・スミスの評価について解説しました。以前のビデオでは、RAG(Retrieval-Augmented Generation)生成の答えと参照答えの比較、RAG生成の答えと関連文書の比較を行い、本稿では、問い合わせと検索された文書を比較するという新しいテストについて語ります。これは検索品質や正確性に対する非常に良いテストです。ビデオでは、ランチェインを使用する必要がないという共通の疑問に触れ、その答えは「いいえ」であると説明しました。重要なのは、任意の関数呼び出しをランチェイン・スミスに接続できるという点です。評価セットは、以前に説明したように入力出力をペアにして定義されています。以前に参照答えの評価と、答えの幻覚評価について話しましたが、今回は問い合わせと文書を比較する評価についてです。これは、RAGで非常に一般的です。評価のプロンプトは非常にシンプルで、入力の問い合わせと予測の文書を比較するだけで、基準を満たすかどうかを評価します。評価の結果は、評価スコアとして表示され、各問い合わせと検索された文書の関連性を示します。この方法は、参照がない場合に入力問い合わせと検索文書を比較する際に非常に適しています。

Takeaways

  • 🔍 ランチェインのドキュメンテーションをインデックス化し、検索品質や正確性をテストすることが重要です。
  • 🛠️ ランチェインを使用しなくても、ランスミスを使用することができます。任意の関数呼び出しをランスミスに記録することができます。
  • 📚 評価セットは、インデックスドキュメントに基づく質問と回答のペアです。
  • 📈 参照回答と比較した評価、および回答の幻覚評価が以前に説明されました。
  • 🟢 緑色のバーでは、質問と検索されたドキュメントを比較し、検索品質をテストします。
  • 📝 評価プロンプトはシンプルで、入力質問と予測(取得されたドキュメント)を比較する基準を提供します。
  • 🔑 ランチェインの文字列バリデーターを使用して、質問と取得ドキュメントを比較します。
  • 📊 スコア文字列バリデーターを使用して、ドキュメントが入力質問に関連しているかどうかを評価します。
  • 🌟 正規化基準として、0が関連性なし、5が一部関連、10が全て関連していることを意味します。
  • 📈 評価結果は、入力質問と取得ドキュメントの関連性スコアを示します。
  • 🔎 個別の評価結果を確認し、スコアリングの理由を理解することができます。
  • 📚 この方法は、ランチェインを使用して検索評価を実施する方法を示しています。

Q & A

  • ランチェインのドキュメンテーションをインデックス化するために必要なものは何ですか?

    -ランチェインのドキュメンテーションをインデックス化するためには、ランチェインを使用する必要はありません。重要なのは、関数の定義と、その関数をLangSmithに登録することです。

  • ランチェインを使用しない場合でも、ランスミスを使用できますか?

    -はい、ランスミスを使用することができます。ランスミスは、任意の関数呼び出しや特定のモデルAPIに接続することができます。

  • 評価セットの入力と出力ペアはどのようにして得られますか?

    -評価セットの入力と出力ペアは、インデックス化されたドキュメントに基づいて得られます。これらのペアは、質問とそれに対応する回答から成るものです。

  • 参照回答とは何ですか?

    -参照回答とは、生成された回答と比較するために使用される正確な回答です。これは、回答の質を評価するために使用されます。

  • 回答のハロウセン評価とは何ですか?

    -回答のハロウセン評価とは、生成された回答が参照文書から離れている場合に、そのような現象をテストするプロセスです。

  • ドキュメントの検索品質をテストするために使用される緑色のバーとは何ですか?

    -緑色のバーは、検索されたドキュメントを質問と比較するプロセスを表しています。これは、検索品質や正確性をテストするのに非常に役立ちます。

  • ランチェインの文字列バリデータとは何ですか?

    -ランチェインの文字列バリデータとは、質問と検索されたドキュメントを比較するために使用されるツールです。これは、入力と予測の関係を評価するのに使われます。

  • 評価プロンプトには何が必要ですか?

    -評価プロンプトには、入力質問と予測(検索されたドキュメントや任意の回答)が必要です。また、評価基準として、ドキュメントが入力に関連しているかどうかをスコア付けします。

  • スコアリングバリデータの役割は何ですか?

    -スコアリングバリデータは、入力質問と検索されたドキュメントの関連性を評価し、その結果をスコアで示します。これにより、検索品質を客観的に評価することができます。

  • 評価結果を表示する際に使用されるメトリックは何ですか?

    -評価結果を表示する際には、入力質問と検索されたドキュメントの関連性のスコアを使用します。これは、ドキュメントが質問にどれだけ関連しているかを示します。

  • 評価結果を確認する際に、どのような情報を得られますか?

    -評価結果を確認する際には、各ドキュメントが質問に関連しているかどうかのスコアと、そのスコアの詳細な説明が得られます。これにより、検索結果の質を理解し、改善の余地を特定することができます。

  • ランスミスを使用して検索評価を行う際の利点は何ですか?

    -ランスミスを使用して検索評価を行うことで、検索されたドキュメントが質問にどれほど関連しているかを客観的に評価することができます。また、検索品質の向上や、検索アルゴリズムの最適化に役立ちます。

Outlines

00:00

📈 ランチェインの評価方法: ドキュメントの関連性の評価

ランチェインを使用して、Smithの評価方法について解説しています。このビデオでは、以前のビデオで触れたRAG(Retrieval-Augmented Generation)の評価方法に加えて、検索されたドキュメントと質問の関連性評価について説明しています。ランチェイン自体は使用していませんが、ランスミスに接続するためにtraceable decoratorを使用しています。評価の際には、ランチェインの文字列バリデータを使用し、質問と検索されたドキュメントを比較します。評価のプロンプトはシンプルで、入力質問と予測(検索されたドキュメント)を比較するためだけの基準を提供しています。

05:02

📊 RAG評価の結果: ドキュメントの関連性のスコア

この段落では、RAG評価の結果を紹介しています。新しい実験の結果を表示し、メトリックの表示を選択できます。入力質問と検索されたドキュメントの関連性スコアを比較し、精度を評価しています。各評価の詳細を表示し、スコアリングの根拠を確認することができます。この評価方法は、参考回答がない場合のドキュメントの関連性評価に役立ちます。

Mindmap

Keywords

💡Lang chain

「Lang chain」とは、ビデオの主題に沿って文書をインデックスし、検索機能を提供するツールです。ビデオでは、Lang chainを使用してドキュメントをインデックスし、検索の質を評価するプロセスが説明されています。

💡Rag eval

「Rag eval」とは、Retrieve And Generate(RAG)モデルの応答を評価するプロセスを指します。ビデオでは、RAG生成された答えと参照答えを比較し、ドキュメントの関連性をテストする手法が紹介されています。

💡Traceable decorator

「Traceable decorator」とは、関数の呼び出しをログとして記録する機能を提供するプログラミングの装飾子です。ビデオでは、このデコレータを使用して、任意の関数呼び出しをLang Smithに接続し、関数の結果を記録する方法が説明されています。

💡Retrieval quality

「Retrieval quality」とは、検索システムが返す情報の質を評価する指標です。ビデオでは、検索ドキュメントが質問にどれだけ関連しているかをテストすることで、検索の質を評価する方法が説明されています。

💡Answer hallucination eval

「Answer hallucination eval」とは、生成された答えが参照答えとどれだけ一致しているかを評価するプロセスです。ビデオでは、検索ドキュメントと答えを比較し、ハローケーション(虚構)のテストを行う方法が紹介されています。

💡Score string evaluator

「Score string evaluator」とは、文字列同士を比較し、関連性や一致度をスコア付けする評価ツールです。ビデオでは、質問と検索ドキュメントの関連性を評価するために使用され、スコアに基づいてドキュメントの関連性を判断します。

💡Vector store

「Vector store」とは、検索システムで使用されるデータベースの一種で、情報をベクトル形式で格納し、高速な検索が可能にします。ビデオでは、検索ドキュメントがベクトルストアから取得されるプロセスが説明されています。

💡Normalization criteria

「Normalization criteria」とは、評価スコアを一定の範囲内に収めるための基準です。ビデオでは、ドキュメントの関連性スコアを0から10の範囲で正規化し、関連性の強さを示す方法が説明されています。

💡Instrument of retrieval evaluation

「Instrument of retrieval evaluation」とは、検索結果の質を測定するツールや手法を指します。ビデオでは、入力質問と取得されたドキュメントを比較し、検索の質を評価するプロセスが説明されています。

💡Document relevance

「Document relevance」とは、検索によって取得されたドキュメントが、入力された質問に対してどれだけ関連性があるかを示す指標です。ビデオでは、ドキュメントの関連性スコアに基づいて、検索の質を評価する方法が紹介されています。

💡Evaluation prompt

「Evaluation prompt」とは、評価プロセスで使用される入力例や質問の形式です。ビデオでは、評価プロンプトを使用して、検索ドキュメントが質問にどれだけ適切に答えるかを評価する方法が説明されています。

Highlights

This is the 14th video focused on LangChain's Smith valuations

The last two videos discussed RagEval and comparing Rag-generated answers to reference answers and relevant documents

The video will focus on comparing retrieved documents to the question, a test for retrieval quality or accuracy

LangChain is indexed with a set of documentation, but is not used for this evaluation

LangSmith can be used with any arbitrary function call or model API, not just LangChain

The traceable decorator is used to log function calls to LangSmith

A dataset of input-output question-answer pairs is defined based on the indexed documents

Answer hallucination evaluation is discussed, comparing retrieved documents to the answer

LangChain's string evaluator is used to compare the question (input) to retrieved documents (prediction)

There is no ground truth or reference answer for this evaluation, only the question and retrieved documents are compared

The evaluation prompt is simple, providing the input question and a placeholder for the prediction (retrieved documents)

The information flow involves extracting the question from examples, performing retrieval, and mapping the question to retrieved documents as the prediction

LangChain's score string evaluator is used, with criteria based on document relevance to the question

The evaluator is defined with the eval set, and the evaluation is kicked off

The experiment can be viewed, with metrics like accuracy scores for question-document comparison displayed

The prompt itself can be assessed to understand the grading, with the assistant's answer incorporating retrieved documents

The assistant's response is evaluated based on relevance to the user's question, with a scoring system from 0-10

Different responses may receive variable scores based on the relevance and reasoning provided

This demonstrates how to instrument retrieval evaluation in LangSmith using the score string evaluator

The focus is on document relevance in this third type of Rag evaluation

Transcripts

play00:01

hi this is Lance from Lang chain this is

play00:02

our 14th video focused on Langs Smith

play00:05

valuations so our last two video talked

play00:07

about rag eval and we talked through

play00:09

first comparing our rag generated answer

play00:11

to a reference answer we talked about

play00:14

comparing our rag generated answer to

play00:15

relevant documents this thing here in

play00:17

the red to test for things like

play00:19

hallucinations and now we're going to

play00:20

talk about this green bar so comparing

play00:22

our retriev documents to the question

play00:24

and this is a really nice test for

play00:25

retrieval quality or

play00:27

accuracy so one thing just Refresh on WE

play00:31

index a set of Lang chain

play00:33

documentation and our rag chain is

play00:35

defined right here and one thing you'll

play00:37

notice that we're not actually using

play00:38

Lang chain for any of this and this is a

play00:40

big common question that comes up is do

play00:42

I need to use Lang chain to use Langs

play00:43

Smith and of course the answer is no

play00:46

you'll see right here all I'm doing is

play00:48

I'm basically defining my function that

play00:49

performs all the he heavy lifting this

play00:51

is really where my answer is generated

play00:53

here I'm calling basically open a API

play00:55

using this wrap thing um but the key

play00:57

point is this with this traceable

play00:59

decorator this function call is

play01:00

basically just log to Langs Smith um so

play01:03

that's a way we can connect any

play01:04

arbitrary function call that you know

play01:06

hits any particular model API we want

play01:08

doesn't have to use Lang Lang chain at

play01:10

all with this traceable decer I can then

play01:12

register that function to Langs Smith

play01:14

and so uh the results of this function

play01:16

are going to be logged and we'll see

play01:17

that

play01:19

shortly

play01:20

um so we defined a data set we already

play01:24

went through this but I'll just refresh

play01:25

very quickly input output pairs question

play01:27

answer pairs based upon our again index

play01:29

doc doents which are here um so that's

play01:32

our eval set now we previously talked

play01:35

about again that reference answer to

play01:36

answer evaluation so that's what we

play01:38

talked about here um we talked about

play01:40

answer hallucination eval so that's

play01:43

comparing as you see in our flow here

play01:45

comparing the retrieve documents to our

play01:47

answer okay now we're going to talk

play01:49

about again comparing documents to our

play01:52

question so that's kind of the third

play01:54

type of evales that are very common in

play01:55

Rag and you know again you'll see that

play01:58

we're just going to use a line chain

play01:59

string of valuator just like before um

play02:02

and that makes sense because we're

play02:03

comparing a question which is a string

play02:05

to retrieve documents which are

play02:08

strings um and you'll see previously we

play02:11

used again up here the label score

play02:15

string evaluator uh for comparing our um

play02:19

answer to our uh context or this is you

play02:23

know again the hallucination test here

play02:26

comparing our context to the question

play02:29

we'll just use a score string evaluator

play02:32

and this and that's just simply because

play02:34

we don't actually have kind of a ground

play02:35

truth or reference for this particular

play02:37

case uh we have a question and we have

play02:40

retriev documents and so those are

play02:42

really the only two entities that we

play02:43

care about evaluating here um and you

play02:46

can actually look at the prompt we use

play02:48

for evaluation I already have it open

play02:50

here basically it's pretty simple we

play02:52

Supply some criteria there's your input

play02:54

question and then there is a prediction

play02:57

and this prediction is a placeholder it

play02:59

can be retrieve documents it can be any

play03:02

kind of answer that we want right um so

play03:04

again it's just basically a two-part

play03:06

evaluation comparing our input to a

play03:10

prediction given some criteria so that's

play03:12

nicely suited for this problem because

play03:14

in this case we only have an input

play03:16

question and retrieve

play03:19

documents um so that's really all we

play03:23

need to cover here and you can kind of

play03:25

see in the information flow kind of it

play03:27

follows what we showed previously where

play03:29

we have our examples in blue here so

play03:31

from the examples we simply just fish

play03:33

out the question that's the input and

play03:36

then we pass in the question to our rag

play03:39

chain we get we perform retrieval so we

play03:42

get these documents out so then those

play03:44

documents are just a prediction so again

play03:46

we're mapping from our question is our

play03:49

input the context are then are is our

play03:53

prediction um and again you recall that

play03:57

every line chain string of valer just

play03:58

simply has a few different common Keys

play04:01

input prediction and reference if

play04:03

applicable in this case we don't have a

play04:05

reference um and so here we're actually

play04:08

just going to Define our evaluator this

play04:09

follows a lot of what we did previously

play04:11

so we're using the score string

play04:13

evaluator but in this case because we

play04:15

don't have a reference our criteria is

play04:17

just simply something like this this is

play04:19

an answer a set of um documents

play04:22

retrieved from a vector store the input

play04:24

is a question used for retrieval score

play04:26

whether documents are relevant to the

play04:28

input and then we give some normal

play04:29

ization criteria um you know zero means

play04:32

that none of none of them are relevant

play04:34

five means some are relevant 10 means

play04:35

they're all relevant so that's all we

play04:37

need to do here we can Define our

play04:39

evaluator now again we're use the same

play04:41

eval set we did before so it's rag test

play04:44

LC um we can kick that off so we've just

play04:48

kicked off for

play04:50

evaluation and we'll let that run for a

play04:52

little bit so we can kind of go over and

play04:55

we can look at our eell set so again you

play04:56

can see here is our examples these are

play04:58

the input output pairs here's all the

play05:01

experiments we've run uh so this is the

play05:03

newest experiment that we just and we

play05:05

can see that open up our

play05:09

experiment and if you go to this display

play05:11

you can choose what metrics you actually

play05:12

want to show so in this case we can

play05:15

choose to toggle on or off the eval

play05:16

scores in this case we're going to show

play05:17

our eval scores these are our accuracy

play05:20

scores from that comparing our input to

play05:24

the uh the input question to the re

play05:27

documents and here we can just open this

play05:30

up we can actually look at the prompt

play05:31

itself to assess the grading so here was

play05:35

the grer chain um and you can see it

play05:38

follows the prompt that we showed here

play05:41

you know basically the question ins

play05:42

start of the assistant's answer in this

play05:44

case you can see the assistant's answer

play05:45

has the retriev documents plummed in

play05:47

there um and you can see the question is

play05:50

here and you can see you know gives a

play05:54

very nice kind of detail explanation as

play05:56

to its scoring in this case it scores it

play05:58

as a 10 the assistant response is

play06:00

relevant to the user's question um we

play06:03

can look at some of the other ones we

play06:05

can see you know the scoring is is a bit

play06:06

more variable so in this case it only

play06:08

scores as a.3 we can go we can kind of

play06:11

sity check we can look at uh some of the

play06:14

the reasoning for the scoring so anyway

play06:16

this shows you very simply how to

play06:17

instrument of retrieval evaluation using

play06:21

in using ideas we talked already uh

play06:23

about um except that we simply use the

play06:25

scoring evaluator because we don't

play06:28

actually have in this particular case

play06:30

uh what you might call reference we're

play06:31

only comparing two things in this case

play06:33

we're comparing our our input question

play06:36

to the retrieve documents as the

play06:37

prediction so this shows you a third way

play06:39

to run rag evaluations in this

play06:41

particular case uh for document

play06:43

relevance thanks

Rate This

5.0 / 5 (0 votes)

Related Tags
ランチェインRAG評価ドキュメンテーション情報検索API評価指標精度テスト回答品質テキスト比較AI評価
Do you need a summary in English?