Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Agentic RAG","local":"agentic-rag","sections":[{"title":"Introduction to Retrieval-Augmented Generation (RAG)","local":"introduction-to-retrieval-augmented-generation-rag","sections":[{"title":"Why Use RAG?","local":"why-use-rag","sections":[],"depth":3},{"title":"Limitations of Traditional RAG","local":"limitations-of-traditional-rag","sections":[],"depth":3}],"depth":2},{"title":"Agentic RAG: A More Powerful Approach","local":"agentic-rag-a-more-powerful-approach","sections":[{"title":"Key Benefits of Agentic RAG","local":"key-benefits-of-agentic-rag","sections":[],"depth":3}],"depth":2},{"title":"Building an Agentic RAG System","local":"building-an-agentic-rag-system","sections":[{"title":"Step 1: Install Required Dependencies","local":"step-1-install-required-dependencies","sections":[],"depth":3},{"title":"Step 2: Prepare the Knowledge Base","local":"step-2-prepare-the-knowledge-base","sections":[],"depth":3},{"title":"Step 3: Create a Retriever Tool","local":"step-3-create-a-retriever-tool","sections":[],"depth":3},{"title":"Step 4: Create an Advanced Retrieval Agent","local":"step-4-create-an-advanced-retrieval-agent","sections":[],"depth":3},{"title":"Step 5: Run the Agent to Answer Questions","local":"step-5-run-the-agent-to-answer-questions","sections":[],"depth":3}],"depth":2},{"title":"Practical Applications of Agentic RAG","local":"practical-applications-of-agentic-rag","sections":[],"depth":2},{"title":"Conclusion","local":"conclusion","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/smolagents/pr_2321/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/entry/start.fe75d00e.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/scheduler.545a7209.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/singletons.d667ceb3.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/index.1d3c4622.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/paths.cd5ec750.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/entry/app.bd903b71.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/preload-helper.bbc9581e.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/index.5e5f0156.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/nodes/0.119a3025.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/nodes/7.ac9b1edc.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.b21a3620.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/CodeBlock.f0f69955.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/en/_app/immutable/chunks/DocNotebookDropdown.017c1aef.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Agentic RAG","local":"agentic-rag","sections":[{"title":"Introduction to Retrieval-Augmented Generation (RAG)","local":"introduction-to-retrieval-augmented-generation-rag","sections":[{"title":"Why Use RAG?","local":"why-use-rag","sections":[],"depth":3},{"title":"Limitations of Traditional RAG","local":"limitations-of-traditional-rag","sections":[],"depth":3}],"depth":2},{"title":"Agentic RAG: A More Powerful Approach","local":"agentic-rag-a-more-powerful-approach","sections":[{"title":"Key Benefits of Agentic RAG","local":"key-benefits-of-agentic-rag","sections":[],"depth":3}],"depth":2},{"title":"Building an Agentic RAG System","local":"building-an-agentic-rag-system","sections":[{"title":"Step 1: Install Required Dependencies","local":"step-1-install-required-dependencies","sections":[],"depth":3},{"title":"Step 2: Prepare the Knowledge Base","local":"step-2-prepare-the-knowledge-base","sections":[],"depth":3},{"title":"Step 3: Create a Retriever Tool","local":"step-3-create-a-retriever-tool","sections":[],"depth":3},{"title":"Step 4: Create an Advanced Retrieval Agent","local":"step-4-create-an-advanced-retrieval-agent","sections":[],"depth":3},{"title":"Step 5: Run the Agent to Answer Questions","local":"step-5-run-the-agent-to-answer-questions","sections":[],"depth":3}],"depth":2},{"title":"Practical Applications of Agentic RAG","local":"practical-applications-of-agentic-rag","sections":[],"depth":2},{"title":"Conclusion","local":"conclusion","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <div class="flex space-x-1 " style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"> </button> </div> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"> </button> </div></div> <h1 class="relative group"><a id="agentic-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#agentic-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Agentic RAG</span></h1> <h2 class="relative group"><a id="introduction-to-retrieval-augmented-generation-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#introduction-to-retrieval-augmented-generation-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Introduction to Retrieval-Augmented Generation (RAG)</span></h2> <p data-svelte-h="svelte-ahsalp">Retrieval-Augmented Generation (RAG) combines the power of large language models with external knowledge retrieval to produce more accurate, factual, and contextually relevant responses. At its core, RAG is about “using an LLM to answer a user query, but basing the answer on information retrieved from a knowledge base.”</p> <h3 class="relative group"><a id="why-use-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#why-use-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Why Use RAG?</span></h3> <p data-svelte-h="svelte-3b2p9t">RAG offers several significant advantages over using vanilla or fine-tuned LLMs:</p> <ol data-svelte-h="svelte-s9vwtj"><li><strong>Factual Grounding</strong>: Reduces hallucinations by anchoring responses in retrieved facts</li> <li><strong>Domain Specialization</strong>: Provides domain-specific knowledge without model retraining</li> <li><strong>Knowledge Recency</strong>: Allows access to information beyond the model’s training cutoff</li> <li><strong>Transparency</strong>: Enables citation of sources for generated content</li> <li><strong>Control</strong>: Offers fine-grained control over what information the model can access</li></ol> <h3 class="relative group"><a id="limitations-of-traditional-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#limitations-of-traditional-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Limitations of Traditional RAG</span></h3> <p data-svelte-h="svelte-5ohm8g">Despite its benefits, traditional RAG approaches face several challenges:</p> <ul data-svelte-h="svelte-1b6u5vg"><li><strong>Single Retrieval Step</strong>: If the initial retrieval results are poor, the final generation will suffer</li> <li><strong>Query-Document Mismatch</strong>: User queries (often questions) may not match well with documents containing answers (often statements)</li> <li><strong>Limited Reasoning</strong>: Simple RAG pipelines don’t allow for multi-step reasoning or query refinement</li> <li><strong>Context Window Constraints</strong>: Retrieved documents must fit within the model’s context window</li></ul> <h2 class="relative group"><a id="agentic-rag-a-more-powerful-approach" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#agentic-rag-a-more-powerful-approach"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Agentic RAG: A More Powerful Approach</span></h2> <p data-svelte-h="svelte-nkypap">We can overcome these limitations by implementing an <strong>Agentic RAG</strong> system - essentially an agent equipped with retrieval capabilities. This approach transforms RAG from a rigid pipeline into an interactive, reasoning-driven process.</p> <h3 class="relative group"><a id="key-benefits-of-agentic-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#key-benefits-of-agentic-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Key Benefits of Agentic RAG</span></h3> <p data-svelte-h="svelte-106qzhl">An agent with retrieval tools can:</p> <ol data-svelte-h="svelte-17ov5nb"><li>✅ <strong>Formulate optimized queries</strong>: The agent can transform user questions into retrieval-friendly queries</li> <li>✅ <strong>Perform multiple retrievals</strong>: The agent can retrieve information iteratively as needed</li> <li>✅ <strong>Reason over retrieved content</strong>: The agent can analyze, synthesize, and draw conclusions from multiple sources</li> <li>✅ <strong>Self-critique and refine</strong>: The agent can evaluate retrieval results and adjust its approach</li></ol> <p data-svelte-h="svelte-1vth8dz">This approach naturally implements advanced RAG techniques:</p> <ul data-svelte-h="svelte-1kmp0ag"><li><strong>Hypothetical Document Embedding (HyDE)</strong>: Instead of using the user query directly, the agent formulates retrieval-optimized queries (<a href="https://huggingface.co/papers/2212.10496" rel="nofollow">paper reference</a>)</li> <li><strong>Self-Query Refinement</strong>: The agent can analyze initial results and perform follow-up retrievals with refined queries (<a href="https://docs.llamaindex.ai/en/stable/examples/evaluation/RetryQuery/" rel="nofollow">technique reference</a>)</li></ul> <h2 class="relative group"><a id="building-an-agentic-rag-system" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#building-an-agentic-rag-system"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Building an Agentic RAG System</span></h2> <p data-svelte-h="svelte-ebtqsa">Let’s build a complete Agentic RAG system step by step. We’ll create an agent that can answer questions about the Hugging Face Transformers library by retrieving information from its documentation.</p> <p data-svelte-h="svelte-a2onz5">You can follow along with the code snippets below, or check out the full example in the smolagents GitHub repository: <a href="https://github.com/huggingface/smolagents/blob/main/examples/rag.py" rel="nofollow">examples/rag.py</a>.</p> <h3 class="relative group"><a id="step-1-install-required-dependencies" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-1-install-required-dependencies"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 1: Install Required Dependencies</span></h3> <p data-svelte-h="svelte-1yz8wyl">First, we need to install the necessary packages:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->pip install smolagents pandas langchain langchain-community sentence-transformers datasets python-dotenv rank_bm25 --upgrade<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-io6cbu">If you plan to use Hugging Face’s Inference API, you’ll need to set up your API token:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-comment"># Load environment variables (including HF_TOKEN)</span> | |
| <span class="hljs-keyword">from</span> dotenv <span class="hljs-keyword">import</span> load_dotenv | |
| load_dotenv()<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="step-2-prepare-the-knowledge-base" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-2-prepare-the-knowledge-base"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 2: Prepare the Knowledge Base</span></h3> <p data-svelte-h="svelte-1r0dacz">We’ll use a dataset containing Hugging Face documentation and prepare it for retrieval:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> datasets | |
| <span class="hljs-keyword">from</span> langchain.docstore.document <span class="hljs-keyword">import</span> Document | |
| <span class="hljs-keyword">from</span> langchain.text_splitter <span class="hljs-keyword">import</span> RecursiveCharacterTextSplitter | |
| <span class="hljs-keyword">from</span> langchain_community.retrievers <span class="hljs-keyword">import</span> BM25Retriever | |
| <span class="hljs-comment"># Load the Hugging Face documentation dataset</span> | |
| knowledge_base = datasets.load_dataset(<span class="hljs-string">"m-ric/huggingface_doc"</span>, split=<span class="hljs-string">"train"</span>) | |
| <span class="hljs-comment"># Filter to include only Transformers documentation</span> | |
| knowledge_base = knowledge_base.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> row: row[<span class="hljs-string">"source"</span>].startswith(<span class="hljs-string">"huggingface/transformers"</span>)) | |
| <span class="hljs-comment"># Convert dataset entries to Document objects with metadata</span> | |
| source_docs = [ | |
| Document(page_content=doc[<span class="hljs-string">"text"</span>], metadata={<span class="hljs-string">"source"</span>: doc[<span class="hljs-string">"source"</span>].split(<span class="hljs-string">"/"</span>)[<span class="hljs-number">1</span>]}) | |
| <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> knowledge_base | |
| ] | |
| <span class="hljs-comment"># Split documents into smaller chunks for better retrieval</span> | |
| text_splitter = RecursiveCharacterTextSplitter( | |
| chunk_size=<span class="hljs-number">500</span>, <span class="hljs-comment"># Characters per chunk</span> | |
| chunk_overlap=<span class="hljs-number">50</span>, <span class="hljs-comment"># Overlap between chunks to maintain context</span> | |
| add_start_index=<span class="hljs-literal">True</span>, | |
| strip_whitespace=<span class="hljs-literal">True</span>, | |
| separators=[<span class="hljs-string">"\n\n"</span>, <span class="hljs-string">"\n"</span>, <span class="hljs-string">"."</span>, <span class="hljs-string">" "</span>, <span class="hljs-string">""</span>], <span class="hljs-comment"># Priority order for splitting</span> | |
| ) | |
| docs_processed = text_splitter.split_documents(source_docs) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"Knowledge base prepared with <span class="hljs-subst">{<span class="hljs-built_in">len</span>(docs_processed)}</span> document chunks"</span>)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="step-3-create-a-retriever-tool" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-3-create-a-retriever-tool"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 3: Create a Retriever Tool</span></h3> <p data-svelte-h="svelte-16ovxir">Now we’ll create a custom tool that our agent can use to retrieve information from the knowledge base:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> Tool | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">RetrieverTool</span>(<span class="hljs-title class_ inherited__">Tool</span>): | |
| name = <span class="hljs-string">"retriever"</span> | |
| description = <span class="hljs-string">"Uses semantic search to retrieve the parts of transformers documentation that could be most relevant to answer your query."</span> | |
| inputs = { | |
| <span class="hljs-string">"query"</span>: { | |
| <span class="hljs-string">"type"</span>: <span class="hljs-string">"string"</span>, | |
| <span class="hljs-string">"description"</span>: <span class="hljs-string">"The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question."</span>, | |
| } | |
| } | |
| output_type = <span class="hljs-string">"string"</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, docs, **kwargs</span>): | |
| <span class="hljs-built_in">super</span>().__init__(**kwargs) | |
| <span class="hljs-comment"># Initialize the retriever with our processed documents</span> | |
| self.retriever = BM25Retriever.from_documents( | |
| docs, k=<span class="hljs-number">10</span> <span class="hljs-comment"># Return top 10 most relevant documents</span> | |
| ) | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, query: <span class="hljs-built_in">str</span></span>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">"""Execute the retrieval based on the provided query."""</span> | |
| <span class="hljs-keyword">assert</span> <span class="hljs-built_in">isinstance</span>(query, <span class="hljs-built_in">str</span>), <span class="hljs-string">"Your search query must be a string"</span> | |
| <span class="hljs-comment"># Retrieve relevant documents</span> | |
| docs = self.retriever.invoke(query) | |
| <span class="hljs-comment"># Format the retrieved documents for readability</span> | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">"\nRetrieved documents:\n"</span> + <span class="hljs-string">""</span>.join( | |
| [ | |
| <span class="hljs-string">f"\n\n===== Document <span class="hljs-subst">{<span class="hljs-built_in">str</span>(i)}</span> =====\n"</span> + doc.page_content | |
| <span class="hljs-keyword">for</span> i, doc <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(docs) | |
| ] | |
| ) | |
| <span class="hljs-comment"># Initialize our retriever tool with the processed documents</span> | |
| retriever_tool = RetrieverTool(docs_processed)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1j7z97m"><p>We’re using BM25, a lexical retrieval method, for simplicity and speed. For production systems, you might want to use semantic search with embeddings for better retrieval quality. Check the <a href="https://huggingface.co/spaces/mteb/leaderboard" rel="nofollow">MTEB Leaderboard</a> for high-quality embedding models.</p></blockquote> <h3 class="relative group"><a id="step-4-create-an-advanced-retrieval-agent" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-4-create-an-advanced-retrieval-agent"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 4: Create an Advanced Retrieval Agent</span></h3> <p data-svelte-h="svelte-uyg5h9">Now we’ll create an agent that can use our retriever tool to answer questions:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> InferenceClientModel, CodeAgent | |
| <span class="hljs-comment"># Initialize the agent with our retriever tool</span> | |
| agent = CodeAgent( | |
| tools=[retriever_tool], <span class="hljs-comment"># List of tools available to the agent</span> | |
| model=InferenceClientModel(), <span class="hljs-comment"># Default model "Qwen/Qwen3-Next-80B-A3B-Thinking"</span> | |
| max_steps=<span class="hljs-number">4</span>, <span class="hljs-comment"># Limit the number of reasoning steps</span> | |
| verbosity_level=<span class="hljs-number">2</span>, <span class="hljs-comment"># Show detailed agent reasoning</span> | |
| ) | |
| <span class="hljs-comment"># To use a specific model, you can specify it like this:</span> | |
| <span class="hljs-comment"># model=InferenceClientModel(model_id="meta-llama/Llama-3.3-70B-Instruct")</span><!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1lti5bi"><p>Inference Providers give access to hundreds of models, powered by serverless inference partners. A list of supported providers can be found <a href="https://huggingface.co/docs/inference-providers/index" rel="nofollow">here</a>.</p></blockquote> <h3 class="relative group"><a id="step-5-run-the-agent-to-answer-questions" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#step-5-run-the-agent-to-answer-questions"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 5: Run the Agent to Answer Questions</span></h3> <p data-svelte-h="svelte-1cnhgyu">Let’s use our agent to answer a question about Transformers:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-comment"># Ask a question that requires retrieving information</span> | |
| question = <span class="hljs-string">"For a transformers model training, which is slower, the forward or the backward pass?"</span> | |
| <span class="hljs-comment"># Run the agent to get an answer</span> | |
| agent_output = agent.run(question) | |
| <span class="hljs-comment"># Display the final answer</span> | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"\nFinal answer:"</span>) | |
| <span class="hljs-built_in">print</span>(agent_output)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="practical-applications-of-agentic-rag" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#practical-applications-of-agentic-rag"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Practical Applications of Agentic RAG</span></h2> <p data-svelte-h="svelte-1vnmlwn">Agentic RAG systems can be applied to various use cases:</p> <ol data-svelte-h="svelte-u8fd9x"><li><strong>Technical Documentation Assistance</strong>: Help users navigate complex technical documentation</li> <li><strong>Research Paper Analysis</strong>: Extract and synthesize information from scientific papers</li> <li><strong>Legal Document Review</strong>: Find relevant precedents and clauses in legal documents</li> <li><strong>Customer Support</strong>: Answer questions based on product documentation and knowledge bases</li> <li><strong>Educational Tutoring</strong>: Provide explanations based on textbooks and learning materials</li></ol> <h2 class="relative group"><a id="conclusion" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#conclusion"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Conclusion</span></h2> <p data-svelte-h="svelte-1nscnr8">Agentic RAG represents a significant advancement over traditional RAG pipelines. By combining the reasoning capabilities of LLM agents with the factual grounding of retrieval systems, we can build more powerful, flexible, and accurate information systems.</p> <p data-svelte-h="svelte-18cofwx">The approach we’ve demonstrated:</p> <ul data-svelte-h="svelte-12ngelm"><li>Overcomes the limitations of single-step retrieval</li> <li>Enables more natural interactions with knowledge bases</li> <li>Provides a framework for continuous improvement through self-critique and query refinement</li></ul> <p data-svelte-h="svelte-izrxrg">As you build your own Agentic RAG systems, consider experimenting with different retrieval methods, agent architectures, and knowledge sources to find the optimal configuration for your specific use case.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/smolagents/blob/main/docs/source/en/examples/rag.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_t2vx7 = { | |
| assets: "/docs/smolagents/pr_2321/en", | |
| base: "/docs/smolagents/pr_2321/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/smolagents/pr_2321/en/_app/immutable/entry/start.fe75d00e.js"), | |
| import("/docs/smolagents/pr_2321/en/_app/immutable/entry/app.bd903b71.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 7], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 47.3 kB
- Xet hash:
- 555e111feb095c338ba5de53a7d85788ec70e7c2d77b236a293b20326839de68
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.