import{s as Gn,o as Vn,n as Ae}from"../chunks/scheduler.889ebb13.js";import{S as En,i as Rn,g as o,s as a,r as f,m as x,A as Bn,h as r,f as n,c as s,j as St,u as y,x as u,n as J,k as j,y as Z,a as l,v as w,d as b,t as g,w as M}from"../chunks/index.ca18042b.js";import{T as Xe}from"../chunks/Tip.b8116e3c.js";import{C as I}from"../chunks/CodeBlock.1db71023.js";import{H as ke}from"../chunks/Heading.3daa581c.js";import{E as Xn}from"../chunks/EditOnGithub.2e95618d.js";function An(U){let c,m,T="this notebook",p;return{c(){c=x("You can follow the code in "),m=o("a"),m.textContent=T,p=x(" that you can run using Google Colab."),this.h()},l(i){c=J(i,"You can follow the code in "),m=r(i,"A",{href:!0,target:!0,"data-svelte-h":!0}),u(m)!=="svelte-8yz016"&&(m.textContent=T),p=J(i," that you can run using Google Colab."),this.h()},h(){j(m,"href","https://huggingface.co/agents-course/notebooks/blob/main/unit2/llama-index/components.ipynb"),j(m,"target","_blank")},m(i,v){l(i,c,v),l(i,m,v),l(i,p,v)},p:Ae,d(i){i&&(n(c),n(m),n(p))}}}function Hn(U){let c,m,T="LlamaHub",p,i,v="LlamaParse",h;return{c(){c=x("Get familiar with "),m=o("a"),m.textContent=T,p=x(" loaders and "),i=o("a"),i.textContent=v,h=x(" parser for more complex data sources."),this.h()},l(d){c=J(d,"Get familiar with "),m=r(d,"A",{href:!0,"data-svelte-h":!0}),u(m)!=="svelte-533qfu"&&(m.textContent=T),p=J(d," loaders and "),i=r(d,"A",{href:!0,"data-svelte-h":!0}),u(i)!=="svelte-a3asoh"&&(i.textContent=v),h=J(d," parser for more complex data sources."),this.h()},h(){j(m,"href","https://docs.llamaindex.ai/en/stable/module_guides/loading/connector/"),j(i,"href","https://github.com/run-llama/llama_cloud_services/blob/main/parse.md")},m(d,$){l(d,c,$),l(d,m,$),l(d,p,$),l(d,i,$),l(d,h,$)},p:Ae,d(d){d&&(n(c),n(m),n(p),n(i),n(h))}}}function Sn(U){let c,m,T="LlamaIndex documentation",p;return{c(){c=x("An overview of the different vector stores can be found in the "),m=o("a"),m.textContent=T,p=x("."),this.h()},l(i){c=J(i,"An overview of the different vector stores can be found in the "),m=r(i,"A",{href:!0,"data-svelte-h":!0}),u(m)!=="svelte-1e65i8i"&&(m.textContent=T),p=J(i,"."),this.h()},h(){j(m,"href","https://docs.llamaindex.ai/en/stable/module_guides/storing/vector_stores/")},m(i,v){l(i,c,v),l(i,m,v),l(i,p,v)},p:Ae,d(i){i&&(n(c),n(m),n(p))}}}function Yn(U){let c,m,T="low-level composition API",p,i,v="Workflows";return{c(){c=x("Take fine-grained control of your query workflows with the "),m=o("a"),m.textContent=T,p=x(". This API lets you customize and fine-tune every step of the query process to match your exact needs, which also pairs great with "),i=o("a"),i.textContent=v,this.h()},l(h){c=J(h,"Take fine-grained control of your query workflows with the "),m=r(h,"A",{href:!0,"data-svelte-h":!0}),u(m)!=="svelte-arbcj7"&&(m.textContent=T),p=J(h,". This API lets you customize and fine-tune every step of the query process to match your exact needs, which also pairs great with "),i=r(h,"A",{href:!0,"data-svelte-h":!0}),u(i)!=="svelte-h6xwqz"&&(i.textContent=v),this.h()},h(){j(m,"href","https://docs.llamaindex.ai/en/stable/module_guides/deploying/query_engine/usage_pattern/#low-level-composition-api"),j(i,"href","https://docs.llamaindex.ai/en/stable/module_guides/workflow/")},m(h,d){l(h,c,d),l(h,m,d),l(h,p,d),l(h,i,d)},p:Ae,d(h){h&&(n(c),n(m),n(p),n(i))}}}function Fn(U){let c,m,T="Components Guides",p,i,v="Guide on RAG",h;return{c(){c=x("Want to learn more about components and how to use them? Continue your journey with the "),m=o("a"),m.textContent=T,p=x(" or the "),i=o("a"),i.textContent=v,h=x("."),this.h()},l(d){c=J(d,"Want to learn more about components and how to use them? Continue your journey with the "),m=r(d,"A",{href:!0,"data-svelte-h":!0}),u(m)!=="svelte-1br2a7q"&&(m.textContent=T),p=J(d," or the "),i=r(d,"A",{href:!0,"data-svelte-h":!0}),u(i)!=="svelte-jojkhh"&&(i.textContent=v),h=J(d,"."),this.h()},h(){j(m,"href","https://docs.llamaindex.ai/en/stable/module_guides/"),j(i,"href","https://docs.llamaindex.ai/en/stable/understanding/rag/")},m(d,$){l(d,c,$),l(d,m,$),l(d,p,$),l(d,i,$),l(d,h,$)},p:Ae,d(d){d&&(n(c),n(m),n(p),n(i),n(h))}}}function Nn(U){let c,m,T,p,i,v,h,d=`Remember Alfred, our helpful butler agent from Unit 1?
To assist us effectively, Alfred needs to understand our requests and <strong>prepare, find and use relevant information to help complete tasks.</strong>
This is where LlamaIndex’s components come in.`,$,R,Qt=`While LlamaIndex has many components, <strong>we’ll focus specifically on the <code>QueryEngine</code> component.</strong>
Why? Because it can be used as a Retrieval-Augmented Generation (RAG) tool for an agent.`,He,B,Pt=`So, what is RAG? LLMs are trained on enormous bodies of data to learn general knowledge.
However, they may not be trained on relevant and up-to-date data.
RAG solves this problem by finding and retrieving relevant information from your data and giving that to the LLM.`,Se,X,zt='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/llama-index/rag.png" alt="RAG"/>',Ye,A,Dt="Now, think about how Alfred works:",Fe,H,Kt="<li>You ask Alfred to help plan a dinner party</li> <li>Alfred needs to check your calendar, dietary preferences, and past successful menus</li> <li>The <code>QueryEngine</code> helps Alfred find this information and use it to plan the dinner party</li>",Ne,S,Ot=`This makes the <code>QueryEngine</code> <strong>a key component for building agentic RAG workflows</strong> in LlamaIndex.
Just as Alfred needs to search through your household information to be helpful, any agent needs a way to find and understand relevant data.
The <code>QueryEngine</code> provides exactly this capability.`,qe,Y,en="Now, let’s dive a bit deeper into the components and see how you can <strong>combine components to create a RAG pipeline.</strong>",Qe,F,Pe,L,ze,N,tn="There are five key stages within RAG, which in turn will be a part of most larger applications you build. These are:",De,q,nn="<li><strong>Loading</strong>: this refers to getting your data from where it lives — whether it’s text files, PDFs, another website, a database, or an API — into your workflow. LlamaHub provides hundreds of integrations to choose from.</li> <li><strong>Indexing</strong>: this means creating a data structure that allows for querying the data. For LLMs, this nearly always means creating vector embeddings. Which are numerical representations of the meaning of the data. Indexing can also refer to numerous other metadata strategies to make it easy to accurately find contextually relevant data based on properties.</li> <li><strong>Storing</strong>: once your data is indexed you will want to store your index, as well as other metadata, to avoid having to re-index it.</li> <li><strong>Querying</strong>: for any given indexing strategy there are many ways you can utilize LLMs and LlamaIndex data structures to query, including sub-queries, multi-step queries and hybrid strategies.</li> <li><strong>Evaluation</strong>: a critical step in any flow is checking how effective it is relative to other strategies, or when you make changes. Evaluation provides objective measures of how accurate, faithful and fast your responses to queries are.</li>",Ke,Q,ln="Next, let’s see how we can reproduce these stages using components.",Oe,P,et,z,an=`As mentioned before, LlamaIndex can work on top of your own data, however, <strong>before accessing data, we need to load it.</strong>
There are three main ways to load data into LlamaIndex:`,tt,D,sn="<li><code>SimpleDirectoryReader</code>: A built-in loader for various file types from a local directory.</li> <li><code>LlamaParse</code>: LlamaParse, LlamaIndex’s official tool for PDF parsing, available as a managed API.</li> <li><code>LlamaHub</code>: A registry of hundreds of data-loading libraries to ingest data from any source.</li>",nt,W,lt,K,on=`<strong>The simplest way to load data is with <code>SimpleDirectoryReader</code>.</strong>
This versatile component can load various file types from a folder and convert them into <code>Document</code> objects that LlamaIndex can work with.
Let’s see how we can use <code>SimpleDirectoryReader</code> to load data from a folder.`,at,O,st,ee,rn=`After loading our documents, we need to break them into smaller pieces called <code>Node</code> objects.
A <code>Node</code> is just a chunk of text from the original document that’s easier for the AI to work with, while it still has references to the original <code>Document</code> object.`,it,te,mn="The <code>IngestionPipeline</code> helps us create these nodes through two key transformations.",ot,ne,un="<li><code>SentenceSplitter</code> breaks down documents into manageable chunks by splitting them at natural sentence boundaries.</li> <li><code>HuggingFaceEmbedding</code> converts each chunk into numerical embeddings - vector representations that capture the semantic meaning in a way AI can process efficiently.</li>",rt,le,dn="This process helps us organise our documents in a way that’s more useful for searching and analysis.",mt,ae,ut,se,dt,ie,cn="After creating our <code>Node</code> objects we need to index them to make them searchable, but before we can do that, we need a place to store our data.",ct,oe,pn=`Since we are using an ingestion pipeline, we can directly attach a vector store to the pipeline to populate it.
In this case, we will use <code>Chroma</code> to store our documents.`,pt,k,Ge,hn="Install ChromaDB",Yt,re,ht,me,ft,G,yt,ue,fn=`This is where vector embeddings come in - by embedding both the query and nodes in the same vector space, we can find relevant matches.
The <code>VectorStoreIndex</code> handles this for us, using the same embedding model we used during ingestion to ensure consistency.`,wt,de,yn="Let’s see how to create this index from our vector store and embeddings:",bt,ce,gt,pe,wn="All information is automatically persisted within the <code>ChromaVectorStore</code> object and the passed directory path.",Mt,he,bn="Great! Now that we can save and load our index easily, let’s explore how to query it in different ways.",vt,fe,Tt,ye,gn="Before we can query our index, we need to convert it to a query interface. The most common conversion options are:",$t,we,Mn="<li><code>as_retriever</code>: For basic document retrieval, returning a list of <code>NodeWithScore</code> objects with similarity scores</li> <li><code>as_query_engine</code>: For single question-answer interactions, returning a written response</li> <li><code>as_chat_engine</code>: For conversational interactions that maintain memory across multiple messages, returning a written response using chat history and indexed context</li>",xt,be,vn=`We’ll focus on the query engine since it is more common for agent-like interactions.
We also pass in an LLM to the query engine to use for the response.`,Jt,ge,Ut,Me,Ct,ve,Tn=`Under the hood, the query engine doesn’t only use the LLM to answer the question but also uses a <code>ResponseSynthesizer</code> as a strategy to process the response.
Once again, this is fully customisable but there are three main strategies that work well out of the box:`,_t,Te,$n="<li><code>refine</code>: create and refine an answer by sequentially going through each retrieved text chunk. This makes a separate LLM call per Node/retrieved chunk.</li> <li><code>compact</code> (default): similar to refining but concatenating the chunks beforehand, resulting in fewer LLM calls.</li> <li><code>tree_summarize</code>: create a detailed answer by going through each retrieved text chunk and creating a tree structure of the answer.</li>",jt,V,Zt,$e,xn="The language model won’t always perform in predictable ways, so we can’t be sure that the answer we get is always correct. We can deal with this by <strong>evaluating the quality of the answer</strong>.",It,xe,Lt,Je,Jn=`LlamaIndex provides <strong>built-in evaluation tools to assess response quality.</strong>
These evaluators leverage LLMs to analyze responses across different dimensions.
Let’s look at the three main evaluators available:`,Wt,Ue,Un="<li><code>FaithfulnessEvaluator</code>: Evaluates the faithfulness of the answer by checking if the answer is supported by the context.</li> <li><code>AnswerRelevancyEvaluator</code>: Evaluate the relevance of the answer by checking if the answer is relevant to the question.</li> <li><code>CorrectnessEvaluator</code>: Evaluate the correctness of the answer by checking if the answer is correct.</li>",kt,Ce,Gt,_e,Cn=`Even without direct evaluation, we can <strong>gain insights into how our system is performing through observability.</strong>
This is especially useful when we are building more complex workflows and want to understand how each component is performing.`,Vt,C,Ve,_n="Install LlamaTrace",Ft,je,Nt,Ee,jn="Additionally, we need to set the <code>PHOENIX_API_KEY</code> environment variable to our LlamaTrace API key. We can get this by:",qt,Re,Zn='<li>Creating an account at <a href="https://llamatrace.com/login" rel="nofollow">LlamaTrace</a></li> <li>Generating an API key in your account settings</li> <li>Using the API key in the code below to enable tracing</li>',Et,Ze,Rt,E,Bt,Ie,In="We have seen how to use components to create a <code>QueryEngine</code>. Now, let’s see how we can <strong>use the <code>QueryEngine</code> as a tool for an agent!</strong>",Xt,Le,At,Be,Ht;return i=new ke({props:{title:"What are components in LlamaIndex?",local:"what-are-components-in-llamaindex",headingTag:"h1"}}),F=new ke({props:{title:"Creating a RAG pipeline using components",local:"creating-a-rag-pipeline-using-components",headingTag:"h2"}}),L=new Xe({props:{$$slots:{default:[An]},$$scope:{ctx:U}}}),P=new ke({props:{title:"Loading and embedding documents",local:"loading-and-embedding-documents",headingTag:"h3"}}),W=new Xe({props:{$$slots:{default:[Hn]},$$scope:{ctx:U}}}),O=new I({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUlMjBpbXBvcnQlMjBTaW1wbGVEaXJlY3RvcnlSZWFkZXIlMEElMEFyZWFkZXIlMjAlM0QlMjBTaW1wbGVEaXJlY3RvcnlSZWFkZXIoaW5wdXRfZGlyJTNEJTIycGF0aCUyRnRvJTJGZGlyZWN0b3J5JTIyKSUwQWRvY3VtZW50cyUyMCUzRCUyMHJlYWRlci5sb2FkX2RhdGEoKQ==",highlighted:`<span class="hljs-keyword">from</span> llama_index.core <span class="hljs-keyword">import</span> SimpleDirectoryReader

reader = SimpleDirectoryReader(input_dir=<span class="hljs-string">&quot;path/to/directory&quot;</span>)
documents = reader.load_data()`,wrap:!1}}),ae=new I({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUlMjBpbXBvcnQlMjBEb2N1bWVudCUwQWZyb20lMjBsbGFtYV9pbmRleC5lbWJlZGRpbmdzLmh1Z2dpbmdmYWNlJTIwaW1wb3J0JTIwSHVnZ2luZ0ZhY2VFbWJlZGRpbmclMEFmcm9tJTIwbGxhbWFfaW5kZXguY29yZS5ub2RlX3BhcnNlciUyMGltcG9ydCUyMFNlbnRlbmNlU3BsaXR0ZXIlMEFmcm9tJTIwbGxhbWFfaW5kZXguY29yZS5pbmdlc3Rpb24lMjBpbXBvcnQlMjBJbmdlc3Rpb25QaXBlbGluZSUwQSUwQSUyMyUyMGNyZWF0ZSUyMHRoZSUyMHBpcGVsaW5lJTIwd2l0aCUyMHRyYW5zZm9ybWF0aW9ucyUwQXBpcGVsaW5lJTIwJTNEJTIwSW5nZXN0aW9uUGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwdHJhbnNmb3JtYXRpb25zJTNEJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwU2VudGVuY2VTcGxpdHRlcihjaHVua19vdmVybGFwJTNEMCklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBIdWdnaW5nRmFjZUVtYmVkZGluZyhtb2RlbF9uYW1lJTNEJTIyQkFBSSUyRmJnZS1zbWFsbC1lbi12MS41JTIyKSUyQyUwQSUyMCUyMCUyMCUyMCU1RCUwQSklMEElMEFub2RlcyUyMCUzRCUyMGF3YWl0JTIwcGlwZWxpbmUuYXJ1bihkb2N1bWVudHMlM0QlNUJEb2N1bWVudC5leGFtcGxlKCklNUQp",highlighted:`<span class="hljs-keyword">from</span> llama_index.core <span class="hljs-keyword">import</span> Document
<span class="hljs-keyword">from</span> llama_index.embeddings.huggingface <span class="hljs-keyword">import</span> HuggingFaceEmbedding
<span class="hljs-keyword">from</span> llama_index.core.node_parser <span class="hljs-keyword">import</span> SentenceSplitter
<span class="hljs-keyword">from</span> llama_index.core.ingestion <span class="hljs-keyword">import</span> IngestionPipeline

<span class="hljs-comment"># create the pipeline with transformations</span>
pipeline = IngestionPipeline(
    transformations=[
        SentenceSplitter(chunk_overlap=<span class="hljs-number">0</span>),
        HuggingFaceEmbedding(model_name=<span class="hljs-string">&quot;BAAI/bge-small-en-v1.5&quot;</span>),
    ]
)

nodes = <span class="hljs-keyword">await</span> pipeline.arun(documents=[Document.example()])`,wrap:!1}}),se=new ke({props:{title:"Storing and indexing documents",local:"storing-and-indexing-documents",headingTag:"h3"}}),re=new I({props:{code:"cGlwJTIwaW5zdGFsbCUyMGxsYW1hLWluZGV4LXZlY3Rvci1zdG9yZXMtY2hyb21h",highlighted:"pip install llama-index-vector-stores-chroma",wrap:!1}}),me=new I({props:{code:"aW1wb3J0JTIwY2hyb21hZGIlMEFmcm9tJTIwbGxhbWFfaW5kZXgudmVjdG9yX3N0b3Jlcy5jaHJvbWElMjBpbXBvcnQlMjBDaHJvbWFWZWN0b3JTdG9yZSUwQSUwQWRiJTIwJTNEJTIwY2hyb21hZGIuUGVyc2lzdGVudENsaWVudChwYXRoJTNEJTIyLiUyRmFsZnJlZF9jaHJvbWFfZGIlMjIpJTBBY2hyb21hX2NvbGxlY3Rpb24lMjAlM0QlMjBkYi5nZXRfb3JfY3JlYXRlX2NvbGxlY3Rpb24oJTIyYWxmcmVkJTIyKSUwQXZlY3Rvcl9zdG9yZSUyMCUzRCUyMENocm9tYVZlY3RvclN0b3JlKGNocm9tYV9jb2xsZWN0aW9uJTNEY2hyb21hX2NvbGxlY3Rpb24pJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBJbmdlc3Rpb25QaXBlbGluZSglMEElMjAlMjAlMjAlMjB0cmFuc2Zvcm1hdGlvbnMlM0QlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBTZW50ZW5jZVNwbGl0dGVyKGNodW5rX3NpemUlM0QyNSUyQyUyMGNodW5rX292ZXJsYXAlM0QwKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMEh1Z2dpbmdGYWNlRW1iZWRkaW5nKG1vZGVsX25hbWUlM0QlMjJCQUFJJTJGYmdlLXNtYWxsLWVuLXYxLjUlMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTVEJTJDJTBBJTIwJTIwJTIwJTIwdmVjdG9yX3N0b3JlJTNEdmVjdG9yX3N0b3JlJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> chromadb
<span class="hljs-keyword">from</span> llama_index.vector_stores.chroma <span class="hljs-keyword">import</span> ChromaVectorStore

db = chromadb.PersistentClient(path=<span class="hljs-string">&quot;./alfred_chroma_db&quot;</span>)
chroma_collection = db.get_or_create_collection(<span class="hljs-string">&quot;alfred&quot;</span>)
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)

pipeline = IngestionPipeline(
    transformations=[
        SentenceSplitter(chunk_size=<span class="hljs-number">25</span>, chunk_overlap=<span class="hljs-number">0</span>),
        HuggingFaceEmbedding(model_name=<span class="hljs-string">&quot;BAAI/bge-small-en-v1.5&quot;</span>),
    ],
    vector_store=vector_store,
)`,wrap:!1}}),G=new Xe({props:{$$slots:{default:[Sn]},$$scope:{ctx:U}}}),ce=new I({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUlMjBpbXBvcnQlMjBWZWN0b3JTdG9yZUluZGV4JTBBZnJvbSUyMGxsYW1hX2luZGV4LmVtYmVkZGluZ3MuaHVnZ2luZ2ZhY2UlMjBpbXBvcnQlMjBIdWdnaW5nRmFjZUVtYmVkZGluZyUwQSUwQWVtYmVkX21vZGVsJTIwJTNEJTIwSHVnZ2luZ0ZhY2VFbWJlZGRpbmcobW9kZWxfbmFtZSUzRCUyMkJBQUklMkZiZ2Utc21hbGwtZW4tdjEuNSUyMiklMEFpbmRleCUyMCUzRCUyMFZlY3RvclN0b3JlSW5kZXguZnJvbV92ZWN0b3Jfc3RvcmUodmVjdG9yX3N0b3JlJTJDJTIwZW1iZWRfbW9kZWwlM0RlbWJlZF9tb2RlbCk=",highlighted:`<span class="hljs-keyword">from</span> llama_index.core <span class="hljs-keyword">import</span> VectorStoreIndex
<span class="hljs-keyword">from</span> llama_index.embeddings.huggingface <span class="hljs-keyword">import</span> HuggingFaceEmbedding

embed_model = HuggingFaceEmbedding(model_name=<span class="hljs-string">&quot;BAAI/bge-small-en-v1.5&quot;</span>)
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=embed_model)`,wrap:!1}}),fe=new ke({props:{title:"Querying a VectorStoreIndex with prompts and LLMs",local:"querying-a-vectorstoreindex-with-prompts-and-llms",headingTag:"h3"}}),ge=new I({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmxsbXMuaHVnZ2luZ2ZhY2VfYXBpJTIwaW1wb3J0JTIwSHVnZ2luZ0ZhY2VJbmZlcmVuY2VBUEklMEElMEFsbG0lMjAlM0QlMjBIdWdnaW5nRmFjZUluZmVyZW5jZUFQSShtb2RlbF9uYW1lJTNEJTIyUXdlbiUyRlF3ZW4yLjUtQ29kZXItMzJCLUluc3RydWN0JTIyKSUwQXF1ZXJ5X2VuZ2luZSUyMCUzRCUyMGluZGV4LmFzX3F1ZXJ5X2VuZ2luZSglMEElMjAlMjAlMjAlMjBsbG0lM0RsbG0lMkMlMEElMjAlMjAlMjAlMjByZXNwb25zZV9tb2RlJTNEJTIydHJlZV9zdW1tYXJpemUlMjIlMkMlMEEpJTBBcXVlcnlfZW5naW5lLnF1ZXJ5KCUyMldoYXQlMjBpcyUyMHRoZSUyMG1lYW5pbmclMjBvZiUyMGxpZmUlM0YlMjIpJTBBJTIzJTIwVGhlJTIwbWVhbmluZyUyMG9mJTIwbGlmZSUyMGlzJTIwNDI=",highlighted:`<span class="hljs-keyword">from</span> llama_index.llms.huggingface_api <span class="hljs-keyword">import</span> HuggingFaceInferenceAPI

llm = HuggingFaceInferenceAPI(model_name=<span class="hljs-string">&quot;Qwen/Qwen2.5-Coder-32B-Instruct&quot;</span>)
query_engine = index.as_query_engine(
    llm=llm,
    response_mode=<span class="hljs-string">&quot;tree_summarize&quot;</span>,
)
query_engine.query(<span class="hljs-string">&quot;What is the meaning of life?&quot;</span>)
<span class="hljs-comment"># The meaning of life is 42</span>`,wrap:!1}}),Me=new ke({props:{title:"Response Processing",local:"response-processing",headingTag:"h3"}}),V=new Xe({props:{$$slots:{default:[Yn]},$$scope:{ctx:U}}}),xe=new ke({props:{title:"Evaluation and observability",local:"evaluation-and-observability",headingTag:"h3"}}),Ce=new I({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUuZXZhbHVhdGlvbiUyMGltcG9ydCUyMEZhaXRoZnVsbmVzc0V2YWx1YXRvciUwQSUwQXF1ZXJ5X2VuZ2luZSUyMCUzRCUyMCUyMyUyMGZyb20lMjB0aGUlMjBwcmV2aW91cyUyMHNlY3Rpb24lMEFsbG0lMjAlM0QlMjAlMjMlMjBmcm9tJTIwdGhlJTIwcHJldmlvdXMlMjBzZWN0aW9uJTBBJTBBJTIzJTIwcXVlcnklMjBpbmRleCUwQWV2YWx1YXRvciUyMCUzRCUyMEZhaXRoZnVsbmVzc0V2YWx1YXRvcihsbG0lM0RsbG0pJTBBcmVzcG9uc2UlMjAlM0QlMjBxdWVyeV9lbmdpbmUucXVlcnkoJTBBJTIwJTIwJTIwJTIwJTIyV2hhdCUyMGJhdHRsZXMlMjB0b29rJTIwcGxhY2UlMjBpbiUyME5ldyUyMFlvcmslMjBDaXR5JTIwaW4lMjB0aGUlMjBBbWVyaWNhbiUyMFJldm9sdXRpb24lM0YlMjIlMEEpJTBBZXZhbF9yZXN1bHQlMjAlM0QlMjBldmFsdWF0b3IuZXZhbHVhdGVfcmVzcG9uc2UocmVzcG9uc2UlM0RyZXNwb25zZSklMEFldmFsX3Jlc3VsdC5wYXNzaW5n",highlighted:`<span class="hljs-keyword">from</span> llama_index.core.evaluation <span class="hljs-keyword">import</span> FaithfulnessEvaluator

query_engine = <span class="hljs-comment"># from the previous section</span>
llm = <span class="hljs-comment"># from the previous section</span>

<span class="hljs-comment"># query index</span>
evaluator = FaithfulnessEvaluator(llm=llm)
response = query_engine.query(
    <span class="hljs-string">&quot;What battles took place in New York City in the American Revolution?&quot;</span>
)
eval_result = evaluator.evaluate_response(response=response)
eval_result.passing`,wrap:!1}}),je=new I({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwbGxhbWEtaW5kZXgtY2FsbGJhY2tzLWFyaXplLXBob2VuaXg=",highlighted:"pip install -U llama-index-callbacks-arize-phoenix",wrap:!1}}),Ze=new I({props:{code:"aW1wb3J0JTIwbGxhbWFfaW5kZXglMEFpbXBvcnQlMjBvcyUwQSUwQVBIT0VOSVhfQVBJX0tFWSUyMCUzRCUyMCUyMiUzQ1BIT0VOSVhfQVBJX0tFWSUzRSUyMiUwQW9zLmVudmlyb24lNUIlMjJPVEVMX0VYUE9SVEVSX09UTFBfSEVBREVSUyUyMiU1RCUyMCUzRCUyMGYlMjJhcGlfa2V5JTNEJTdCUEhPRU5JWF9BUElfS0VZJTdEJTIyJTBBbGxhbWFfaW5kZXguY29yZS5zZXRfZ2xvYmFsX2hhbmRsZXIoJTBBJTIwJTIwJTIwJTIwJTIyYXJpemVfcGhvZW5peCUyMiUyQyUwQSUyMCUyMCUyMCUyMGVuZHBvaW50JTNEJTIyaHR0cHMlM0ElMkYlMkZsbGFtYXRyYWNlLmNvbSUyRnYxJTJGdHJhY2VzJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> llama_index
<span class="hljs-keyword">import</span> os

PHOENIX_API_KEY = <span class="hljs-string">&quot;&lt;PHOENIX_API_KEY&gt;&quot;</span>
os.environ[<span class="hljs-string">&quot;OTEL_EXPORTER_OTLP_HEADERS&quot;</span>] = <span class="hljs-string">f&quot;api_key=<span class="hljs-subst">{PHOENIX_API_KEY}</span>&quot;</span>
llama_index.core.set_global_handler(
    <span class="hljs-string">&quot;arize_phoenix&quot;</span>,
    endpoint=<span class="hljs-string">&quot;https://llamatrace.com/v1/traces&quot;</span>
)`,wrap:!1}}),E=new Xe({props:{$$slots:{default:[Fn]},$$scope:{ctx:U}}}),Le=new Xn({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/en/unit2/llama-index/components.mdx"}}),{c(){c=o("meta"),m=a(),T=o("p"),p=a(),f(i.$$.fragment),v=a(),h=o("p"),h.innerHTML=d,$=a(),R=o("p"),R.innerHTML=Qt,He=a(),B=o("p"),B.textContent=Pt,Se=a(),X=o("p"),X.innerHTML=zt,Ye=a(),A=o("p"),A.textContent=Dt,Fe=a(),H=o("ol"),H.innerHTML=Kt,Ne=a(),S=o("p"),S.innerHTML=Ot,qe=a(),Y=o("p"),Y.innerHTML=en,Qe=a(),f(F.$$.fragment),Pe=a(),f(L.$$.fragment),ze=a(),N=o("p"),N.textContent=tn,De=a(),q=o("ol"),q.innerHTML=nn,Ke=a(),Q=o("p"),Q.textContent=ln,Oe=a(),f(P.$$.fragment),et=a(),z=o("p"),z.innerHTML=an,tt=a(),D=o("ol"),D.innerHTML=sn,nt=a(),f(W.$$.fragment),lt=a(),K=o("p"),K.innerHTML=on,at=a(),f(O.$$.fragment),st=a(),ee=o("p"),ee.innerHTML=rn,it=a(),te=o("p"),te.innerHTML=mn,ot=a(),ne=o("ol"),ne.innerHTML=un,rt=a(),le=o("p"),le.textContent=dn,mt=a(),f(ae.$$.fragment),ut=a(),f(se.$$.fragment),dt=a(),ie=o("p"),ie.innerHTML=cn,ct=a(),oe=o("p"),oe.innerHTML=pn,pt=a(),k=o("details"),Ge=o("summary"),Ge.textContent=hn,Yt=x(`
As introduced in the [section on the LlamaHub](llama-hub), we can install the ChromaDB vector store with the following command:

	`),f(re.$$.fragment),ht=a(),f(me.$$.fragment),ft=a(),f(G.$$.fragment),yt=a(),ue=o("p"),ue.innerHTML=fn,wt=a(),de=o("p"),de.textContent=yn,bt=a(),f(ce.$$.fragment),gt=a(),pe=o("p"),pe.innerHTML=wn,Mt=a(),he=o("p"),he.textContent=bn,vt=a(),f(fe.$$.fragment),Tt=a(),ye=o("p"),ye.textContent=gn,$t=a(),we=o("ul"),we.innerHTML=Mn,xt=a(),be=o("p"),be.textContent=vn,Jt=a(),f(ge.$$.fragment),Ut=a(),f(Me.$$.fragment),Ct=a(),ve=o("p"),ve.innerHTML=Tn,_t=a(),Te=o("ul"),Te.innerHTML=$n,jt=a(),f(V.$$.fragment),Zt=a(),$e=o("p"),$e.innerHTML=xn,It=a(),f(xe.$$.fragment),Lt=a(),Je=o("p"),Je.innerHTML=Jn,Wt=a(),Ue=o("ul"),Ue.innerHTML=Un,kt=a(),f(Ce.$$.fragment),Gt=a(),_e=o("p"),_e.innerHTML=Cn,Vt=a(),C=o("details"),Ve=o("summary"),Ve.textContent=_n,Ft=x(`
As introduced in the [section on the LlamaHub](llama-hub), we can install the LlamaTrace callback from Arize Phoenix with the following command:

	`),f(je.$$.fragment),Nt=a(),Ee=o("p"),Ee.innerHTML=jn,qt=a(),Re=o("ul"),Re.innerHTML=Zn,Et=a(),f(Ze.$$.fragment),Rt=a(),f(E.$$.fragment),Bt=a(),Ie=o("p"),Ie.innerHTML=In,Xt=a(),f(Le.$$.fragment),At=a(),Be=o("p"),this.h()},l(e){const t=Bn("svelte-u9bgzb",document.head);c=r(t,"META",{name:!0,content:!0}),t.forEach(n),m=s(e),T=r(e,"P",{}),St(T).forEach(n),p=s(e),y(i.$$.fragment,e),v=s(e),h=r(e,"P",{"data-svelte-h":!0}),u(h)!=="svelte-1vh4okn"&&(h.innerHTML=d),$=s(e),R=r(e,"P",{"data-svelte-h":!0}),u(R)!=="svelte-35rbyv"&&(R.innerHTML=Qt),He=s(e),B=r(e,"P",{"data-svelte-h":!0}),u(B)!=="svelte-1dt1sd0"&&(B.textContent=Pt),Se=s(e),X=r(e,"P",{"data-svelte-h":!0}),u(X)!=="svelte-kysd50"&&(X.innerHTML=zt),Ye=s(e),A=r(e,"P",{"data-svelte-h":!0}),u(A)!=="svelte-aqkixd"&&(A.textContent=Dt),Fe=s(e),H=r(e,"OL",{"data-svelte-h":!0}),u(H)!=="svelte-135qvuu"&&(H.innerHTML=Kt),Ne=s(e),S=r(e,"P",{"data-svelte-h":!0}),u(S)!=="svelte-mnkj36"&&(S.innerHTML=Ot),qe=s(e),Y=r(e,"P",{"data-svelte-h":!0}),u(Y)!=="svelte-ga98sq"&&(Y.innerHTML=en),Qe=s(e),y(F.$$.fragment,e),Pe=s(e),y(L.$$.fragment,e),ze=s(e),N=r(e,"P",{"data-svelte-h":!0}),u(N)!=="svelte-bhgae9"&&(N.textContent=tn),De=s(e),q=r(e,"OL",{"data-svelte-h":!0}),u(q)!=="svelte-1y6wwuy"&&(q.innerHTML=nn),Ke=s(e),Q=r(e,"P",{"data-svelte-h":!0}),u(Q)!=="svelte-12zc4us"&&(Q.textContent=ln),Oe=s(e),y(P.$$.fragment,e),et=s(e),z=r(e,"P",{"data-svelte-h":!0}),u(z)!=="svelte-1246hsd"&&(z.innerHTML=an),tt=s(e),D=r(e,"OL",{"data-svelte-h":!0}),u(D)!=="svelte-iz7p8h"&&(D.innerHTML=sn),nt=s(e),y(W.$$.fragment,e),lt=s(e),K=r(e,"P",{"data-svelte-h":!0}),u(K)!=="svelte-1c6elju"&&(K.innerHTML=on),at=s(e),y(O.$$.fragment,e),st=s(e),ee=r(e,"P",{"data-svelte-h":!0}),u(ee)!=="svelte-4bo0to"&&(ee.innerHTML=rn),it=s(e),te=r(e,"P",{"data-svelte-h":!0}),u(te)!=="svelte-1uspfck"&&(te.innerHTML=mn),ot=s(e),ne=r(e,"OL",{"data-svelte-h":!0}),u(ne)!=="svelte-1slr2bx"&&(ne.innerHTML=un),rt=s(e),le=r(e,"P",{"data-svelte-h":!0}),u(le)!=="svelte-7ysnum"&&(le.textContent=dn),mt=s(e),y(ae.$$.fragment,e),ut=s(e),y(se.$$.fragment,e),dt=s(e),ie=r(e,"P",{"data-svelte-h":!0}),u(ie)!=="svelte-1symqva"&&(ie.innerHTML=cn),ct=s(e),oe=r(e,"P",{"data-svelte-h":!0}),u(oe)!=="svelte-1j1sj1y"&&(oe.innerHTML=pn),pt=s(e),k=r(e,"DETAILS",{});var We=St(k);Ge=r(We,"SUMMARY",{"data-svelte-h":!0}),u(Ge)!=="svelte-187ducf"&&(Ge.textContent=hn),Yt=J(We,`
As introduced in the [section on the LlamaHub](llama-hub), we can install the ChromaDB vector store with the following command:

	`),y(re.$$.fragment,We),We.forEach(n),ht=s(e),y(me.$$.fragment,e),ft=s(e),y(G.$$.fragment,e),yt=s(e),ue=r(e,"P",{"data-svelte-h":!0}),u(ue)!=="svelte-axr536"&&(ue.innerHTML=fn),wt=s(e),de=r(e,"P",{"data-svelte-h":!0}),u(de)!=="svelte-s47gic"&&(de.textContent=yn),bt=s(e),y(ce.$$.fragment,e),gt=s(e),pe=r(e,"P",{"data-svelte-h":!0}),u(pe)!=="svelte-54vaw7"&&(pe.innerHTML=wn),Mt=s(e),he=r(e,"P",{"data-svelte-h":!0}),u(he)!=="svelte-1j63axa"&&(he.textContent=bn),vt=s(e),y(fe.$$.fragment,e),Tt=s(e),ye=r(e,"P",{"data-svelte-h":!0}),u(ye)!=="svelte-18ur37c"&&(ye.textContent=gn),$t=s(e),we=r(e,"UL",{"data-svelte-h":!0}),u(we)!=="svelte-d9r342"&&(we.innerHTML=Mn),xt=s(e),be=r(e,"P",{"data-svelte-h":!0}),u(be)!=="svelte-rqskw5"&&(be.textContent=vn),Jt=s(e),y(ge.$$.fragment,e),Ut=s(e),y(Me.$$.fragment,e),Ct=s(e),ve=r(e,"P",{"data-svelte-h":!0}),u(ve)!=="svelte-1j4gc2q"&&(ve.innerHTML=Tn),_t=s(e),Te=r(e,"UL",{"data-svelte-h":!0}),u(Te)!=="svelte-3mam70"&&(Te.innerHTML=$n),jt=s(e),y(V.$$.fragment,e),Zt=s(e),$e=r(e,"P",{"data-svelte-h":!0}),u($e)!=="svelte-16j3xwr"&&($e.innerHTML=xn),It=s(e),y(xe.$$.fragment,e),Lt=s(e),Je=r(e,"P",{"data-svelte-h":!0}),u(Je)!=="svelte-1m4sp8c"&&(Je.innerHTML=Jn),Wt=s(e),Ue=r(e,"UL",{"data-svelte-h":!0}),u(Ue)!=="svelte-252wdz"&&(Ue.innerHTML=Un),kt=s(e),y(Ce.$$.fragment,e),Gt=s(e),_e=r(e,"P",{"data-svelte-h":!0}),u(_e)!=="svelte-f2lt8l"&&(_e.innerHTML=Cn),Vt=s(e),C=r(e,"DETAILS",{});var _=St(C);Ve=r(_,"SUMMARY",{"data-svelte-h":!0}),u(Ve)!=="svelte-1csrw0t"&&(Ve.textContent=_n),Ft=J(_,`
As introduced in the [section on the LlamaHub](llama-hub), we can install the LlamaTrace callback from Arize Phoenix with the following command:

	`),y(je.$$.fragment,_),Nt=s(_),Ee=r(_,"P",{"data-svelte-h":!0}),u(Ee)!=="svelte-2gef6z"&&(Ee.innerHTML=jn),qt=s(_),Re=r(_,"UL",{"data-svelte-h":!0}),u(Re)!=="svelte-13n4s9w"&&(Re.innerHTML=Zn),_.forEach(n),Et=s(e),y(Ze.$$.fragment,e),Rt=s(e),y(E.$$.fragment,e),Bt=s(e),Ie=r(e,"P",{"data-svelte-h":!0}),u(Ie)!=="svelte-13rfypl"&&(Ie.innerHTML=In),Xt=s(e),y(Le.$$.fragment,e),At=s(e),Be=r(e,"P",{}),St(Be).forEach(n),this.h()},h(){j(c,"name","hf:doc:metadata"),j(c,"content",qn)},m(e,t){Z(document.head,c),l(e,m,t),l(e,T,t),l(e,p,t),w(i,e,t),l(e,v,t),l(e,h,t),l(e,$,t),l(e,R,t),l(e,He,t),l(e,B,t),l(e,Se,t),l(e,X,t),l(e,Ye,t),l(e,A,t),l(e,Fe,t),l(e,H,t),l(e,Ne,t),l(e,S,t),l(e,qe,t),l(e,Y,t),l(e,Qe,t),w(F,e,t),l(e,Pe,t),w(L,e,t),l(e,ze,t),l(e,N,t),l(e,De,t),l(e,q,t),l(e,Ke,t),l(e,Q,t),l(e,Oe,t),w(P,e,t),l(e,et,t),l(e,z,t),l(e,tt,t),l(e,D,t),l(e,nt,t),w(W,e,t),l(e,lt,t),l(e,K,t),l(e,at,t),w(O,e,t),l(e,st,t),l(e,ee,t),l(e,it,t),l(e,te,t),l(e,ot,t),l(e,ne,t),l(e,rt,t),l(e,le,t),l(e,mt,t),w(ae,e,t),l(e,ut,t),w(se,e,t),l(e,dt,t),l(e,ie,t),l(e,ct,t),l(e,oe,t),l(e,pt,t),l(e,k,t),Z(k,Ge),Z(k,Yt),w(re,k,null),l(e,ht,t),w(me,e,t),l(e,ft,t),w(G,e,t),l(e,yt,t),l(e,ue,t),l(e,wt,t),l(e,de,t),l(e,bt,t),w(ce,e,t),l(e,gt,t),l(e,pe,t),l(e,Mt,t),l(e,he,t),l(e,vt,t),w(fe,e,t),l(e,Tt,t),l(e,ye,t),l(e,$t,t),l(e,we,t),l(e,xt,t),l(e,be,t),l(e,Jt,t),w(ge,e,t),l(e,Ut,t),w(Me,e,t),l(e,Ct,t),l(e,ve,t),l(e,_t,t),l(e,Te,t),l(e,jt,t),w(V,e,t),l(e,Zt,t),l(e,$e,t),l(e,It,t),w(xe,e,t),l(e,Lt,t),l(e,Je,t),l(e,Wt,t),l(e,Ue,t),l(e,kt,t),w(Ce,e,t),l(e,Gt,t),l(e,_e,t),l(e,Vt,t),l(e,C,t),Z(C,Ve),Z(C,Ft),w(je,C,null),Z(C,Nt),Z(C,Ee),Z(C,qt),Z(C,Re),l(e,Et,t),w(Ze,e,t),l(e,Rt,t),w(E,e,t),l(e,Bt,t),l(e,Ie,t),l(e,Xt,t),w(Le,e,t),l(e,At,t),l(e,Be,t),Ht=!0},p(e,[t]){const We={};t&2&&(We.$$scope={dirty:t,ctx:e}),L.$set(We);const _={};t&2&&(_.$$scope={dirty:t,ctx:e}),W.$set(_);const Ln={};t&2&&(Ln.$$scope={dirty:t,ctx:e}),G.$set(Ln);const Wn={};t&2&&(Wn.$$scope={dirty:t,ctx:e}),V.$set(Wn);const kn={};t&2&&(kn.$$scope={dirty:t,ctx:e}),E.$set(kn)},i(e){Ht||(b(i.$$.fragment,e),b(F.$$.fragment,e),b(L.$$.fragment,e),b(P.$$.fragment,e),b(W.$$.fragment,e),b(O.$$.fragment,e),b(ae.$$.fragment,e),b(se.$$.fragment,e),b(re.$$.fragment,e),b(me.$$.fragment,e),b(G.$$.fragment,e),b(ce.$$.fragment,e),b(fe.$$.fragment,e),b(ge.$$.fragment,e),b(Me.$$.fragment,e),b(V.$$.fragment,e),b(xe.$$.fragment,e),b(Ce.$$.fragment,e),b(je.$$.fragment,e),b(Ze.$$.fragment,e),b(E.$$.fragment,e),b(Le.$$.fragment,e),Ht=!0)},o(e){g(i.$$.fragment,e),g(F.$$.fragment,e),g(L.$$.fragment,e),g(P.$$.fragment,e),g(W.$$.fragment,e),g(O.$$.fragment,e),g(ae.$$.fragment,e),g(se.$$.fragment,e),g(re.$$.fragment,e),g(me.$$.fragment,e),g(G.$$.fragment,e),g(ce.$$.fragment,e),g(fe.$$.fragment,e),g(ge.$$.fragment,e),g(Me.$$.fragment,e),g(V.$$.fragment,e),g(xe.$$.fragment,e),g(Ce.$$.fragment,e),g(je.$$.fragment,e),g(Ze.$$.fragment,e),g(E.$$.fragment,e),g(Le.$$.fragment,e),Ht=!1},d(e){e&&(n(m),n(T),n(p),n(v),n(h),n($),n(R),n(He),n(B),n(Se),n(X),n(Ye),n(A),n(Fe),n(H),n(Ne),n(S),n(qe),n(Y),n(Qe),n(Pe),n(ze),n(N),n(De),n(q),n(Ke),n(Q),n(Oe),n(et),n(z),n(tt),n(D),n(nt),n(lt),n(K),n(at),n(st),n(ee),n(it),n(te),n(ot),n(ne),n(rt),n(le),n(mt),n(ut),n(dt),n(ie),n(ct),n(oe),n(pt),n(k),n(ht),n(ft),n(yt),n(ue),n(wt),n(de),n(bt),n(gt),n(pe),n(Mt),n(he),n(vt),n(Tt),n(ye),n($t),n(we),n(xt),n(be),n(Jt),n(Ut),n(Ct),n(ve),n(_t),n(Te),n(jt),n(Zt),n($e),n(It),n(Lt),n(Je),n(Wt),n(Ue),n(kt),n(Gt),n(_e),n(Vt),n(C),n(Et),n(Rt),n(Bt),n(Ie),n(Xt),n(At),n(Be)),n(c),M(i,e),M(F,e),M(L,e),M(P,e),M(W,e),M(O,e),M(ae,e),M(se,e),M(re),M(me,e),M(G,e),M(ce,e),M(fe,e),M(ge,e),M(Me,e),M(V,e),M(xe,e),M(Ce,e),M(je),M(Ze,e),M(E,e),M(Le,e)}}}const qn='{"title":"What are components in LlamaIndex?","local":"what-are-components-in-llamaindex","sections":[{"title":"Creating a RAG pipeline using components","local":"creating-a-rag-pipeline-using-components","sections":[{"title":"Loading and embedding documents","local":"loading-and-embedding-documents","sections":[],"depth":3},{"title":"Storing and indexing documents","local":"storing-and-indexing-documents","sections":[],"depth":3},{"title":"Querying a VectorStoreIndex with prompts and LLMs","local":"querying-a-vectorstoreindex-with-prompts-and-llms","sections":[],"depth":3},{"title":"Response Processing","local":"response-processing","sections":[],"depth":3},{"title":"Evaluation and observability","local":"evaluation-and-observability","sections":[],"depth":3}],"depth":2}],"depth":1}';function Qn(U){return Vn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tl extends En{constructor(c){super(),Rn(this,c,Qn,Nn,Gn,{})}}export{tl as component};
