Retrieval Augmented Generation (RAG) allows  you to improve AI-generated responses by adding relevant information from outside sources. 

But, what if you want your system to do more than just respond? What if you need it to work independently, make choices, and actively engage with your data? This is where a more advanced version of RAG comes in, adding a new level of independent action to your automated processes.

This beginner-friendly webinar delves into the world of Agentic RAG. We'll walk through a practical example and build an AI application that demonstrates the power and flexibility of RAG.

Understanding the Basics: What is RAG?

Before exploring the agentic aspects, it's important to understand the fundamental RAG technique. RAG stands for Retrieval Augmented Generation, a two-part strategy that enhances the capabilities of LLMs.

Retrieval: Gathering Context for Intelligent Responses

The retrieval phase focuses on gathering relevant information from external data sources to provide context for the AI's response. This involves:

  1. Identifying a Query: The user initiates the process with a question, task, or prompt.
  2. Accessing Data Sources: The AI utilizes various data sources to gather context relevant to the query. These sources can include:
  • Documents: Files uploaded to the AI application allow it to access specific knowledge bases.
  • Websites: Scraping web pages pulls in real-time information from the internet.
  • Databases: Tapping into structured data repositories to access specific facts or figures.
  • APIs: Connecting to external services to access information unavailable through other sources.
  1. Selecting Relevant Information: The AI analyzes the data sources and retrieves the most relevant chunks of information based on the user's query.

Augmented Generation: Crafting Enhanced Responses

Once the relevant context is gathered, the augmented generation phase kicks in. The AI utilizes the retrieved information to create a more informed and accurate response. This process elevates the LLM's capabilities beyond generic answers, allowing it to provide:

  • Specific and Contextualized Responses: The response is tailored to the user's query by incorporating specific information from the retrieved data.
  • Enhanced Accuracy: The risk of hallucinations (generating factually incorrect or irrelevant information) is minimized by grounding the response in real data.

Introducing Agentic RAG: Giving AI More Agency

Agentic RAG builds on the foundation of RAG, and elevates AI workflows with more agency. This means empowering the AI to act autonomously, make decisions, and dynamically interact with data to achieve specific goals on behalf of the user.

Key Components of Agentic RAG

  1. Additional Query Intelligence: Agentic RAG goes beyond simply answering the initial query. It analyzes the query to understand its intent and may formulate additional queries to gather more nuanced information.
  2. Autonomous Actions: Agentic AI can perform actions on behalf of the user, such as:
  • Scheduling meetings.
  • Booking appointments.
  • Sending emails.
  • Updating data in external systems.
  1. Decision Making: Agentic RAG enables AI to make decisions based on the information it gathers and the analysis it performs. These decisions can drive subsequent actions within the workflow, leading to dynamic and personalized user experiences.

Building an Agentic RAG Application: A Practical Example

To illustrate the power of Agentic RAG, let's walk through a practical example. The AI application built within MindStudio acts as a sales assistant and is equipped with the following capabilities:

  • Generating Sales Collateral: The AI can generate personalized sales materials based on product information and customer details.
  • Answering Product-Related Questions: The AI can access product documentation and answer user queries with high accuracy.

Setting Up the Workflow

The process starts by creating a simple menu-based workflow to guide the user through the application's functionalities. Below is a breakdown of the sales assistant workflow structure:

Workflows

  • Menu Workflow:some text
    • Start: The starting point of the workflow.
    • Menu: Presents the user with two options: "Create Collaterals" and "Ask Docs."
    • Jump Blocks: Two jump blocks, one for each menu option, redirecting the user to the corresponding workflow.
  • GenerateCollaterals Workflow:some text
    • Product Input: Allows the user to upload a document containing information about the product.
    • Lead Input: Allows the user to upload a document containing information about the new client.
    • Generate Text: Generates sales collateral based on the uploaded product and lead information.
  • AskDocs Workflow:some text
    • Docs Data Source: A data source containing product documentation.
    • User Input: Allows the user to ask a question about the product.
    • Query Data Source: Queries the "Docs" data source with the user's question.
    • Generate Text: Generates an answer based on the retrieved context from the "Docs" data source.

Implementing Simple RAG

The "AskDocs" workflow demonstrates a basic implementation of RAG. The user's question acts as the query, prompting the AI to retrieve relevant information from the "Docs" data source. The AI then utilizes this context to generate a response.

Introducing Agentic Elements

To elevate this application with Agentic RAG, enhance the "AskDocs" workflow with the following elements:

1. Query Interpretation: Enhancing Query Intelligence

Instead of directly querying the "Docs" data source with the user's original question, you can add a step to interpret the query and formulate additional questions. This enhances the AI's understanding of the user's intent and enables it to provide more comprehensive answers.

  • Generate Text (Analysis): Insert a "Generate Text" block after the "User Input" block. This block will analyze the user's query and generate:some text
    • Three additional questions: These questions will expand on the original query, seeking more specific information from the documentation.
    • Key terms to search for: These terms will be used to perform a Google search if the initial query and subsequent analysis don't provide a satisfactory answer.
  • Save to Variable (response_analysis): Save the output of the "Generate Text (Analysis)" block to a variable called response_analysis.

2. Decision Making: Guiding the Workflow Flow

You can also incorporate a logic block to analyze the AI's response and make decisions based on whether the initial query was answered sufficiently.

  • Logic Block: Insert a "Logic" block after the "Generate Text (Analysis)" block.Add two conditions within the logic block:some text
    • Case 1: Evaluates whether the question has been answered based on the response_analysis variable. If yes, the workflow continues to the "Display Content" block.
  • Case 2: Evaluates whether the question has not been answered based on the response_analysis variable. If yes, the workflow proceeds to the "Google Search" block.

3. Autonomous Actions: Performing a Google Search

If the initial RAG process doesn't provide a satisfactory answer, you can add a step instructing the  AI toautonomously perform a Google search to gather additional context.

  • Google Search: Insert a "Google Search" block after the "Logic" block.
  • Search Query: Configure the "Search Query" field to use the original user query ({{query}}) and the key terms generated in the "Generate Text (Analysis)" block.
  • Save to Variable (google_result):  Save the top URL returned by the Google search to a variable called google_result.
  • Scrape URL: Insert a "Scrape URL" block after the "Google Search" block. Configure the "URL" field to use the google_result variable. This will scrape the content of the webpage associated with the retrieved URL.
  • Save to Variable (url_scrape): Save the scraped content to a variable called url_scrape.

4. Combining Context and Generating a Final Response

After the Google search, the AI will combine all the available context and generate a final response.

  • Generate Text (Final): Insert a "Generate Text" block after the "Scrape URL" block.
  • Prompt: Include the following elements in the prompt:some text
    • {{product_info}}: Information about the product from the "Product Input" block.
    • {{lead_info}}: Information about the lead from the "Lead Input" block.
    • {{query}}: The original user question.
    • {{query_result}}: The initial response generated using RAG.
    • {{url_scrape}}: The scraped content from the Google search.
  • Prompt Structure:
  •      # About our product
    {{product_info}}

    # About the customer
    {{lead_info}}

    # Customer Question:
    Answer the following question:
    {{query}}

    This was the response:
    {{query_result}}

    # Additional Info
    We scraped the web to find the following info:
    {{url_scrape}}

    Answer the original question and try to tie it back to our product if it makes sense to do so.
    Respond using markdown formatting.‍
  • Save to Variable (query_response2): Save the generated response to a variable called query_response2.
  • Display Content: Connect both the "Generate Text" block (for the initial RAG response) and the "Generate Text (Final)" block to a "Display Content" block. Configure this block to display the query_response2 variable.

Agentic Decision Making: Determining Question Relevance

The logic block in this workflow allows the AI to make a decision based on its analysis of the initial response. This is a crucial element of Agentic RAG, as it empowers the AI to decide whether further action is required to adequately answer the user's question.

Benefits of Agentic RAG

By incorporating agentic elements into your RAG workflows, you can unlock several key benefits:

  • Saves Time: Agentic RAG allows you to automate tasks and decisions, freeing valuable time and resources. This efficiency translates into cost savings and increased productivity.
  • Higher Accuracy, Less Hallucinations: By grounding responses in real data and allowing the AI to analyze and refine its answers, you can achieve higher accuracy and reduce the risk of hallucinations.
  • More Automated Tasks and Decisions: With Agentic RAG, you can automate more complex tasks and decisions, such as data analysis, research, and information retrieval. This allows the AI to handle more intricate processes and provide more sophisticated solutions.

When NOT to Use RAG/Agentic RAG

While RAG and Agentic RAG offer significant advantages, they might not be the best fit in some situations. Consider these scenarios:

  • Low-Quality Data: If your data source is incomplete, inaccurate, or poorly structured, utilizing RAG might lead to unreliable responses. Ensure the quality and comprehensiveness of your data before implementing RAG.
  • Required Context Fits into the AI Prompt: If the necessary context is concise enough to fit within the AI prompt, directly including it might be a more straightforward solution than implementing RAG.
  • Workflow Process is Unclear:  If the workflow process is poorly defined or ambiguous, introducing agentic elements might lead to unpredictable and undesirable results. Carefully plan and define your workflow steps before introducing agentic decision-making.

Agentic RAG allows you to create more intelligent, autonomous, and efficient workflows. By understanding its core principles and the considerations for implementation, you can leverage this technology to create innovative applications that solve real-world problems with MindStudio.

Register Now ->