import{s as wa,a as Ua,n as ja,o as pa}from"../chunks/scheduler.1f027d5a.js";import{S as ia,i as Ia,e,s as a,c as U,h as ca,a as y,d as M,b as n,f as Ta,g as T,j as J,k as Ts,l as oa,m as t,n as w,t as j,o as p,p as i}from"../chunks/index.6117a65d.js";import{C as ua}from"../chunks/CopyLLMTxtMenu.0ff8411a.js";import{D as da,C as I}from"../chunks/DocNotebookDropdown.316c3715.js";import{H as c,E as ra}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.0eecd2bb.js";function Ca(Jt){let o,ps,ws,is,d,Is,r,cs,C,os,m,Ut='<em>作者 <a href="https://huggingface.co/m-ric" rel="nofollow">Aymeric Roucher</a></em>',us,b,Tt="本 notebook 演示了如何评估你的 RAG（Retrieval Augmented Generation），通过构建一个合成评估数据集并使用 LLM-as-a-judge 来计算你系统的准确性。",ds,h,wt='对于 RAG 系统的介绍，你可以查看<a href="rag_zephyr_langchain">这个技术指南</a>!',rs,B,jt="RAG 系统很复杂: 这里有一个 RAG 流程图，我们用蓝色标注了系统增强的所有可能性：",Cs,Z,pt,ms,G,it="实施上述任何改进都可能会带来巨大的性能提升；但如果无法监控对系统性能的影响，那么进行任何更改都是无用的！让我们看看如何评估我们的 RAG 系统。",bs,A,hs,Q,It="由于有如此多的部分需要调整，这些部分对性能有很大影响，因此对 RAG 系统进行基准测试是至关重要的。",Bs,W,ct="对于我们的评估流水线，我们将需要：",Zs,V,ot="<li>一个带有问题-答案对的评估数据集（QA 对）</li> <li>一个评估器，用于计算我们的系统在上面的评估数据集上的准确性。</li>",Gs,R,ut="➡️ 结果发现，我们可以在整个过程中使用 LLMs 来帮助！",As,X,dt='<li>评估数据集将由 LLM 🤖 合成生成，并且问题将由其他 LLM 🤖 过滤掉</li> <li>然后，<a href="https://huggingface.co/papers/2306.05685" rel="nofollow">LLM-as-a-judge</a> 智能体 🤖 将在这个合成数据集上执行评估。</li>',Qs,g,rt="<strong>让我们深入挖掘并开始构建我们的评估流水线！</strong> 首先，安装所需的模型依赖项。",Ws,f,Vs,N,Rs,k,Xs,v,gs,E,fs,S,Ns,Y,ks,F,Ct="我们首先构建一个问题和相关上下文的综合数据集。方法是先从我们的知识库中获取元素，并让 LLM 根据这些文档生成问题。",vs,_,mt="然后，我们设置其他 LLM 智能体作为生成问答对的质置过滤器：每个智能体将作为一个特定缺陷的过滤器。",Es,q,Ss,x,Ys,z,Fs,H,bt='我们采用 <a href="https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1" rel="nofollow">Mixtral</a> 作为问答对的生成，因为他在各个排行榜上表现极佳，比如 <a href="https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard" rel="nofollow">Chatbot Arena</a>。',_s,$,qs,L,xs,D,ht="现在让我们生成我们的问答对。",zs,K,Bt="对于这个例子，我们只生成 10 个问答对，并从 Hub 加载其余的。",Hs,P,Zt="但是对于你的特定知识库，考虑到你想要获得至少约 100 个测试样本，并且考虑到我们稍后会用我们的批判智能体过滤掉大约一半的样本，你应该生成更多的样本，超过 200 个。",$s,O,Ls,ll,Ds,sl,Ks,Ml,Gt="之前的智能体生成的问题可能存在许多缺陷：在验证这些问题之前，我们应该进行质量检查。",Ps,tl,At='因此，我们构建了批判智能体，它们将根据以下几个标准对每个问题进行评分，这些标准在<a href="https://huggingface.co/papers/2312.10003" rel="nofollow">这篇论文</a>中给出：',Os,al,Qt="<li><strong>具体性（Groundedness）</strong>：问题是否可以从给定的上下文中得到回答？</li> <li><strong>相关性（Relevance）</strong>：问题对用户是否相关？例如，<code>&quot;transformers 4.29.1 发布的日期是什么？&quot;</code>对于 ML 用户来说并不相关。</li>",lM,nl,Wt=`我们注意到的一个最后的失败案例是，当一个函数是为生成问题的特定环境量身定做的，但本身难以理解，比如<code>&quot;这个指南中使用的函数的名称是什么？&quot;</code>。
我们也为这个标准构建了一个批判智能体：`,sM,el,Vt="<li><strong>独立（Stand-alone）</strong>：对于一个具有领域知识/互联网访问权限的人来说，问题在没有任何上下文的情况下是否可以理解？与此相反的是，对于从特定博客文章生成的问题比如”这篇文章中使用的函数是什么？”</li>",MM,yl,Rt="我们系统地用所有这些智能体对函数进行评分，每当任何一个智能体的分数太低时，我们就从我们的评估数据集中删除这个问题。",tM,Jl,Xt="💡 <strong><em>当要求智能体输出分数时，我们首先要求它们产生其理由。这将帮助我们验证分数，但最重要的是，要求它首先输出理由给了模型更多的 token 来思考和详细阐述答案，然后再将其总结成一个单一的分数 token。</em></strong>",aM,Ul,gt="我们现在构建并运行这些批判智能体。",nM,Tl,eM,wl,yM,jl,ft="现在让我们基于我们批判智能体的分数过滤掉不好的问题：",JM,pl,UM,il,Nt=`Evaluation dataset before filtering:
`,TM,Il,kt="现在我们合成评估数据集已完成！我们可以在这个评估数据集上评估不同的 RAG 系统。",wM,cl,vt="我们在这里只生成了少数几个问答对，以减少时间和成本。下面，让我们通过加载一个预先生成的数据集来进行下一部分：",jM,ol,pM,ul,iM,dl,IM,rl,Et="<li>在这一部分，<strong>我们将知识库中的文档分割成更小的片段</strong>：这些将是被检索器选取的片段，然后被阅读器 LLM 作为支持其答案的元素。</li> <li>目标是构建语义上相关的片段：不要太小，以免不足以支持答案，也不要太大，以免稀释单个内容。</li>",cM,Cl,St="文本分割有许多选项：",oM,ml,Yt=`<li>每隔 <code>n</code> 个单词/字符分割，但这有可能割裂段落甚至句子</li> <li>在 <code>n</code> 个单词/字符后分割，但只在句子边界处</li> <li><strong>递归分割</strong> 尝试通过树状处理文档来保留更多文档结构，首先在最大单元（章节）上分割，然后递归地在更小单元（段落，句子）上分割。
要了解更多关于分块的信息，我建议你阅读由 Greg Kamradt 编写的<a href="https://github.com/FullStackRetrieval-com/RetrievalTutorials/blob/main/5_Levels_Of_Text_Splitting.ipynb" rel="nofollow">不错的教程</a> 。</li>`,uM,bl,Ft='<a href="https://huggingface.co/spaces/m-ric/chunk_visualizer" rel="nofollow">这个 space</a> 让你可视化不同的分割选项是如何影响你得到的片段的流程。',dM,hl,_t=`<p>在以下内容中，我们使用 Langchain 的 <code>RecursiveCharacterTextSplitter</code>。
💡 <em>为了在我们的文本分割器中测量片段长度，我们的长度函数将不是字符的数量，而是 token 化文本中的 token 数量：实际上，对于后续处理 token 的嵌入器来说，以 token 为单位测量长度更为相关，并且在经验上表现更好.</em></p>`,rM,Bl,CM,Zl,mM,Gl,bM,Al,qt="<strong>检索器的作用类似于内部搜索引擎</strong>：给定用户查询，它从你的知识库中返回最相关的文档。",hM,Ql,xt='<p>对于知识库，我们使用 Langchain 向量数据库，因为它提供了一个方便的 <a href="https://github.com/facebookresearch/faiss" rel="nofollow">FAISS</a> 索引，并允许我们在整个处理过程中保留文档元数据。</p>',BM,Wl,zt="🛠️ <strong>包含可选项：</strong>",ZM,Vl,Ht='<li>调整分块方法：<ul><li>片段(chunks)的大小</li> <li>方法：在不同的分隔符上分割，使用<a href="https://python.langchain.com/docs/modules/data_connection/document_transformers/semantic-chunker" rel="nofollow">语义分块</a>…</li></ul></li> <li>更改嵌入模型</li>',GM,Rl,AM,Xl,QM,gl,$t="在这一部分，<strong>LLM 阅读器读取检索到的文档以形成其答案。</strong>",WM,fl,Lt="🛠️ 为了改善结果，我们尝试了以下选项：",VM,Nl,Dt="<li>切换重排序开启或关闭的状态</li> <li>更改阅读器模型</li>",RM,kl,XM,vl,gM,El,fM,Sl,NM,Yl,Kt=`RAG 系统和评估数据集现在准备好了。最后一步是在这个评估数据集上判断 RAG 系统的输出。
为此，<strong>我们设置了一个裁判智能体</strong>。 ⚖️🤖`,kM,Fl,Pt='在<a href="https://docs.ragas.io/en/latest/concepts/metrics/index.html" rel="nofollow">不同的 RAG 评估指标</a>中，我们选择只关注忠实度，因为这是衡量我们系统性能的最佳的端到端指标。',vM,_l,Ot='<p>我们使用 GPT4 作为评判者，因为它在实际应用中表现良好，但你也可以尝试其他模型，例如 <a href="https://huggingface.co/kaist-ai/prometheus-13b-v1.0" rel="nofollow">kaist-ai/prometheus-13b-v1.0</a> 或 <a href="https://huggingface.co/BAAI/JudgeLM-33B-v1.0" rel="nofollow">BAAI/JudgeLM-33B-v1.0</a>。</p>',EM,ql,la='💡 <em>在评估提示中，我们给出了每个指标的详细描述，采用 1-5 分的评分刻度，正如 <a href="https://huggingface.co/kaist-ai/prometheus-13b-v1.0" rel="nofollow">Prometheus 的提示模板</a> 所做的那样：这有助于模型精确地确定其指标。如果你给评判 LLM 一个模糊的评分刻度，那么不同示例之间的输出将不够一致。</em>',SM,xl,sa="💡 <em>再次提示 LLM 在给出最终评分之前先输出其理由，这样它就有更多的 token 来帮助它正式化和详细阐述评判。</em>",YM,zl,FM,Hl,_M,$l,qM,Ll,Ma="🚀 让我们运行一下测试和评估一下答案!👇",xM,Dl,zM,Kl,HM,Pl,$M,Ol,LM,ls,DM,ss,KM,Ms,ta='让我们加载通过调整这个 notebook 中可用的不同选项所获得的结果。关于这些选项为何有效或无效的更多细节，请参阅 <a href="advanced_rag">高级 RAG</a> 的 notebook。',PM,ts,aa="正如在下面的图表中所看到的，一些调整并没有带来任何改善，而有些则带来了巨大的性能提升。",OM,as,na="➡️ <strong><em>所以没有单一的好方法：在调整你的 RAG 系统时，应该尝试几种不同的方向。</em></strong>",lt,ns,st,es,Mt,u,ea,tt,ys,ya="如上图所示，这些调整对性能的影响各不相同。尤其是调整片段大小，既简单又非常有影响力。",at,Js,Ja="但这只是针对我们的情况：你的结果可能大不相同：现在你已经有了一个可靠的评估流水线，可以开始探索其他选项了！🗺️",nt,Us,et,js,yt;return d=new da({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/zh-CN/rag_evaluation.ipynb"}]}}),r=new ua({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),C=new c({props:{title:"RAG 评估",local:"rag-评估",headingTag:"h1"}}),A=new c({props:{title:"评估RAG性能",local:"评估rag性能",headingTag:"h3"}}),f=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjAtcSUyMHRvcmNoJTIwdHJhbnNmb3JtZXJzJTIwdHJhbnNmb3JtZXJzJTIwbGFuZ2NoYWluJTIwc2VudGVuY2UtdHJhbnNmb3JtZXJzJTIwdHFkbSUyMG9wZW5weXhsJTIwb3BlbmFpJTIwcGFuZGFzJTIwZGF0YXNldHMlMjBsYW5nY2hhaW4tY29tbXVuaXR5JTIwcmFnYXRvdWlsbGU=",highlighted:"!pip install -q torch transformers transformers langchain sentence-transformers tqdm openpyxl openai pandas datasets langchain-community ragatouille",wrap:!1}}),N=new I({props:{code:"JTI1cmVsb2FkX2V4dCUyMGF1dG9yZWxvYWQlMEElMjVhdXRvcmVsb2FkJTIwMg==",highlighted:`%reload_ext autoreload
%autoreload <span class="hljs-number">2</span>`,wrap:!1}}),k=new I({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjBwYW5kYXMlMjBhcyUyMHBkJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyME9wdGlvbmFsJTJDJTIwTGlzdCUyQyUyMFR1cGxlJTBBaW1wb3J0JTIwanNvbiUwQWltcG9ydCUyMGRhdGFzZXRzJTBBJTBBcGQuc2V0X29wdGlvbiglMjJkaXNwbGF5Lm1heF9jb2x3aWR0aCUyMiUyQyUyME5vbmUp",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Optional</span>, <span class="hljs-type">List</span>, <span class="hljs-type">Tuple</span>
<span class="hljs-keyword">import</span> json
<span class="hljs-keyword">import</span> datasets

pd.set_option(<span class="hljs-string">&quot;display.max_colwidth&quot;</span>, <span class="hljs-literal">None</span>)`,wrap:!1}}),v=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),E=new c({props:{title:"加载你的知识基础",local:"加载你的知识基础",headingTag:"h3"}}),S=new I({props:{code:"ZHMlMjAlM0QlMjBkYXRhc2V0cy5sb2FkX2RhdGFzZXQoJTIybS1yaWMlMkZodWdnaW5nZmFjZV9kb2MlMjIlMkMlMjBzcGxpdCUzRCUyMnRyYWluJTIyKQ==",highlighted:'ds = datasets.load_dataset(<span class="hljs-string">&quot;m-ric/huggingface_doc&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)',wrap:!1}}),Y=new c({props:{title:"1. 为评估构建合成数据集",local:"1-为评估构建合成数据集",headingTag:"h1"}}),q=new c({props:{title:"1.1. 准备源数据文档",local:"11-准备源数据文档",headingTag:"h3"}}),x=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi50ZXh0X3NwbGl0dGVyJTIwaW1wb3J0JTIwUmVjdXJzaXZlQ2hhcmFjdGVyVGV4dFNwbGl0dGVyJTBBZnJvbSUyMGxhbmdjaGFpbi5kb2NzdG9yZS5kb2N1bWVudCUyMGltcG9ydCUyMERvY3VtZW50JTIwYXMlMjBMYW5nY2hhaW5Eb2N1bWVudCUwQSUwQWxhbmdjaGFpbl9kb2NzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwTGFuZ2NoYWluRG9jdW1lbnQocGFnZV9jb250ZW50JTNEZG9jJTVCJTIydGV4dCUyMiU1RCUyQyUyMG1ldGFkYXRhJTNEJTdCJTIyc291cmNlJTIyJTNBJTIwZG9jJTVCJTIyc291cmNlJTIyJTVEJTdEKSUwQSUyMCUyMCUyMCUyMGZvciUyMGRvYyUyMGluJTIwdHFkbShkcyklMEElNUQlMEElMEElMEF0ZXh0X3NwbGl0dGVyJTIwJTNEJTIwUmVjdXJzaXZlQ2hhcmFjdGVyVGV4dFNwbGl0dGVyKCUwQSUyMCUyMCUyMCUyMGNodW5rX3NpemUlM0QyMDAwJTJDJTBBJTIwJTIwJTIwJTIwY2h1bmtfb3ZlcmxhcCUzRDIwMCUyQyUwQSUyMCUyMCUyMCUyMGFkZF9zdGFydF9pbmRleCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBzZXBhcmF0b3JzJTNEJTVCJTIyJTVDbiU1Q24lMjIlMkMlMjAlMjIlNUNuJTIyJTJDJTIwJTIyLiUyMiUyQyUyMCUyMiUyMCUyMiUyQyUyMCUyMiUyMiU1RCUyQyUwQSklMEElMEFkb2NzX3Byb2Nlc3NlZCUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMGRvYyUyMGluJTIwbGFuZ2NoYWluX2RvY3MlM0ElMEElMjAlMjAlMjAlMjBkb2NzX3Byb2Nlc3NlZCUyMCUyQiUzRCUyMHRleHRfc3BsaXR0ZXIuc3BsaXRfZG9jdW1lbnRzKCU1QmRvYyU1RCk=",highlighted:`<span class="hljs-keyword">from</span> langchain.text_splitter <span class="hljs-keyword">import</span> RecursiveCharacterTextSplitter
<span class="hljs-keyword">from</span> langchain.docstore.document <span class="hljs-keyword">import</span> Document <span class="hljs-keyword">as</span> LangchainDocument

langchain_docs = [
    LangchainDocument(page_content=doc[<span class="hljs-string">&quot;text&quot;</span>], metadata={<span class="hljs-string">&quot;source&quot;</span>: doc[<span class="hljs-string">&quot;source&quot;</span>]})
    <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> tqdm(ds)
]


text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=<span class="hljs-number">2000</span>,
    chunk_overlap=<span class="hljs-number">200</span>,
    add_start_index=<span class="hljs-literal">True</span>,
    separators=[<span class="hljs-string">&quot;\\n\\n&quot;</span>, <span class="hljs-string">&quot;\\n&quot;</span>, <span class="hljs-string">&quot;.&quot;</span>, <span class="hljs-string">&quot; &quot;</span>, <span class="hljs-string">&quot;&quot;</span>],
)

docs_processed = []
<span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> langchain_docs:
    docs_processed += text_splitter.split_documents([doc])`,wrap:!1}}),z=new c({props:{title:"1.2. 为问题生成设置智能体",local:"12-为问题生成设置智能体",headingTag:"h3"}}),$=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMEluZmVyZW5jZUNsaWVudCUwQSUwQSUwQXJlcG9faWQlMjAlM0QlMjAlMjJtaXN0cmFsYWklMkZNaXh0cmFsLTh4N0ItSW5zdHJ1Y3QtdjAuMSUyMiUwQSUwQWxsbV9jbGllbnQlMjAlM0QlMjBJbmZlcmVuY2VDbGllbnQoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0RyZXBvX2lkJTJDJTBBJTIwJTIwJTIwJTIwdGltZW91dCUzRDEyMCUyQyUwQSklMEElMEElMEFkZWYlMjBjYWxsX2xsbShpbmZlcmVuY2VfY2xpZW50JTNBJTIwSW5mZXJlbmNlQ2xpZW50JTJDJTIwcHJvbXB0JTNBJTIwc3RyKSUzQSUwQSUyMCUyMCUyMCUyMHJlc3BvbnNlJTIwJTNEJTIwaW5mZXJlbmNlX2NsaWVudC5wb3N0KCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGpzb24lM0QlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJpbnB1dHMlMjIlM0ElMjBwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwYXJhbWV0ZXJzJTIyJTNBJTIwJTdCJTIybWF4X25ld190b2tlbnMlMjIlM0ElMjAxMDAwJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydGFzayUyMiUzQSUyMCUyMnRleHQtZ2VuZXJhdGlvbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBqc29uLmxvYWRzKHJlc3BvbnNlLmRlY29kZSgpKSU1QjAlNUQlNUIlMjJnZW5lcmF0ZWRfdGV4dCUyMiU1RCUwQSUwQSUwQWNhbGxfbGxtKGxsbV9jbGllbnQlMkMlMjAlMjJUaGlzJTIwaXMlMjBhJTIwdGVzdCUyMGNvbnRleHQlMjIp",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient


repo_id = <span class="hljs-string">&quot;mistralai/Mixtral-8x7B-Instruct-v0.1&quot;</span>

llm_client = InferenceClient(
    model=repo_id,
    timeout=<span class="hljs-number">120</span>,
)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">call_llm</span>(<span class="hljs-params">inference_client: InferenceClient, prompt: <span class="hljs-built_in">str</span></span>):
    response = inference_client.post(
        json={
            <span class="hljs-string">&quot;inputs&quot;</span>: prompt,
            <span class="hljs-string">&quot;parameters&quot;</span>: {<span class="hljs-string">&quot;max_new_tokens&quot;</span>: <span class="hljs-number">1000</span>},
            <span class="hljs-string">&quot;task&quot;</span>: <span class="hljs-string">&quot;text-generation&quot;</span>,
        },
    )
    <span class="hljs-keyword">return</span> json.loads(response.decode())[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>]


call_llm(llm_client, <span class="hljs-string">&quot;This is a test context&quot;</span>)`,wrap:!1}}),L=new I({props:{code:"UUFfZ2VuZXJhdGlvbl9wcm9tcHQlMjAlM0QlMjAlMjIlMjIlMjIlMEFZb3VyJTIwdGFzayUyMGlzJTIwdG8lMjB3cml0ZSUyMGElMjBmYWN0b2lkJTIwcXVlc3Rpb24lMjBhbmQlMjBhbiUyMGFuc3dlciUyMGdpdmVuJTIwYSUyMGNvbnRleHQuJTBBWW91ciUyMGZhY3RvaWQlMjBxdWVzdGlvbiUyMHNob3VsZCUyMGJlJTIwYW5zd2VyYWJsZSUyMHdpdGglMjBhJTIwc3BlY2lmaWMlMkMlMjBjb25jaXNlJTIwcGllY2UlMjBvZiUyMGZhY3R1YWwlMjBpbmZvcm1hdGlvbiUyMGZyb20lMjB0aGUlMjBjb250ZXh0LiUwQVlvdXIlMjBmYWN0b2lkJTIwcXVlc3Rpb24lMjBzaG91bGQlMjBiZSUyMGZvcm11bGF0ZWQlMjBpbiUyMHRoZSUyMHNhbWUlMjBzdHlsZSUyMGFzJTIwcXVlc3Rpb25zJTIwdXNlcnMlMjBjb3VsZCUyMGFzayUyMGluJTIwYSUyMHNlYXJjaCUyMGVuZ2luZS4lMEFUaGlzJTIwbWVhbnMlMjB0aGF0JTIweW91ciUyMGZhY3RvaWQlMjBxdWVzdGlvbiUyME1VU1QlMjBOT1QlMjBtZW50aW9uJTIwc29tZXRoaW5nJTIwbGlrZSUyMCUyMmFjY29yZGluZyUyMHRvJTIwdGhlJTIwcGFzc2FnZSUyMiUyMG9yJTIwJTIyY29udGV4dCUyMi4lMEElMEFQcm92aWRlJTIweW91ciUyMGFuc3dlciUyMGFzJTIwZm9sbG93cyUzQSUwQSUwQU91dHB1dCUzQSUzQSUzQSUwQUZhY3RvaWQlMjBxdWVzdGlvbiUzQSUyMCh5b3VyJTIwZmFjdG9pZCUyMHF1ZXN0aW9uKSUwQUFuc3dlciUzQSUyMCh5b3VyJTIwYW5zd2VyJTIwdG8lMjB0aGUlMjBmYWN0b2lkJTIwcXVlc3Rpb24pJTBBJTBBTm93JTIwaGVyZSUyMGlzJTIwdGhlJTIwY29udGV4dC4lMEElMEFDb250ZXh0JTNBJTIwJTdCY29udGV4dCU3RCU1Q24lMEFPdXRwdXQlM0ElM0ElM0ElMjIlMjIlMjI=",highlighted:`QA_generation_prompt = <span class="hljs-string">&quot;&quot;&quot;
Your task is to write a factoid question and an answer given a context.
Your factoid question should be answerable with a specific, concise piece of factual information from the context.
Your factoid question should be formulated in the same style as questions users could ask in a search engine.
This means that your factoid question MUST NOT mention something like &quot;according to the passage&quot; or &quot;context&quot;.

Provide your answer as follows:

Output:::
Factoid question: (your factoid question)
Answer: (your answer to the factoid question)

Now here is the context.

Context: {context}\\n
Output:::&quot;&quot;&quot;</span>`,wrap:!1}}),O=new I({props:{code:"aW1wb3J0JTIwcmFuZG9tJTBBJTBBTl9HRU5FUkFUSU9OUyUyMCUzRCUyMDEwJTIwJTIwJTIzJTIwV2UlMjBpbnRlbnRpb25hbGx5JTIwZ2VuZXJhdGUlMjBvbmx5JTIwMTAlMjBRQSUyMGNvdXBsZXMlMjBoZXJlJTIwZm9yJTIwY29zdCUyMGFuZCUyMHRpbWUlMjBjb25zaWRlcmF0aW9ucyUwQSUwQXByaW50KGYlMjJHZW5lcmF0aW5nJTIwJTdCTl9HRU5FUkFUSU9OUyU3RCUyMFFBJTIwY291cGxlcy4uLiUyMiklMEElMEFvdXRwdXRzJTIwJTNEJTIwJTVCJTVEJTBBZm9yJTIwc2FtcGxlZF9jb250ZXh0JTIwaW4lMjB0cWRtKHJhbmRvbS5zYW1wbGUoZG9jc19wcm9jZXNzZWQlMkMlMjBOX0dFTkVSQVRJT05TKSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBHZW5lcmF0ZSUyMFFBJTIwY291cGxlJTBBJTIwJTIwJTIwJTIwb3V0cHV0X1FBX2NvdXBsZSUyMCUzRCUyMGNhbGxfbGxtKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxsbV9jbGllbnQlMkMlMjBRQV9nZW5lcmF0aW9uX3Byb21wdC5mb3JtYXQoY29udGV4dCUzRHNhbXBsZWRfY29udGV4dC5wYWdlX2NvbnRlbnQpJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMHRyeSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHF1ZXN0aW9uJTIwJTNEJTIwb3V0cHV0X1FBX2NvdXBsZS5zcGxpdCglMjJGYWN0b2lkJTIwcXVlc3Rpb24lM0ElMjAlMjIpJTVCLTElNUQuc3BsaXQoJTIyQW5zd2VyJTNBJTIwJT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aW51ZQ==",highlighted:`<span class="hljs-keyword">import</span> random

N_GENERATIONS = <span class="hljs-number">10</span>  <span class="hljs-comment"># We intentionally generate only 10 QA couples here for cost and time considerations</span>

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Generating <span class="hljs-subst">{N_GENERATIONS}</span> QA couples...&quot;</span>)

outputs = []
<span class="hljs-keyword">for</span> sampled_context <span class="hljs-keyword">in</span> tqdm(random.sample(docs_processed, N_GENERATIONS)):
    <span class="hljs-comment"># Generate QA couple</span>
    output_QA_couple = call_llm(
        llm_client, QA_generation_prompt.<span class="hljs-built_in">format</span>(context=sampled_context.page_content)
    )
    <span class="hljs-keyword">try</span>:
        question = output_QA_couple.split(<span class="hljs-string">&quot;Factoid question: &quot;</span>)[-<span class="hljs-number">1</span>].split(<span class="hljs-string">&quot;Answer: &quot;</span>)[<span class="hljs-number">0</span>]
        answer = output_QA_couple.split(<span class="hljs-string">&quot;Answer: &quot;</span>)[-<span class="hljs-number">1</span>]
        <span class="hljs-keyword">assert</span> <span class="hljs-built_in">len</span>(answer) &lt; <span class="hljs-number">300</span>, <span class="hljs-string">&quot;Answer is too long&quot;</span>
        outputs.append(
            {
                <span class="hljs-string">&quot;context&quot;</span>: sampled_context.page_content,
                <span class="hljs-string">&quot;question&quot;</span>: question,
                <span class="hljs-string">&quot;answer&quot;</span>: answer,
                <span class="hljs-string">&quot;source_doc&quot;</span>: sampled_context.metadata[<span class="hljs-string">&quot;source&quot;</span>],
            }
        )
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">continue</span>`,wrap:!1}}),ll=new I({props:{code:"ZGlzcGxheShwZC5EYXRhRnJhbWUob3V0cHV0cykuaGVhZCgxKSk=",highlighted:'display(pd.DataFrame(outputs).head(<span class="hljs-number">1</span>))',wrap:!1}}),sl=new c({props:{title:"1.3. 设置批判智能体",local:"13-设置批判智能体",headingTag:"h3"}}),Tl=new I({props:{code:" ",highlighted:`question_groundedness_critique_prompt = <span class="hljs-string">&quot;&quot;&quot;
You will be given a context and a question.
Your task is to provide a &#x27;total rating&#x27; scoring how well one can answer the given question unambiguously with the given context.
Give your answer on a scale of 1 to 5, where 1 means that the question is not answerable at all given the context, and 5 means that the question is clearly and unambiguously answerable with the context.

Provide your answer as follows:

Answer:::
Evaluation: (your rationale for the rating, as a text)
Total rating: (your rating, as a number between 1 and 5)

You MUST provide values for &#x27;Evaluation:&#x27; and &#x27;Total rating:&#x27; in your answer.

Now here are the question and context.

Question: {question}\\n
Context: {context}\\n
Answer::: &quot;&quot;&quot;</span>

question_relevance_critique_prompt = <span class="hljs-string">&quot;&quot;&quot;
You will be given a question.
Your task is to provide a &#x27;total rating&#x27; representing how useful this question can be to machine learning developers building NLP applications with the Hugging Face ecosystem.
Give your answer on a scale of 1 to 5, where 1 means that the question is not useful at all, and 5 means that the question is extremely useful.

Provide your answer as follows:

Answer:::
Evaluation: (your rationale for the rating, as a text)
Total rating: (your rating, as a number between 1 and 5)

You MUST provide values for &#x27;Evaluation:&#x27; and &#x27;Total rating:&#x27; in your answer.

Now here is the question.

Question: {question}\\n
Answer::: &quot;&quot;&quot;</span>

question_standalone_critique_prompt = <span class="hljs-string">&quot;&quot;&quot;
You will be given a question.
Your task is to provide a &#x27;total rating&#x27; representing how context-independant this question is.
Give your answer on a scale of 1 to 5, where 1 means that the question depends on additional information to be understood, and 5 means that the question makes sense by itself.
For instance, if the question refers to a particular setting, like &#x27;in the context&#x27; or &#x27;in the document&#x27;, the rating must be 1.
The questions can contain obscure technical nouns or acronyms like Gradio, Hub, Hugging Face or Space and still be a 5: it must simply be clear to an operator with access to documentation what the question is about.

For instance, &quot;What is the name of the checkpoint from which the ViT model is imported?&quot; should receive a 1, since there is an implicit mention of a context, thus the question is not independant from the context.

Provide your answer as follows:

Answer:::
Evaluation: (your rationale for the rating, as a text)
Total rating: (your rating, as a number between 1 and 5)

You MUST provide values for &#x27;Evaluation:&#x27; and &#x27;Total rating:&#x27; in your answer.

Now here is the question.

Question: {question}\\n
Answer::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UyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXQudXBkYXRlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGYlMjIlN0Jjcml0ZXJpb24lN0Rfc2NvcmUlMjIlM0ElMjBzY29yZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGYlMjIlN0Jjcml0ZXJpb24lN0RfZXZhbCUyMiUzQSUyMGV2YWwlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZXhjZXB0JTIwRXhjZXB0aW9uJTIwYXMlMjBlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29udGludWU=",highlighted:`<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Generating critique for each QA couple...&quot;</span>)
<span class="hljs-keyword">for</span> output <span class="hljs-keyword">in</span> tqdm(outputs):
    evaluations = {
        <span class="hljs-string">&quot;groundedness&quot;</span>: call_llm(
            llm_client,
            question_groundedness_critique_prompt.<span class="hljs-built_in">format</span>(
                context=output[<span class="hljs-string">&quot;context&quot;</span>], question=output[<span class="hljs-string">&quot;question&quot;</span>]
            ),
        ),
        <span class="hljs-string">&quot;relevance&quot;</span>: call_llm(
            llm_client,
            question_relevance_critique_prompt.<span class="hljs-built_in">format</span>(question=output[<span class="hljs-string">&quot;question&quot;</span>]),
        ),
        <span class="hljs-string">&quot;standalone&quot;</span>: call_llm(
            llm_client,
            question_standalone_critique_prompt.<span class="hljs-built_in">format</span>(question=output[<span class="hljs-string">&quot;question&quot;</span>]),
        ),
    }
    <span class="hljs-keyword">try</span>:
        <span class="hljs-keyword">for</span> criterion, evaluation <span class="hljs-keyword">in</span> evaluations.items():
            score, <span class="hljs-built_in">eval</span> = (
                <span class="hljs-built_in">int</span>(evaluation.split(<span class="hljs-string">&quot;Total rating: &quot;</span>)[-<span class="hljs-number">1</span>].strip()),
                evaluation.split(<span class="hljs-string">&quot;Total rating: &quot;</span>)[-<span class="hljs-number">2</span>].split(<span class="hljs-string">&quot;Evaluation: &quot;</span>)[<span class="hljs-number">1</span>],
            )
            output.update(
                {
                    <span class="hljs-string">f&quot;<span class="hljs-subst">{criterion}</span>_score&quot;</span>: score,
                    <span class="hljs-string">f&quot;<span class="hljs-subst">{criterion}</span>_eval&quot;</span>: <span class="hljs-built_in">eval</span>,
                }
            )
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        <span class="hljs-keyword">continue</span>`,wrap:!1}}),pl=new I({props:{code:"aW1wb3J0JTIwcGFuZGFzJTIwYXMlMjBwZCUwQSUwQXBkLnNldF9vcHRpb24oJTIyZGlzcGxheS5tYXhfY29sd2lkdGglMjIlMkMlMjBOb25lKSUwQSUwQWdlbmVyYXRlZF9xdWVzdGlvbnMlMjAlM0QlMjBwZC5EYXRhRnJhbWUuZnJvbV9kaWN0KG91dHB1dHMpJTBBJTBBcHJpbnQoJTIyRXZhbHVhdGlvbiUyMGRhdGFzZXQlMjBiZWZvcmUlMjBmaWx0ZXJpbmclM0ElMjIpJTBBZGlzcGxheSglMEElMjAlMjAlMjAlMjBnZW5lcmF0ZWRfcXVlc3Rpb25zJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycXVlc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yRmluYWwlMjBldmFsdWF0aW9uJTIwZGF0YXNldCUzQSUyMiklMEFkaXNwbGF5KCUwQSUyMCUyMCUyMCUyMGdlbmVyYXRlZF9xdWVzdGlvbnMlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJxdWVzdGlvbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmFuc3dlciUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmdyb3VuZGVkbmVzc19zY29yZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJlbGV2YW5jZV9zY29yZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YW5kYWxvbmVfc2NvcmUlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUQlMEElMjAlMjAlMjAlMjAlNUQlMEEpJTBBJTBBZXZhbF9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMuRGF0YXNldC5mcm9tX3BhbmRhcyglMEElMjAlMjAlMjAlMjBnZW5lcmF0ZWRfcXVlc3Rpb25zJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiUyQyUyMHByZXNlcnZlX2luZGV4JTNERmFsc2UlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

<span class="hljs-meta">&gt;&gt;&gt; </span>pd.set_option(<span class="hljs-string">&quot;display.max_colwidth&quot;</span>, <span class="hljs-literal">None</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>generated_questions = pd.DataFrame.from_dict(outputs)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Evaluation dataset before filtering:&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>display(
<span class="hljs-meta">... </span>    generated_questions[
<span class="hljs-meta">... </span>        [
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;question&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;answer&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;groundedness_score&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;relevance_score&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;standalone_score&quot;</span>,
<span class="hljs-meta">... </span>        ]
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_questions = generated_questions.loc[
<span class="hljs-meta">... </span>    (generated_questions[<span class="hljs-string">&quot;groundedness_score&quot;</span>] &gt;= <span class="hljs-number">4</span>)
<span class="hljs-meta">... </span>    &amp; (generated_questions[<span class="hljs-string">&quot;relevance_score&quot;</span>] &gt;= <span class="hljs-number">4</span>)
<span class="hljs-meta">... </span>    &amp; (generated_questions[<span class="hljs-string">&quot;standalone_score&quot;</span>] &gt;= <span class="hljs-number">4</span>)
<span class="hljs-meta">... </span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;============================================&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Final evaluation dataset:&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>display(
<span class="hljs-meta">... </span>    generated_questions[
<span class="hljs-meta">... </span>        [
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;question&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;answer&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;groundedness_score&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;relevance_score&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;standalone_score&quot;</span>,
<span class="hljs-meta">... </span>        ]
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>eval_dataset = datasets.Dataset.from_pandas(
<span class="hljs-meta">... </span>    generated_questions, split=<span class="hljs-string">&quot;train&quot;</span>, preserve_index=<span class="hljs-literal">False</span>
<span class="hljs-meta">... </span>)`,wrap:!1}}),ol=new I({props:{code:"ZXZhbF9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCUyMm0tcmljJTJGaHVnZ2luZ2ZhY2VfZG9jX3FhX2V2YWwlMjIlMkMlMjBzcGxpdCUzRCUyMnRyYWluJTIyKQ==",highlighted:'eval_dataset = datasets.load_dataset(<span class="hljs-string">&quot;m-ric/huggingface_doc_qa_eval&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)',wrap:!1}}),ul=new c({props:{title:"2. 构建我们的 RAG 系统",local:"2-构建我们的-rag-系统",headingTag:"h1"}}),dl=new c({props:{title:"2.1. 预处理文档来构建我们的向量数据库",local:"21-预处理文档来构建我们的向量数据库",headingTag:"h3"}}),Bl=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi5kb2NzdG9yZS5kb2N1bWVudCUyMGltcG9ydCUyMERvY3VtZW50JTIwYXMlMjBMYW5nY2hhaW5Eb2N1bWVudCUwQSUwQVJBV19LTk9XTEVER0VfQkFTRSUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMExhbmdjaGFpbkRvY3VtZW50KHBhZ2VfY29udGVudCUzRGRvYyU1QiUyMnRleHQlMjIlNUQlMkMlMjBtZXRhZGF0YSUzRCU3QiUyMnNvdXJjZSUyMiUzQSUyMGRvYyU1QiUyMnNvdXJjZSUyMiU1RCU3RCklMEElMjAlMjAlMjAlMjBmb3IlMjBkb2MlMjBpbiUyMHRxZG0oZHMpJTBBJTVE",highlighted:`<span class="hljs-keyword">from</span> langchain.docstore.document <span class="hljs-keyword">import</span> Document <span class="hljs-keyword">as</span> LangchainDocument

RAW_KNOWLEDGE_BASE = [
    LangchainDocument(page_content=doc[<span class="hljs-string">&quot;text&quot;</span>], metadata={<span class="hljs-string">&quot;source&quot;</span>: doc[<span class="hljs-string">&quot;source&quot;</span>]})
    <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> tqdm(ds)
]`,wrap:!1}}),Zl=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi50ZXh0X3NwbGl0dGVyJTIwaW1wb3J0JTIwUmVjdXJzaXZlQ2hhcmFjdGVyVGV4dFNwbGl0dGVyJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEElMEFkZWYlMjBzcGxpdF9kb2N1bWVudHMoJTBBJTIwJTIwJTIwJTIwY2h1bmtfc2l6ZSUzQSUyMGludCUyQyUwQSUyMCUyMCUyMCUyMGtub3dsZWRnZV9iYXNlJTNBJTIwTGlzdCU1QkxhbmdjaGFpbkRvY3VtZW50JTVEJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVyX25hbWUlM0ElMjBzdHIlMkMlMEEpJTIwLSUzRSUyMExpc3QlNUJMYW5nY2hhaW5Eb2N1bWVudCU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMFNwbGl0JTIwZG9jdW1lbnRzJTIwaW50byUyMGNodW5rcyUyMG9mJTIwc2l6ZSUyMCU2MGNodW5rX3NpemUlNjAlMjBjaGFyYWN0ZXJzJTIwYW5kJTIwcmV0dXJuJTIwYSUyMGxpc3QlMjBvZiUyMGRvY3VtZW50cy4lMEElMjAlMjAlMjAlMjAlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjB0ZXh0X3NwbGl0dGVyJTIwJTNEJTIwUmVjdXJzaX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vY3NfcHJvY2Vzc2VkX3VuaXF1ZSUyMCUzRCUyMCU1QiU1RCUwQSUyMCUyMCUyMCUyMGZvciUyMGRvYyUyMGluJTIwZG9jc19wcm9jZXNzZWQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZiUyMGRvYy5wYWdlX2NvbnRlbnQlMjBub3QlMjBpbiUyMHVuaXF1ZV90ZXh0cyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHVuaXF1ZV90ZXh0cyU1QmRvYy5wYWdlX2NvbnRlbnQlNUQlMjAlM0QlMjBUcnVlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZG9jc19wcm9jZXNzZWRfdW5pcXVlLmFwcGVuZChkb2MpJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZG9jc19wcm9jZXNzZWRfdW5pcXVl",highlighted:`<span class="hljs-keyword">from</span> langchain.text_splitter <span class="hljs-keyword">import</span> RecursiveCharacterTextSplitter
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer


<span class="hljs-keyword">def</span> <span class="hljs-title function_">split_documents</span>(<span class="hljs-params">
    chunk_size: <span class="hljs-built_in">int</span>,
    knowledge_base: <span class="hljs-type">List</span>[LangchainDocument],
    tokenizer_name: <span class="hljs-built_in">str</span>,
</span>) -&gt; <span class="hljs-type">List</span>[LangchainDocument]:
    <span class="hljs-string">&quot;&quot;&quot;
    Split documents into chunks of size \`chunk_size\` characters and return a list of documents.
    &quot;&quot;&quot;</span>
    text_splitter = RecursiveCharacterTextSplitter.from_huggingface_tokenizer(
        AutoTokenizer.from_pretrained(tokenizer_name),
        chunk_size=chunk_size,
        chunk_overlap=<span class="hljs-built_in">int</span>(chunk_size / <span class="hljs-number">10</span>),
        add_start_index=<span class="hljs-literal">True</span>,
        strip_whitespace=<span class="hljs-literal">True</span>,
        separators=[<span class="hljs-string">&quot;\\n\\n&quot;</span>, <span class="hljs-string">&quot;\\n&quot;</span>, <span class="hljs-string">&quot;.&quot;</span>, <span class="hljs-string">&quot; &quot;</span>, <span class="hljs-string">&quot;&quot;</span>],
    )

    docs_processed = []
    <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> knowledge_base:
        docs_processed += text_splitter.split_documents([doc])

    <span class="hljs-comment"># Remove duplicates</span>
    unique_texts = {}
    docs_processed_unique = []
    <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> docs_processed:
        <span class="hljs-keyword">if</span> doc.page_content <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> unique_texts:
            unique_texts[doc.page_content] = <span class="hljs-literal">True</span>
            docs_processed_unique.append(doc)

    <span class="hljs-keyword">return</span> docs_processed_unique`,wrap:!1}}),Gl=new c({props:{title:"2.2.  检索器 - 嵌入 🗂️",local:"22-检索器---嵌入-",headingTag:"h3"}}),Rl=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi52ZWN0b3JzdG9yZXMlMjBpbXBvcnQlMjBGQUlTUyUwQWZyb20lMjBsYW5nY2hhaW5fY29tbXVuaXR5LmVtYmVkZGluZ3MlMjBpbXBvcnQlMjBIdWdnaW5nRmFjZUVtYmVkZGluZ3MlMEFmcm9tJTIwbGFuZ2NoYWluX2NvbW11bml0eS52ZWN0b3JzdG9yZXMudXRpbHMlMjBpbXBvcnQlMjBEaXN0YW5jZVN0cmF0ZWd5JTBBaW1wb3J0JTIwb3MlMEElMEElMEFkZWYlMjBsb2FkX2VtYmVkZGluZ3MoJTBBJTIwJTIwJTIwJTIwbGFuZ2NoYWluX2RvY3MlM0ElMjBMaXN0JTVCTGFuZ2NoYWluRG9jdW1lbnQlNUQlMkMlMEElMjAlMjAlMjAlMjBjaHVua19zaXplJTNBJTIwaW50JTJDJTBBJTIwJTIwJTIwJTIwZW1iZWRkaW5nX21vZGVsX25hbWUlM0ElMjBPcHRpb25hbCU1QnN0ciU1RCUyMCUzRCUyMC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lMjBkaXN0YW5jZV9zdHJhdGVneSUzRERpc3RhbmNlU3RyYXRlZ3kuQ09TSU5FJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGtub3dsZWRnZV9pbmRleC5zYXZlX2xvY2FsKGluZGV4X2ZvbGRlcl9wYXRoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMGtub3dsZWRnZV9pbmRleA==",highlighted:`<span class="hljs-keyword">from</span> langchain.vectorstores <span class="hljs-keyword">import</span> FAISS
<span class="hljs-keyword">from</span> langchain_community.embeddings <span class="hljs-keyword">import</span> HuggingFaceEmbeddings
<span class="hljs-keyword">from</span> langchain_community.vectorstores.utils <span class="hljs-keyword">import</span> DistanceStrategy
<span class="hljs-keyword">import</span> os


<span class="hljs-keyword">def</span> <span class="hljs-title function_">load_embeddings</span>(<span class="hljs-params">
    langchain_docs: <span class="hljs-type">List</span>[LangchainDocument],
    chunk_size: <span class="hljs-built_in">int</span>,
    embedding_model_name: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">str</span>] = <span class="hljs-string">&quot;thenlper/gte-small&quot;</span>,
</span>) -&gt; FAISS:
    <span class="hljs-string">&quot;&quot;&quot;
    Creates a FAISS index from the given embedding model and documents. Loads the index directly if it already exists.

    Args:
        langchain_docs: list of documents
        chunk_size: size of the chunks to split the documents into
        embedding_model_name: name of the embedding model to use

    Returns:
        FAISS index
    &quot;&quot;&quot;</span>
    <span class="hljs-comment"># load embedding_model</span>
    embedding_model = HuggingFaceEmbeddings(
        model_name=embedding_model_name,
        multi_process=<span class="hljs-literal">True</span>,
        model_kwargs={<span class="hljs-string">&quot;device&quot;</span>: <span class="hljs-string">&quot;cuda&quot;</span>},
        encode_kwargs={
            <span class="hljs-string">&quot;normalize_embeddings&quot;</span>: <span class="hljs-literal">True</span>
        },  <span class="hljs-comment"># set True to compute cosine similarity</span>
    )

    <span class="hljs-comment"># Check if embeddings already exist on disk</span>
    index_name = (
        <span class="hljs-string">f&quot;index_chunk:<span class="hljs-subst">{chunk_size}</span>_embeddings:<span class="hljs-subst">{embedding_model_name.replace(<span class="hljs-string">&#x27;/&#x27;</span>, <span class="hljs-string">&#x27;~&#x27;</span>)}</span>&quot;</span>
    )
    index_folder_path = <span class="hljs-string">f&quot;./data/indexes/<span class="hljs-subst">{index_name}</span>/&quot;</span>
    <span class="hljs-keyword">if</span> os.path.isdir(index_folder_path):
        <span class="hljs-keyword">return</span> FAISS.load_local(
            index_folder_path,
            embedding_model,
            distance_strategy=DistanceStrategy.COSINE,
        )

    <span class="hljs-keyword">else</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Index not found, generating it...&quot;</span>)
        docs_processed = split_documents(
            chunk_size,
            langchain_docs,
            embedding_model_name,
        )
        knowledge_index = FAISS.from_documents(
            docs_processed, embedding_model, distance_strategy=DistanceStrategy.COSINE
        )
        knowledge_index.save_local(index_folder_path)
        <span class="hljs-keyword">return</span> knowledge_index`,wrap:!1}}),Xl=new c({props:{title:"2.3. 阅读器 - LLM 💬",local:"23-阅读器---llm-",headingTag:"h3"}}),kl=new I({props:{code:"UkFHX1BST01QVF9URU1QTEFURSUyMCUzRCUyMCUyMiUyMiUyMiUwQSUzQyU3Q3N5c3RlbSU3QyUzRSUwQVVzaW5nJTIwdGhlJTIwaW5mb3JtYXRpb24lMjBjb250YWluZWQlMjBpbiUyMHRoZSUyMGNvbnRleHQlMkMlMEFnaXZlJTIwYSUyMGNvbXByZWhlbnNpdmUlMjBhbnN3ZXIlMjB0byUyMHRoZSUyMHF1ZXN0aW9uLiUwQVJlc3BvbmQlMjBvbmx5JTIwdG8lMjB0aGUlMjBxdWVzdGlvbiUyMGFza2VkJTJDJTIwcmVzcG9uc2UlMjBzaG91bGQlMjBiZSUyMGNvbmNpc2UlMjBhbmQlMjByZWxldmFudCUyMHRvJTIwdGhlJTIwcXVlc3Rpb24uJTBBUHJvdmlkZSUyMHRoZSUyMG51bWJlciUyMG9mJTIwdGhlJTIwc291cmNlJTIwZG9jdW1lbnQlMjB3aGVuJTIwcmVsZXZhbnQuJTBBSWYlMjB0aGUlMjBhbnN3ZXIlMjBjYW5ub3QlMjBiZSUyMGRlZHVjZWQlMjBmcm9tJTIwdGhlJTIwY29udGV4dCUyQyUyMGRvJTIwbm90JTIwZ2l2ZSUyMGFuJTIwYW5zd2VyLiUzQyUyRnMlM0UlMEElM0MlN0N1c2VyJTdDJTNFJTBBQ29udGV4dCUzQSUwQSU3QmNvbnRleHQlN0QlMEEtLS0lMEFOb3clMjBoZXJlJTIwaXMlMjB0aGUlMjBxdWVzdGlvbiUyMHlvdSUyMG5lZWQlMjB0byUyMGFuc3dlci4lMEElMEFRdWVzdGlvbiUzQSUyMCU3QnF1ZXN0aW9uJTdEJTBBJTNDJTJGcyUzRSUwQSUzQyU3Q2Fzc2lzdGFudCU3QyUzRSUwQSUyMiUyMiUyMg==",highlighted:`RAG_PROMPT_TEMPLATE = <span class="hljs-string">&quot;&quot;&quot;
&lt;|system|&gt;
Using the information contained in the context,
give a comprehensive answer to the question.
Respond only to the question asked, response should be concise and relevant to the question.
Provide the number of the source document when relevant.
If the answer cannot be deduced from the context, do not give an answer.&lt;/s&gt;
&lt;|user|&gt;
Context:
{context}
---
Now here is the question you need to answer.

Question: {question}
&lt;/s&gt;
&lt;|assistant|&gt;
&quot;&quot;&quot;</span>`,wrap:!1}}),vl=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbl9jb21tdW5pdHkubGxtcyUyMGltcG9ydCUyMEh1Z2dpbmdGYWNlSHViJTBBJTBBcmVwb19pZCUyMCUzRCUyMCUyMkh1Z2dpbmdGYWNlSDQlMkZ6ZXBoeXItN2ItYmV0YSUyMiUwQVJFQURFUl9NT0RFTF9OQU1FJTIwJTNEJTIwJTIyemVwaHlyLTdiLWJldGElMjIlMEFIRl9BUElfVE9LRU4lMjAlM0QlMjAlMjIlMjIlMEElMEFSRUFERVJfTExNJTIwJTNEJTIwSHVnZ2luZ0ZhY2VIdWIoJTBBJTIwJTIwJTIwJTIwcmVwb19pZCUzRHJlcG9faWQlMkMlMEElMjAlMjAlMjAlMjB0YXNrJTNEJTIydGV4dC1nZW5lcmF0aW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwaHVnZ2luZ2ZhY2VodWJfYXBpX3Rva2VuJTNESEZfQVBJX1RPS0VOJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWxfa3dhcmdzJTNEJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybWF4X25ld190b2tlbnMlMjIlM0ElMjA1MTIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0b3BfayUyMiUzQSUyMDMwJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydGVtcGVyYXR1cmUlMjIlM0ElMjAwLjElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyZXBldGl0aW9uX3BlbmFsdHklMjIlM0ElMjAxLjAzJTJDJTBBJTIwJTIwJTIwJTIwJTdEJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> langchain_community.llms <span class="hljs-keyword">import</span> HuggingFaceHub

repo_id = <span class="hljs-string">&quot;HuggingFaceH4/zephyr-7b-beta&quot;</span>
READER_MODEL_NAME = <span class="hljs-string">&quot;zephyr-7b-beta&quot;</span>
HF_API_TOKEN = <span class="hljs-string">&quot;&quot;</span>

READER_LLM = HuggingFaceHub(
    repo_id=repo_id,
    task=<span class="hljs-string">&quot;text-generation&quot;</span>,
    huggingfacehub_api_token=HF_API_TOKEN,
    model_kwargs={
        <span class="hljs-string">&quot;max_new_tokens&quot;</span>: <span class="hljs-number">512</span>,
        <span class="hljs-string">&quot;top_k&quot;</span>: <span class="hljs-number">30</span>,
        <span class="hljs-string">&quot;temperature&quot;</span>: <span class="hljs-number">0.1</span>,
        <span class="hljs-string">&quot;repetition_penalty&quot;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yQiUzRCUyMCUyMiUyMi5qb2luKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QmYlMjJEb2N1bWVudCUyMCU3QnN0cihpKSU3RCUzQSUzQSUzQSU1Q24lMjIlMjAlMkIlMjBkb2MlMjBmb3IlMjBpJTJDJTIwZG9jJTIwaW4lMjBlbnVtZXJhdGUocmVsZXZhbnRfZG9jcyklNUQlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIwJTIwJTIwJTIwZmluYWxfcHJvbXB0JTIwJTNEJTIwUkFHX1BST01QVF9URU1QTEFURS5mb3JtYXQocXVlc3Rpb24lM0RxdWVzdGlvbiUyQyUyMGNvbnRleHQlM0Rjb250ZXh0KSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFJlZGFjdCUyMGFuJTIwYW5zd2VyJTBBJTIwJTIwJTIwJTIwYW5zd2VyJTIwJTNEJTIwbGxtKGZpbmFsX3Byb21wdCklMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBhbnN3ZXIlMkMlMjByZWxldmFudF9kb2Nz",highlighted:`<span class="hljs-keyword">from</span> ragatouille <span class="hljs-keyword">import</span> RAGPretrainedModel
<span class="hljs-keyword">from</span> langchain_core.vectorstores <span class="hljs-keyword">import</span> VectorStore
<span class="hljs-keyword">from</span> langchain_core.language_models.llms <span class="hljs-keyword">import</span> LLM


<span class="hljs-keyword">def</span> <span class="hljs-title function_">answer_with_rag</span>(<span class="hljs-params">
    question: <span class="hljs-built_in">str</span>,
    llm: LLM,
    knowledge_index: VectorStore,
    reranker: <span class="hljs-type">Optional</span>[RAGPretrainedModel] = <span class="hljs-literal">None</span>,
    num_retrieved_docs: <span class="hljs-built_in">int</span> = <span class="hljs-number">30</span>,
    num_docs_final: <span class="hljs-built_in">int</span> = <span class="hljs-number">7</span>,
</span>) -&gt; <span class="hljs-type">Tuple</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">List</span>[LangchainDocument]]:
    <span class="hljs-string">&quot;&quot;&quot;Answer a question using RAG with the given knowledge index.&quot;&quot;&quot;</span>
    <span class="hljs-comment"># Gather documents with retriever</span>
    relevant_docs = knowledge_index.similarity_search(
        query=question, k=num_retrieved_docs
    )
    relevant_docs = [doc.page_content <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> relevant_docs]  <span class="hljs-comment"># keep only the text</span>

    <span class="hljs-comment"># Optionally rerank results</span>
    <span class="hljs-keyword">if</span> reranker:
        relevant_docs = reranker.rerank(question, relevant_docs, k=num_docs_final)
        relevant_docs = [doc[<span class="hljs-string">&quot;content&quot;</span>] <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> relevant_docs]

    relevant_docs = relevant_docs[:num_docs_final]

    <span class="hljs-comment"># Build the final prompt</span>
    context = <span class="hljs-string">&quot;\\nExtracted documents:\\n&quot;</span>
    context += <span class="hljs-string">&quot;&quot;</span>.join(
        [<span class="hljs-string">f&quot;Document <span class="hljs-subst">{<span class="hljs-built_in">str</span>(i)}</span>:::\\n&quot;</span> + doc <span class="hljs-keyword">for</span> i, doc <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(relevant_docs)]
    )

    final_prompt = RAG_PROMPT_TEMPLATE.<span class="hljs-built_in">format</span>(question=question, context=context)

    <span class="hljs-comment"># Redact an answer</span>
    answer = llm(final_prompt)

    <span class="hljs-keyword">return</span> answer, relevant_docs`,wrap:!1}}),Sl=new c({props:{title:"3. 对 RAG 系统进行基准测试",local:"3-对-rag-系统进行基准测试",headingTag:"h1"}}),zl=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbl9jb3JlLmxhbmd1YWdlX21vZGVscyUyMGltcG9ydCUyMEJhc2VDaGF0TW9kZWwlMEElMEFkZWYlMjBydW5fcmFnX3Rlc3RzKCUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzQSUyMGRhdGFzZXRzLkRhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBsbG0lMkMlMEElMjAlMjAlMjAlMjBrbm93b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MjB0ZXN0X3NldHRpbmdzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVzdWx0JTVCJTIydGVzdF9zZXR0aW5ncyUyMiU1RCUyMCUzRCUyMHRlc3Rfc2V0dGluZ3MlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXRzLmFwcGVuZChyZXN1bHQpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2l0aCUyMG9wZW4ob3V0cHV0X2ZpbGUlMkMlMjAlMjJ3JTIyKSUyMGFzJTIwZiUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGpzb24uZHVtcChvdXRwdXRzJTJDJTIwZik=",highlighted:`<span class="hljs-keyword">from</span> langchain_core.language_models <span class="hljs-keyword">import</span> BaseChatModel

<span class="hljs-keyword">def</span> <span class="hljs-title function_">run_rag_tests</span>(<span class="hljs-params">
    eval_dataset: datasets.Dataset,
    llm,
    knowledge_index: VectorStore,
    output_file: <span class="hljs-built_in">str</span>,
    reranker: <span class="hljs-type">Optional</span>[RAGPretrainedModel] = <span class="hljs-literal">None</span>,
    verbose: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">bool</span>] = <span class="hljs-literal">True</span>,
    test_settings: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">str</span>] = <span class="hljs-literal">None</span>,  <span class="hljs-comment"># To document the test settings used</span>
</span>):
    <span class="hljs-string">&quot;&quot;&quot;Runs RAG tests on the given dataset and saves the results to the given output file.&quot;&quot;&quot;</span>
    <span class="hljs-keyword">try</span>:  <span class="hljs-comment"># load previous generations if they exist</span>
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(output_file, <span class="hljs-string">&quot;r&quot;</span>) <span class="hljs-keyword">as</span> f:
            outputs = json.load(f)
    <span class="hljs-keyword">except</span>:
        outputs = []

    <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> tqdm(eval_dataset):
        question = example[<span class="hljs-string">&quot;question&quot;</span>]
        <span class="hljs-keyword">if</span> question <span class="hljs-keyword">in</span> [output[<span class="hljs-string">&quot;question&quot;</span>] <span class="hljs-keyword">for</span> output <span class="hljs-keyword">in</span> outputs]:
            <span class="hljs-keyword">continue</span>

        answer, relevant_docs = answer_with_rag(
            question, llm, knowledge_index, reranker=reranker
        )
        <span class="hljs-keyword">if</span> verbose:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=======================================================&quot;</span>)
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Question: <span class="hljs-subst">{question}</span>&quot;</span>)
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Answer: <span class="hljs-subst">{answer}</span>&quot;</span>)
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&#x27;True answer: <span class="hljs-subst">{example[<span class="hljs-string">&quot;answer&quot;</span>]}</span>&#x27;</span>)
        result = {
            <span class="hljs-string">&quot;question&quot;</span>: question,
            <span class="hljs-string">&quot;true_answer&quot;</span>: example[<span class="hljs-string">&quot;answer&quot;</span>],
            <span class="hljs-string">&quot;source_doc&quot;</span>: example[<span class="hljs-string">&quot;source_doc&quot;</span>],
            <span class="hljs-string">&quot;generated_answer&quot;</span>: answer,
            <span class="hljs-string">&quot;retrieved_docs&quot;</span>: [doc <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> relevant_docs],
        }
        <span class="hljs-keyword">if</span> test_settings:
            result[<span class="hljs-string">&quot;test_settings&quot;</span>] = test_settings
        outputs.append(result)

        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(output_file, <span class="hljs-string">&quot;w&quot;</span>) <span class="hljs-keyword">as</span> f:
            json.dump(outputs, f)`,wrap:!1}}),Hl=new I({props:{code:"RVZBTFVBVElPTl9QUk9NUFQlMjAlM0QlMjAlMjIlMjIlMjIlMjMlMjMlMjNUYXNrJTIwRGVzY3JpcHRpb24lM0ElMEFBbiUyMGluc3Ryd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ALUATION_PROMPT = <span class="hljs-string">&quot;&quot;&quot;###Task Description:
An instruction (might include an Input inside it), a response to evaluate, a reference answer that gets a score of 5, and a score rubric representing a evaluation criteria are given.
1. Write a detailed feedback that assess the quality of the response strictly based on the given score rubric, not evaluating in general.
2. After writing a feedback, write a score that is an integer between 1 and 5. You should refer to the score rubric.
3. The output format should look as follows: \\&quot;Feedback: {{write a feedback for criteria}} [RESULT] {{an integer number between 1 and 5}}\\&quot;
4. Please do not generate any other opening, closing, and explanations. Be sure to include [RESULT] in your output.

###The instruction to evaluate:
{instruction}

###Response to evaluate:
{response}

###Reference Answer (Score 5):
{reference_answer}

###Score Rubrics:
[Is the response correct, accurate, and factual based on the reference answer?]
Score 1: The response is completely incorrect, inaccurate, and/or not factual.
Score 2: The response is mostly incorrect, inaccurate, and/or not factual.
Score 3: The response is somewhat correct, accurate, and/or factual.
Score 4: The response is mostly correct, accurate, and factual.
Score 5: The response is completely correct, accurate, and factual.

###Feedback:&quot;&quot;&quot;</span>

<span class="hljs-keyword">from</span> langchain.prompts.chat <span class="hljs-keyword">import</span> (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
)
<span class="hljs-keyword">from</span> langchain.schema <span class="hljs-keyword">import</span> SystemMessage


evaluation_prompt_template = ChatPromptTemplate.from_messages(
    [
        SystemMessage(content=<span class="hljs-string">&quot;You are a fair evaluator language model.&quot;</span>),
        HumanMessagePromptTemplate.from_template(EVALUATION_PROMPT),
    ]
)`,wrap:!1}}),$l=new I({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi5jaGF0X21vZGVscyUyMGltcG9ydCUyMENoYXRPcGVuQUklMEElMEFPUEVOQUlfQVBJX0tFWSUyMCUzRCUyMCUyMiUyMiUwQSUwQWV2YWxfY2hhdF9tb2RlbCUyMCUzRCUyMENoYXRPcGVuQUkobW9kZWwlM0QlMjJncHQtNC0xMTA2LXByZXZpZXclMjIlMkMlMjB0ZW1wZXJhdHVyZSUzRDAlMkMlMjBvcGVuYWlfYXB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UyMCUyMCUyMCUyMCUyMGV4cGVyaW1lbnQlNUJmJTIyZXZhbF9zY29yZV8lN0JldmFsdWF0b3JfbmFtZSU3RCUyMiU1RCUyMCUzRCUyMHNjb3JlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZXhwZXJpbWVudCU1QmYlMjJldmFsX2ZlZWRiYWNrXyU3QmV2YWx1YXRvcl9uYW1lJTdEJTIyJTVEJTIwJTNEJTIwZmVlZGJhY2slMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3aXRoJTIwb3BlbihhbnN3ZXJfcGF0aCUyQyUyMCUyMnclMjIpJTIwYXMlMjBmJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwanNvbi5kdW1wKGFuc3dlcnMlMkMlMjBmKQ==",highlighted:`<span class="hljs-keyword">from</span> langchain.chat_models <span class="hljs-keyword">import</span> ChatOpenAI

OPENAI_API_KEY = <span class="hljs-string">&quot;&quot;</span>

eval_chat_model = ChatOpenAI(model=<span class="hljs-string">&quot;gpt-4-1106-preview&quot;</span>, temperature=<span class="hljs-number">0</span>, openai_api_key=OPENAI_API_KEY)
evaluator_name = <span class="hljs-string">&quot;GPT4&quot;</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">evaluate_answers</span>(<span class="hljs-params">
    answer_path: <span class="hljs-built_in">str</span>,
    eval_chat_model,
    evaluator_name: <span class="hljs-built_in">str</span>,
    evaluation_prompt_template: ChatPromptTemplate,
</span>) -&gt; <span class="hljs-literal">None</span>:
    <span class="hljs-string">&quot;&quot;&quot;Evaluates generated answers. Modifies the given answer file in place for better checkpointing.&quot;&quot;&quot;</span>
    answers = []
    <span class="hljs-keyword">if</span> os.path.isfile(answer_path):  <span class="hljs-comment"># load previous generations if they exist</span>
        answers = json.load(<span class="hljs-built_in">open</span>(answer_path, <span class="hljs-string">&quot;r&quot;</span>))

    <span class="hljs-keyword">for</span> experiment <span class="hljs-keyword">in</span> tqdm(answers):
        <span class="hljs-keyword">if</span> <span class="hljs-string">f&quot;eval_score_<span class="hljs-subst">{evaluator_name}</span>&quot;</span> <span class="hljs-keyword">in</span> experiment:
            <span class="hljs-keyword">continue</span>

        eval_prompt = evaluation_prompt_template.format_messages(
            instruction=experiment[<span class="hljs-string">&quot;question&quot;</span>],
            response=experiment[<span class="hljs-string">&quot;generated_answer&quot;</span>],
            reference_answer=experiment[<span class="hljs-string">&quot;true_answer&quot;</span>],
        )
        eval_result = eval_chat_model.invoke(eval_prompt)
        feedback, score = [
            item.strip() <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> eval_result.content.split(<span class="hljs-string">&quot;[RESULT]&quot;</span>)
        ]
        experiment[<span class="hljs-string">f&quot;eval_score_<span class="hljs-subst">{evaluator_name}</span>&quot;</span>] = score
        experiment[<span class="hljs-string">f&quot;eval_feedback_<span class="hljs-subst">{evaluator_name}</span>&quot;</span>] = feedback

        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(answer_path, <span class="hljs-string">&quot;w&quot;</span>) <span class="hljs-keyword">as</span> f:
            json.dump(answers, f)`,wrap:!1}}),Dl=new I({props:{code:"aWYlMjBub3QlMjBvcy5wYXRoLmV4aXN0cyglMjIuJTJGb3V0cHV0JTIyKSUzQSUwQSUyMCUyMCUyMCUyMG9zLm1rZGlyKCUyMi4lMkZvdXRwdXQlMjIpJTBBJTBBZm9yJTIwY2h1bmtfc2l6ZSUyMGluJTIwJTVCMjAwJTVEJTNBJTIwJTIwJTIzJTIwQWRkJTIwb3RoZXIlMjBjaHVuayUyMHNpemVzJTIwKGluJTIwdG9rZW5zKSUyMGFzJTIwbmVlZGVkJTBBJTIwJTIwJTIwJTIwZm9yJTIwZW1iZWRkaW5ncyUyMGluJTIwJTVCJTIydGhlbmxwZXIlMkZndGUtc21hbGwlMjIlNUQlM0ElMjAlMjAlMjMlMjBBZGQlMjBvdGhlciUyMGVtYmVkZGluZ3MlMjBhcyUyMG5lZWRlZCUwQ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IwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9wcm9tcHRfdGVtcGxhdGUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAp",highlighted:`<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(<span class="hljs-string">&quot;./output&quot;</span>):
    os.mkdir(<span class="hljs-string">&quot;./output&quot;</span>)

<span class="hljs-keyword">for</span> chunk_size <span class="hljs-keyword">in</span> [<span class="hljs-number">200</span>]:  <span class="hljs-comment"># Add other chunk sizes (in tokens) as needed</span>
    <span class="hljs-keyword">for</span> embeddings <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;thenlper/gte-small&quot;</span>]:  <span class="hljs-comment"># Add other embeddings as needed</span>
        <span class="hljs-keyword">for</span> rerank <span class="hljs-keyword">in</span> [<span class="hljs-literal">True</span>, <span class="hljs-literal">False</span>]:
            settings_name = <span class="hljs-string">f&quot;chunk:<span class="hljs-subst">{chunk_size}</span>_embeddings:<span class="hljs-subst">{embeddings.replace(<span class="hljs-string">&#x27;/&#x27;</span>, <span class="hljs-string">&#x27;~&#x27;</span>)}</span>_rerank:<span class="hljs-subst">{rerank}</span>_reader-model:<span class="hljs-subst">{READER_MODEL_NAME}</span>&quot;</span>
            output_file_name = <span class="hljs-string">f&quot;./output/rag_<span class="hljs-subst">{settings_name}</span>.json&quot;</span>

            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Running evaluation for <span class="hljs-subst">{settings_name}</span>:&quot;</span>)

            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Loading knowledge base embeddings...&quot;</span>)
            knowledge_index = load_embeddings(
                RAW_KNOWLEDGE_BASE,
                chunk_size=chunk_size,
                embedding_model_name=embeddings,
            )

            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Running RAG...&quot;</span>)
            reranker = (
                RAGPretrainedModel.from_pretrained(<span class="hljs-string">&quot;colbert-ir/colbertv2.0&quot;</span>)
                <span class="hljs-keyword">if</span> rerank
                <span class="hljs-keyword">else</span> <span class="hljs-literal">None</span>
            )
            run_rag_tests(
                eval_dataset=eval_dataset,
                llm=READER_LLM,
                knowledge_index=knowledge_index,
                output_file=output_file_name,
                reranker=reranker,
                verbose=<span class="hljs-literal">False</span>,
                test_settings=settings_name,
            )

            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Running evaluation...&quot;</span>)
            evaluate_answers(
                output_file_name,
                eval_chat_model,
                evaluator_name,
                evaluation_prompt_template,
            )`,wrap:!1}}),Kl=new c({props:{title:"检查结果",local:"检查结果",headingTag:"h3"}}),Pl=new I({props:{code:"aW1wb3J0JTIwZ2xvYiUwQSUwQW91dHB1dHMlMjAlM0QlMjAlNUIlNUQlMEFmb3IlMjBmaWxlJTIwaW4lMjBnbG9iLmdsb2IoJTIyLiUyRm91dHB1dCUyRiouanNvbiUyMiklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXQlMjAlM0QlMjBwZC5EYXRhRnJhbWUoanNvbi5sb2FkKG9wZW4oZmlsZSUyQyUyMCUyMnIlMjIpKSklMEElMjAlMjAlMjAlMjBvdXRwdXQlNUIlMjJzZXR0aW5ncyUyMiU1RCUyMCUzRCUyMGZpbGUlMEElMjAlMjAlMjAlMjBvdXRwdXRzLmFwcGVuZChvdXRwdXQpJTBBcmVzdWx0JTIwJTNEJTIwcGQuY29uY2F0KG91dHB1dHMp",highlighted:`<span class="hljs-keyword">import</span> glob

outputs = []
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> glob.glob(<span class="hljs-string">&quot;./output/*.json&quot;</span>):
    output = pd.DataFrame(json.load(<span class="hljs-built_in">open</span>(file, <span class="hljs-string">&quot;r&quot;</span>)))
    output[<span class="hljs-string">&quot;settings&quot;</span>] = file
    outputs.append(output)
result = pd.concat(outputs)`,wrap:!1}}),Ol=new I({props:{code:"cmVzdWx0JTVCJTIyZXZhbF9zY29yZV9HUFQ0JTIyJTVEJTIwJTNEJTIwcmVzdWx0JTVCJTIyZXZhbF9zY29yZV9HUFQ0JTIyJTVELmFwcGx5KCUwQSUyMCUyMCUyMCUyMGxhbWJkYSUyMHglM0ElMjBpbnQoeCklMjBpZiUyMGlzaW5zdGFuY2UoeCUyQyUyMHN0ciklMjBlbHNlJTIwMSUwQSklMEFyZXN1bHQlNUIlMjJldmFsX3Njb3JlX0dQVDQlMjIlNUQlMjAlM0QlMjAocmVzdWx0JTVCJTIyZXZhbF9zY29yZV9HUFQ0JTIyJTVEJTIwLSUyMDEpJTIwJTJGJTIwNA==",highlighted:`result[<span class="hljs-string">&quot;eval_score_GPT4&quot;</span>] = result[<span class="hljs-string">&quot;eval_score_GPT4&quot;</span>].apply(
    <span class="hljs-keyword">lambda</span> x: <span class="hljs-built_in">int</span>(x) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(x, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-number">1</span>
)
result[<span class="hljs-string">&quot;eval_score_GPT4&quot;</span>] = (result[<span class="hljs-string">&quot;eval_score_GPT4&quot;</span>] - <span class="hljs-number">1</span>) / <span class="hljs-number">4</span>`,wrap:!1}}),ls=new I({props:{code:"YXZlcmFnZV9zY29yZXMlMjAlM0QlMjByZXN1bHQuZ3JvdXBieSglMjJzZXR0aW5ncyUyMiklNUIlMjJldmFsX3Njb3JlX0dQVDQlMjIlNUQubWVhbigpJTBBYXZlcmFnZV9zY29yZXMuc29ydF92YWx1ZXMoKQ==",highlighted:`average_scores = result.groupby(<span class="hljs-string">&quot;settings&quot;</span>)[<span class="hljs-string">&quot;eval_score_GPT4&quot;</span>].mean()
average_scores.sort_values()`,wrap:!1}}),ss=new c({props:{title:"结果示例",local:"结果示例",headingTag:"h2"}}),ns=new I({props:{code:"aW1wb3J0JTIwcGxvdGx5LmV4cHJlc3MlMjBhcyUyMHB4JTBBJTBBc2NvcmVzJTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCUyMm0tcmljJTJGcmFnX3Njb3Jlc19jb29rYm9vayUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMjIpJTBBc2NvcmVzJTIwJTNEJTIwcGQuU2VyaWVzKHNjb3JlcyU1QiUyMnNjb3JlJTIyJTVEJTJDJTIwaW5kZXglM0RzY29yZXMlNUIlMjJzZXR0aW5ncyUyMiU1RCk=",highlighted:`<span class="hljs-keyword">import</span> plotly.express <span class="hljs-keyword">as</span> px

scores = datasets.load_dataset(<span class="hljs-string">&quot;m-ric/rag_scores_cookbook&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
scores = pd.Series(scores[<span class="hljs-string">&quot;score&quot;</span>], index=scores[<span class="hljs-string">&quot;settings&quot;</span>])`,wrap:!1}}),es=new I({props:{code:"ZmlnJTIwJTNEJTIwcHguYmFyKCUwQSUyMCUyMCUyMCUyMHNjb3JlcyUyQyUwQSUyMCUyMCUyMCUyMGNvbG9yJTNEc2NvcmVzJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTNEJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydmFsdWUlMjIlM0ElMjAlMjJBY2N1cmFjeSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnNldHRpbmdzJTIyJTNBJTIwJTIyQ29uZmlndXJhdGlvbiUyMiUyQyUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMGNvbG9yX2NvbnRpbnVvdXNfc2NhbGUlM0QlMjJibHVlcmVkJTIyJTJDJTBBKSUwQWZpZy51cGRhdGVfbGF5b3V0KCUwQSUyMCUyMCUyMCUyMHdpZHRoJTNEMTAwMCUyQyUwQSUyMCUyMCUyMCUyMGhlaWdodCUzRDYwMCUyQyUwQSUyMCUyMCUyMCUyMGJhcm1vZGUlM0QlMjJncm91cCUyMiUyQyUwQSUyMCUyMCUyMCUyMHlheGlzX3JhbmdlJTNEJTVCMCUyQyUyMDEwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMHRpdGxlJTNEJTIyJTNDYiUzRUFjY3VyYWN5JTIwb2YlMjBkaWZmZXJlbnQlMjBSQUclMjBjb25maWd1cmF0aW9ucyUzQyUyRmIlM0UlMjIlMkMlMEElMjAlMjAlMjAlMjB4YXhpc190aXRsZSUzRCUyMlJBRyUyMHNldHRpbmdzJTIyJTJDJTBBJTIwJTIwJTIwJTIwZm9udCUzRGRpY3Qoc2l6ZSUzRDE1KSUyQyUwQSklMEFmaWcubGF5b3V0LnlheGlzLnRpY2tzdWZmaXglMjAlM0QlMjAlMjIlMjUlMjIlMEFmaWcudXBkYXRlX2NvbG9yYXhlcyhzaG93c2NhbGUlM0RGYWxzZSklMEFmaWcudXBkYXRlX3RyYWNlcyh0ZXh0dGVtcGxhdGUlM0QlMjIlMjUlN0J5JTNBLjFmJTdEJTIyJTJDJTIwdGV4dHBvc2l0aW9uJTNEJTIyb3V0c2lkZSUyMiklMEFmaWcuc2hvdygp",highlighted:`fig = px.bar(
    scores,
    color=scores,
    labels={
        <span class="hljs-string">&quot;value&quot;</span>: <span class="hljs-string">&quot;Accuracy&quot;</span>,
        <span class="hljs-string">&quot;settings&quot;</span>: <span class="hljs-string">&quot;Configuration&quot;</span>,
    },
    color_continuous_scale=<span class="hljs-string">&quot;bluered&quot;</span>,
)
fig.update_layout(
    width=<span class="hljs-number">1000</span>,
    height=<span class="hljs-number">600</span>,
    barmode=<span class="hljs-string">&quot;group&quot;</span>,
    yaxis_range=[<span class="hljs-number">0</span>, <span class="hljs-number">100</span>],
    title=<span class="hljs-string">&quot;&lt;b&gt;Accuracy of different RAG configurations&lt;/b&gt;&quot;</span>,
    xaxis_title=<span class="hljs-string">&quot;RAG settings&quot;</span>,
    font=<span class="hljs-built_in">dict</span>(size=<span class="hljs-number">15</span>),
)
fig.layout.yaxis.ticksuffix = <span class="hljs-string">&quot;%&quot;</span>
fig.update_coloraxes(showscale=<span class="hljs-literal">False</span>)
fig.update_traces(texttemplate=<span class="hljs-string">&quot;%{y:.1f}&quot;</span>, textposition=<span class="hljs-string">&quot;outside&quot;</span>)
fig.show()`,wrap:!1}}),Us=new ra({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/zh-CN/rag_evaluation.md"}}),{c(){o=e("meta"),ps=a(),ws=e("p"),is=a(),U(d.$$.fragment),Is=a(),U(r.$$.fragment),cs=a(),U(C.$$.fragment),os=a(),m=e("p"),m.innerHTML=Ut,us=a(),b=e("p"),b.textContent=Tt,ds=a(),h=e("p"),h.innerHTML=wt,rs=a(),B=e("p"),B.textContent=jt,Cs=a(),Z=e("img"),ms=a(),G=e("p"),G.textContent=it,bs=a(),U(A.$$.fragment),hs=a(),Q=e("p"),Q.textContent=It,Bs=a(),W=e("p"),W.textContent=ct,Zs=a(),V=e("ol"),V.innerHTML=ot,Gs=a(),R=e("p"),R.textContent=ut,As=a(),X=e("ol"),X.innerHTML=dt,Qs=a(),g=e("p"),g.innerHTML=rt,Ws=a(),U(f.$$.fragment),Vs=a(),U(N.$$.fragment),Rs=a(),U(k.$$.fragment),Xs=a(),U(v.$$.fragment),gs=a(),U(E.$$.fragment),fs=a(),U(S.$$.fragment),Ns=a(),U(Y.$$.fragment),ks=a(),F=e("p"),F.textContent=Ct,vs=a(),_=e("p"),_.textContent=mt,Es=a(),U(q.$$.fragment),Ss=a(),U(x.$$.fragment),Ys=a(),U(z.$$.fragment),Fs=a(),H=e("p"),H.innerHTML=bt,_s=a(),U($.$$.fragment),qs=a(),U(L.$$.fragment),xs=a(),D=e("p"),D.textContent=ht,zs=a(),K=e("p"),K.textContent=Bt,Hs=a(),P=e("p"),P.textContent=Zt,$s=a(),U(O.$$.fragment),Ls=a(),U(ll.$$.fragment),Ds=a(),U(sl.$$.fragment),Ks=a(),Ml=e("p"),Ml.textContent=Gt,Ps=a(),tl=e("p"),tl.innerHTML=At,Os=a(),al=e("ul"),al.innerHTML=Qt,lM=a(),nl=e("p"),nl.innerHTML=Wt,sM=a(),el=e("ul"),el.innerHTML=Vt,MM=a(),yl=e("p"),yl.textContent=Rt,tM=a(),Jl=e("p"),Jl.innerHTML=Xt,aM=a(),Ul=e("p"),Ul.textContent=gt,nM=a(),U(Tl.$$.fragment),eM=a(),U(wl.$$.fragment),yM=a(),jl=e("p"),jl.textContent=ft,JM=a(),U(pl.$$.fragment),UM=a(),il=e("pre"),il.textContent=Nt,TM=a(),Il=e("p"),Il.textContent=kt,wM=a(),cl=e("p"),cl.textContent=vt,jM=a(),U(ol.$$.fragment),pM=a(),U(ul.$$.fragment),iM=a(),U(dl.$$.fragment),IM=a(),rl=e("ul"),rl.innerHTML=Et,cM=a(),Cl=e("p"),Cl.textContent=St,oM=a(),ml=e("ul"),ml.innerHTML=Yt,uM=a(),bl=e("p"),bl.innerHTML=Ft,dM=a(),hl=e("blockquote"),hl.innerHTML=_t,rM=a(),U(Bl.$$.fragment),CM=a(),U(Zl.$$.fragment),mM=a(),U(Gl.$$.fragment),bM=a(),Al=e("p"),Al.innerHTML=qt,hM=a(),Ql=e("blockquote"),Ql.innerHTML=xt,BM=a(),Wl=e("p"),Wl.innerHTML=zt,ZM=a(),Vl=e("ul"),Vl.innerHTML=Ht,GM=a(),U(Rl.$$.fragment),AM=a(),U(Xl.$$.fragment),QM=a(),gl=e("p"),gl.innerHTML=$t,WM=a(),fl=e("p"),fl.textContent=Lt,VM=a(),Nl=e("ul"),Nl.innerHTML=Dt,RM=a(),U(kl.$$.fragment),XM=a(),U(vl.$$.fragment),gM=a(),U(El.$$.fragment),fM=a(),U(Sl.$$.fragment),NM=a(),Yl=e("p"),Yl.innerHTML=Kt,kM=a(),Fl=e("p"),Fl.innerHTML=Pt,vM=a(),_l=e("blockquote"),_l.innerHTML=Ot,EM=a(),ql=e("p"),ql.innerHTML=la,SM=a(),xl=e("p"),xl.innerHTML=sa,YM=a(),U(zl.$$.fragment),FM=a(),U(Hl.$$.fragment),_M=a(),U($l.$$.fragment),qM=a(),Ll=e("p"),Ll.textContent=Ma,xM=a(),U(Dl.$$.fragment),zM=a(),U(Kl.$$.fragment),HM=a(),U(Pl.$$.fragment),$M=a(),U(Ol.$$.fragment),LM=a(),U(ls.$$.fragment),DM=a(),U(ss.$$.fragment),KM=a(),Ms=e("p"),Ms.innerHTML=ta,PM=a(),ts=e("p"),ts.textContent=aa,OM=a(),as=e("p"),as.innerHTML=na,lt=a(),U(ns.$$.fragment),st=a(),U(es.$$.fragment),Mt=a(),u=e("img"),tt=a(),ys=e("p"),ys.textContent=ya,at=a(),Js=e("p"),Js.textContent=Ja,nt=a(),U(Us.$$.fragment),et=a(),js=e("p"),this.h()},l(l){const s=ca("svelte-u9bgzb",document.head);o=y(s,"META",{name:!0,content:!0}),s.forEach(M),ps=n(l),ws=y(l,"P",{}),Ta(ws).forEach(M),is=n(l),T(d.$$.fragment,l),Is=n(l),T(r.$$.fragment,l),cs=n(l),T(C.$$.fragment,l),os=n(l),m=y(l,"P",{"data-svelte-h":!0}),J(m)!=="svelte-11ntk8v"&&(m.innerHTML=Ut),us=n(l),b=y(l,"P",{"data-svelte-h":!0}),J(b)!=="svelte-zw09hj"&&(b.textContent=Tt),ds=n(l),h=y(l,"P",{"data-svelte-h":!0}),J(h)!=="svelte-1aes7ge"&&(h.innerHTML=wt),rs=n(l),B=y(l,"P",{"data-svelte-h":!0}),J(B)!=="svelte-12rale4"&&(B.textContent=jt),Cs=n(l),Z=y(l,"IMG",{src:!0,height:!0}),ms=n(l),G=y(l,"P",{"data-svelte-h":!0}),J(G)!=="svelte-10yhsu2"&&(G.textContent=it),bs=n(l),T(A.$$.fragment,l),hs=n(l),Q=y(l,"P",{"data-svelte-h":!0}),J(Q)!=="svelte-lx6lk2"&&(Q.textContent=It),Bs=n(l),W=y(l,"P",{"data-svelte-h":!0}),J(W)!=="svelte-1ukr2wc"&&(W.textContent=ct),Zs=n(l),V=y(l,"OL",{"data-svelte-h":!0}),J(V)!=="svelte-1mbcpc9"&&(V.innerHTML=ot),Gs=n(l),R=y(l,"P",{"data-svelte-h":!0}),J(R)!=="svelte-19a0j42"&&(R.textContent=ut),As=n(l),X=y(l,"OL",{"data-svelte-h":!0}),J(X)!=="svelte-1ebb9tz"&&(X.innerHTML=dt),Qs=n(l),g=y(l,"P",{"data-svelte-h":!0}),J(g)!=="svelte-1946r5u"&&(g.innerHTML=rt),Ws=n(l),T(f.$$.fragment,l),Vs=n(l),T(N.$$.fragment,l),Rs=n(l),T(k.$$.fragment,l),Xs=n(l),T(v.$$.fragment,l),gs=n(l),T(E.$$.fragment,l),fs=n(l),T(S.$$.fragment,l),Ns=n(l),T(Y.$$.fragment,l),ks=n(l),F=y(l,"P",{"data-svelte-h":!0}),J(F)!=="svelte-126kv91"&&(F.textContent=Ct),vs=n(l),_=y(l,"P",{"data-svelte-h":!0}),J(_)!=="svelte-4o7kqj"&&(_.textContent=mt),Es=n(l),T(q.$$.fragment,l),Ss=n(l),T(x.$$.fragment,l),Ys=n(l),T(z.$$.fragment,l),Fs=n(l),H=y(l,"P",{"data-svelte-h":!0}),J(H)!=="svelte-pq5chq"&&(H.innerHTML=bt),_s=n(l),T($.$$.fragment,l),qs=n(l),T(L.$$.fragment,l),xs=n(l),D=y(l,"P",{"data-svelte-h":!0}),J(D)!=="svelte-1b1cnkb"&&(D.textContent=ht),zs=n(l),K=y(l,"P",{"data-svelte-h":!0}),J(K)!=="svelte-k9r3k0"&&(K.textContent=Bt),Hs=n(l),P=y(l,"P",{"data-svelte-h":!0}),J(P)!=="svelte-a6hv5k"&&(P.textContent=Zt),$s=n(l),T(O.$$.fragment,l),Ls=n(l),T(ll.$$.fragment,l),Ds=n(l),T(sl.$$.fragment,l),Ks=n(l),Ml=y(l,"P",{"data-svelte-h":!0}),J(Ml)!=="svelte-cy38ww"&&(Ml.textContent=Gt),Ps=n(l),tl=y(l,"P",{"data-svelte-h":!0}),J(tl)!=="svelte-1osbiot"&&(tl.innerHTML=At),Os=n(l),al=y(l,"UL",{"data-svelte-h":!0}),J(al)!=="svelte-14wv6gb"&&(al.innerHTML=Qt),lM=n(l),nl=y(l,"P",{"data-svelte-h":!0}),J(nl)!=="svelte-1fze0kb"&&(nl.innerHTML=Wt),sM=n(l),el=y(l,"UL",{"data-svelte-h":!0}),J(el)!=="svelte-1yamk70"&&(el.innerHTML=Vt),MM=n(l),yl=y(l,"P",{"data-svelte-h":!0}),J(yl)!=="svelte-djxjqi"&&(yl.textContent=Rt),tM=n(l),Jl=y(l,"P",{"data-svelte-h":!0}),J(Jl)!=="svelte-crlkwa"&&(Jl.innerHTML=Xt),aM=n(l),Ul=y(l,"P",{"data-svelte-h":!0}),J(Ul)!=="svelte-1g2jy8m"&&(Ul.textContent=gt),nM=n(l),T(Tl.$$.fragment,l),eM=n(l),T(wl.$$.fragment,l),yM=n(l),jl=y(l,"P",{"data-svelte-h":!0}),J(jl)!=="svelte-cjndcy"&&(jl.textContent=ft),JM=n(l),T(pl.$$.fragment,l),UM=n(l),il=y(l,"PRE",{"data-svelte-h":!0}),J(il)!=="svelte-1k8l62p"&&(il.textContent=Nt),TM=n(l),Il=y(l,"P",{"data-svelte-h":!0}),J(Il)!=="svelte-q06ahl"&&(Il.textContent=kt),wM=n(l),cl=y(l,"P",{"data-svelte-h":!0}),J(cl)!=="svelte-1kklb5b"&&(cl.textContent=vt),jM=n(l),T(ol.$$.fragment,l),pM=n(l),T(ul.$$.fragment,l),iM=n(l),T(dl.$$.fragment,l),IM=n(l),rl=y(l,"UL",{"data-svelte-h":!0}),J(rl)!=="svelte-pqbs43"&&(rl.innerHTML=Et),cM=n(l),Cl=y(l,"P",{"data-svelte-h":!0}),J(Cl)!=="svelte-1965er0"&&(Cl.textContent=St),oM=n(l),ml=y(l,"UL",{"data-svelte-h":!0}),J(ml)!=="svelte-vakfil"&&(ml.innerHTML=Yt),uM=n(l),bl=y(l,"P",{"data-svelte-h":!0}),J(bl)!=="svelte-1ln9tsn"&&(bl.innerHTML=Ft),dM=n(l),hl=y(l,"BLOCKQUOTE",{"data-svelte-h":!0}),J(hl)!=="svelte-1b121lz"&&(hl.innerHTML=_t),rM=n(l),T(Bl.$$.fragment,l),CM=n(l),T(Zl.$$.fragment,l),mM=n(l),T(Gl.$$.fragment,l),bM=n(l),Al=y(l,"P",{"data-svelte-h":!0}),J(Al)!=="svelte-1movshy"&&(Al.innerHTML=qt),hM=n(l),Ql=y(l,"BLOCKQUOTE",{"data-svelte-h":!0}),J(Ql)!=="svelte-1l6mdl0"&&(Ql.innerHTML=xt),BM=n(l),Wl=y(l,"P",{"data-svelte-h":!0}),J(Wl)!=="svelte-lzkfgi"&&(Wl.innerHTML=zt),ZM=n(l),Vl=y(l,"UL",{"data-svelte-h":!0}),J(Vl)!=="svelte-1kyrqvw"&&(Vl.innerHTML=Ht),GM=n(l),T(Rl.$$.fragment,l),AM=n(l),T(Xl.$$.fragment,l),QM=n(l),gl=y(l,"P",{"data-svelte-h":!0}),J(gl)!=="svelte-10ha94n"&&(gl.innerHTML=$t),WM=n(l),fl=y(l,"P",{"data-svelte-h":!0}),J(fl)!=="svelte-171gtnx"&&(fl.textContent=Lt),VM=n(l),Nl=y(l,"UL",{"data-svelte-h":!0}),J(Nl)!=="svelte-1f36qso"&&(Nl.innerHTML=Dt),RM=n(l),T(kl.$$.fragment,l),XM=n(l),T(vl.$$.fragment,l),gM=n(l),T(El.$$.fragment,l),fM=n(l),T(Sl.$$.fragment,l),NM=n(l),Yl=y(l,"P",{"data-svelte-h":!0}),J(Yl)!=="svelte-1sqpkjh"&&(Yl.innerHTML=Kt),kM=n(l),Fl=y(l,"P",{"data-svelte-h":!0}),J(Fl)!=="svelte-1mbklsh"&&(Fl.innerHTML=Pt),vM=n(l),_l=y(l,"BLOCKQUOTE",{"data-svelte-h":!0}),J(_l)!=="svelte-1gm4r4w"&&(_l.innerHTML=Ot),EM=n(l),ql=y(l,"P",{"data-svelte-h":!0}),J(ql)!=="svelte-1tcmdhq"&&(ql.innerHTML=la),SM=n(l),xl=y(l,"P",{"data-svelte-h":!0}),J(xl)!=="svelte-t9ho3k"&&(xl.innerHTML=sa),YM=n(l),T(zl.$$.fragment,l),FM=n(l),T(Hl.$$.fragment,l),_M=n(l),T($l.$$.fragment,l),qM=n(l),Ll=y(l,"P",{"data-svelte-h":!0}),J(Ll)!=="svelte-1ffahd2"&&(Ll.textContent=Ma),xM=n(l),T(Dl.$$.fragment,l),zM=n(l),T(Kl.$$.fragment,l),HM=n(l),T(Pl.$$.fragment,l),$M=n(l),T(Ol.$$.fragment,l),LM=n(l),T(ls.$$.fragment,l),DM=n(l),T(ss.$$.fragment,l),KM=n(l),Ms=y(l,"P",{"data-svelte-h":!0}),J(Ms)!=="svelte-19tissg"&&(Ms.innerHTML=ta),PM=n(l),ts=y(l,"P",{"data-svelte-h":!0}),J(ts)!=="svelte-l94cws"&&(ts.textContent=aa),OM=n(l),as=y(l,"P",{"data-svelte-h":!0}),J(as)!=="svelte-1wj10g3"&&(as.innerHTML=na),lt=n(l),T(ns.$$.fragment,l),st=n(l),T(es.$$.fragment,l),Mt=n(l),u=y(l,"IMG",{src:!0,height:!0,width:!0}),tt=n(l),ys=y(l,"P",{"data-svelte-h":!0}),J(ys)!=="svelte-ds7a4o"&&(ys.textContent=ya),at=n(l),Js=y(l,"P",{"data-svelte-h":!0}),J(Js)!=="svelte-1dxb7bg"&&(Js.textContent=Ja),nt=n(l),T(Us.$$.fragment,l),et=n(l),js=y(l,"P",{}),Ta(js).forEach(M),this.h()},h(){Ts(o,"name","hf:doc:metadata"),Ts(o,"content",ma),Ua(Z.src,pt="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/RAG_workflow.png")||Ts(Z,"src",pt),Ts(Z,"height","700"),Ua(u.src,ea="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/RAG_settings_accuracy.png")||Ts(u,"src",ea),Ts(u,"height","500"),Ts(u,"width","800")},m(l,s){oa(document.head,o),t(l,ps,s),t(l,ws,s),t(l,is,s),w(d,l,s),t(l,Is,s),w(r,l,s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l,hl,s),t(l,rM,s),w(Bl,l,s),t(l,CM,s),w(Zl,l,s),t(l,mM,s),w(Gl,l,s),t(l,bM,s),t(l,Al,s),t(l,hM,s),t(l,Ql,s),t(l,BM,s),t(l,Wl,s),t(l,ZM,s),t(l,Vl,s),t(l,GM,s),w(Rl,l,s),t(l,AM,s),w(Xl,l,s),t(l,QM,s),t(l,gl,s),t(l,WM,s),t(l,fl,s),t(l,VM,s),t(l,Nl,s),t(l,RM,s),w(kl,l,s),t(l,XM,s),w(vl,l,s),t(l,gM,s),w(El,l,s),t(l,fM,s),w(Sl,l,s),t(l,NM,s),t(l,Yl,s),t(l,kM,s),t(l,Fl,s),t(l,vM,s),t(l,_l,s),t(l,EM,s),t(l,ql,s),t(l,SM,s),t(l,xl,s),t(l,YM,s),w(zl,l,s),t(l,FM,s),w(Hl,l,s),t(l,_M,s),w($l,l,s),t(l,qM,s),t(l,Ll,s),t(l,xM,s),w(Dl,l,s),t(l,zM,s),w(Kl,l,s),t(l,HM,s),w(Pl,l,s),t(l,$M,s),w(Ol,l,s),t(l,LM,s),w(ls,l,s),t(l,DM,s),w(ss,l,s),t(l,KM,s),t(l,Ms,s),t(l,PM,s),t(l,ts,s),t(l,OM,s),t(l,as,s),t(l,lt,s),w(ns,l,s),t(l,st,s),w(es,l,s),t(l,Mt,s),t(l,u,s),t(l,tt,s),t(l,ys,s),t(l,at,s),t(l,Js,s),t(l,nt,s),w(Us,l,s),t(l,et,s),t(l,js,s),yt=!0},p:ja,i(l){yt||(j(d.$$.fragment,l),j(r.$$.fragment,l),j(C.$$.fragment,l),j(A.$$.fragment,l),j(f.$$.fragment,l),j(N.$$.fragment,l),j(k.$$.fragment,l),j(v.$$.fragment,l),j(E.$$.fragment,l),j(S.$$.fragment,l),j(Y.$$.fragment,l),j(q.$$.fragment,l),j(x.$$.fragment,l),j(z.$$.fragment,l),j($.$$.fragment,l),j(L.$$.fragment,l),j(O.$$.fragment,l),j(ll.$$.fragment,l),j(sl.$$.fragment,l),j(Tl.$$.fragment,l),j(wl.$$.fragment,l),j(pl.$$.fragment,l),j(ol.$$.fragment,l),j(ul.$$.fragment,l),j(dl.$$.fragment,l),j(Bl.$$.fragment,l),j(Zl.$$.fragment,l),j(Gl.$$.fragment,l),j(Rl.$$.fragment,l),j(Xl.$$.fragment,l),j(kl.$$.fragment,l),j(vl.$$.fragment,l),j(El.$$.fragment,l),j(Sl.$$.fragment,l),j(zl.$$.fragment,l),j(Hl.$$.fragment,l),j($l.$$.fragment,l),j(Dl.$$.fragment,l),j(Kl.$$.fragment,l),j(Pl.$$.fragment,l),j(Ol.$$.fragment,l),j(ls.$$.fragment,l),j(ss.$$.fragment,l),j(ns.$$.fragment,l),j(es.$$.fragment,l),j(Us.$$.fragment,l),yt=!0)},o(l){p(d.$$.fragment,l),p(r.$$.fragment,l),p(C.$$.fragment,l),p(A.$$.fragment,l),p(f.$$.fragment,l),p(N.$$.fragment,l),p(k.$$.fragment,l),p(v.$$.fragment,l),p(E.$$.fragment,l),p(S.$$.fragment,l),p(Y.$$.fragment,l),p(q.$$.fragment,l),p(x.$$.fragment,l),p(z.$$.fragment,l),p($.$$.fragment,l),p(L.$$.fragment,l),p(O.$$.fragment,l),p(ll.$$.fragment,l),p(sl.$$.fragment,l),p(Tl.$$.fragment,l),p(wl.$$.fragment,l),p(pl.$$.fragment,l),p(ol.$$.fragment,l),p(ul.$$.fragment,l),p(dl.$$.fragment,l),p(Bl.$$.fragment,l),p(Zl.$$.fragment,l),p(Gl.$$.fragment,l),p(Rl.$$.fragment,l),p(Xl.$$.fragment,l),p(kl.$$.fragment,l),p(vl.$$.fragment,l),p(El.$$.fragment,l),p(Sl.$$.fragment,l),p(zl.$$.fragment,l),p(Hl.$$.fragment,l),p($l.$$.fragment,l),p(Dl.$$.fragment,l),p(Kl.$$.fragment,l),p(Pl.$$.fragment,l),p(Ol.$$.fragment,l),p(ls.$$.fragment,l),p(ss.$$.fragment,l),p(ns.$$.fragment,l),p(es.$$.fragment,l),p(Us.$$.fragment,l),yt=!1},d(l){l&&(M(ps),M(ws),M(is),M(Is),M(cs),M(os),M(m),M(us),M(b),M(ds),M(h),M(rs),M(B),M(Cs),M(Z),M(ms),M(G),M(bs),M(hs),M(Q),M(Bs),M(W),M(Zs),M(V),M(Gs),M(R),M(As),M(X),M(Qs),M(g),M(Ws),M(Vs),M(Rs),M(Xs),M(gs),M(fs),M(Ns),M(ks),M(F),M(vs),M(_),M(Es),M(Ss),M(Ys),M(Fs),M(H),M(_s),M(qs),M(xs),M(D),M(zs),M(K),M(Hs),M(P),M($s),M(Ls),M(Ds),M(Ks),M(Ml),M(Ps),M(tl),M(Os),M(al),M(lM),M(nl),M(sM),M(el),M(MM),M(yl),M(tM),M(Jl),M(aM),M(Ul),M(nM),M(eM),M(yM),M(jl),M(JM),M(UM),M(il),M(TM),M(Il),M(wM),M(cl),M(jM),M(pM),M(iM),M(IM),M(rl),M(cM),M(Cl),M(oM),M(ml),M(uM),M(bl),M(dM),M(hl),M(rM),M(CM),M(mM),M(bM),M(Al),M(hM),M(Ql),M(BM),M(Wl),M(ZM),M(Vl),M(GM),M(AM),M(QM),M(gl),M(WM),M(fl),M(VM),M(Nl),M(RM),M(XM),M(gM),M(fM),M(NM),M(Yl),M(kM),M(Fl),M(vM),M(_l),M(EM),M(ql),M(SM),M(xl),M(YM),M(FM),M(_M),M(qM),M(Ll),M(xM),M(zM),M(HM),M($M),M(LM),M(DM),M(KM),M(Ms),M(PM),M(ts),M(OM),M(as),M(lt),M(st),M(Mt),M(u),M(tt),M(ys),M(at),M(Js),M(nt),M(et),M(js)),M(o),i(d,l),i(r,l),i(C,l),i(A,l),i(f,l),i(N,l),i(k,l),i(v,l),i(E,l),i(S,l),i(Y,l),i(q,l),i(x,l),i(z,l),i($,l),i(L,l),i(O,l),i(ll,l),i(sl,l),i(Tl,l),i(wl,l),i(pl,l),i(ol,l),i(ul,l),i(dl,l),i(Bl,l),i(Zl,l),i(Gl,l),i(Rl,l),i(Xl,l),i(kl,l),i(vl,l),i(El,l),i(Sl,l),i(zl,l),i(Hl,l),i($l,l),i(Dl,l),i(Kl,l),i(Pl,l),i(Ol,l),i(ls,l),i(ss,l),i(ns,l),i(es,l),i(Us,l)}}}const ma='{"title":"RAG 评估","local":"rag-评估","sections":[{"title":"评估RAG性能","local":"评估rag性能","sections":[],"depth":3},{"title":"加载你的知识基础","local":"加载你的知识基础","sections":[],"depth":3}],"depth":1}';function ba(Jt){return pa(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qa extends ia{constructor(o){super(),Ia(this,o,ba,Ca,wa,{})}}export{Qa as component};
