---
updatedAt: 2026-07-29T17:35:29.000Z
agentTools:
  projectIndex: https://ai-studio-docs.quiq.com/llms.txt
---

# Lesson 3: Retrieval Augmented Generation

## Overview

This assistant builds on Lesson 2 by building out a basic RAG flow. RAG (Retrieval Augmented Generation) is where we retrieve information to include in our prompts so that generative responses can be accurate and up-to-date. RAG is one of the most fundamental techniques to leverage AI effectively and safely.

Now if the user's request is in scope and the `next-best-action` prompt determined that finding information was the next best step, we search a knowledge base for information and include that information in a new generative prompt, `generate-answer`, to generate a response to send to the user.

<Callout icon="⛰️" theme="default">
  ### This assistant is grounded in [QuiqSilver Bikes](https://quiqsilvermountain.com/) - a fictitious retailer of Cannondale bikes.

  The AI assistant on the QuiqSilver website uses flows & techniques that are similar to what's covered in the Academy lessons.

  **This assistant is for educational purposes only, and is not to be representative of a fully hardened production experience.**

  It lacks the necessary guardrails to ensure that responses are accurate and on-brand. A more robust assistant can be seen in Lesson 4.
</Callout>

## What You'll Learn

This lesson is designed to help you incorporate RAG in AI Studio. If you haven't completed [Lesson 2](https://ai-studio-docs.quiq.com/docs/prompts-prompt-chaining-lesson), please complete that first.

In this lesson you'll learn how to:

* Understand the [Search](https://ai-studio-docs.quiq.com/docs/behaviors#search)  behavior
* Understand how to use Search results to generate a response to the customer
* Use the resource search tool
* Create a prompt from scratch

In this section you'll find a video and a written guide you can follow along with. You can view walkthroughs of all the available lessons [here](https://ai-studio-docs.quiq.com/docs/ai-studio-academy).

<Callout icon="📘" theme="info">
  For help getting started and creating a template, refer to the [intro guide](https://ai-studio-docs.quiq.com/docs/ai-studio-academy#using-the-templates).
</Callout>

<HTMLBlock>{`
<div style="padding:49.79% 0 0 0;position:relative;"><iframe src="https://player.vimeo.com/video/962615962?h=27ab175908&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture; clipboard-write" style="position:absolute;top:0;left:0;width:100%;height:100%;" title="Lesson 3 updated prompt ui"></iframe></div><script src="https://player.vimeo.com/api/player.js"></script>
`}</HTMLBlock>

## Creating the Template

Select **Lesson 3: Retrieval Augmented Generation** to get started:

<Image src="https://files.readme.io/89e1d9e-image.png" align="center" width="80% " />

## Understanding Search & Using Resource Search

The assistant in lesson 3 builds off of the assistant in lesson 2, and it now has the ability to answer questions from a sample QuiqSilver Bikes knowledge base that has been added as a dataset in [AI Resources](https://ai-studio-docs.quiq.com/edit/ai-resources).

Within the Flow Editor you should notice a **Search** behavior. The **Search** behavior will run when a customer interacts with your assistant. However, instead of chatting with the assistant directly, you can also open up the **Tools** panel and select **[Resource Search](https://ai-studio-docs.quiq.com/docs/tools-panel#resource-search)** to explore the dataset:

<Image src="https://files.readme.io/f888dfc-image.png" align="center" width="90% " />

<Callout icon="📘" theme="info">
  You can control whether your panels open in split view, like in the screenshot above, or one at a time, within the **Configuration** panel under **Panels >** **Panel Behavior**. [Learn more](https://ai-studio-docs.quiq.com/docs/configuration-panel#panels)
</Callout>

To interact directly with the dataset, enter the search phrase  "What payment options do you offer?" and see what gets returned:

<Image src="https://files.readme.io/c38f932-image.png" align="center" width="80% " />

You can click into each result to view the field data available for use in your prompts:

<Image src="https://files.readme.io/455ffd7-image.png" align="center" width="80% " />

Congratulations 👏 you now know how to use the **Resource Search** tool to query your documents!

## Tracing your Conversation

Send the same message through the Chat panel now, and open up the **Debug Workbench** from the Chat panel and select "What payment options do you offer?", select the **Search** behavior, and you can view the Search Results, as well as the Search Phrase used:

![](https://files.readme.io/74ab2c0-image.png)

Next, click into the `generate-answer` prompt to  view the prompt that helped generate the answer:

<Image src="https://files.readme.io/93b6b8a-image.png" align="center" width="80% " />

## Incorporating Search Results into a Prompt

The **Event Details** view for our `generate-answer` prompt contains all of the actual search results used to generate the answer, but let's take a look at how those results get integrated into the prompt itself.

Scroll up to the top of **Event Details** and select the prompt, or use `ctrl + space` to open up the search tool and search for the `generate-answer` prompt directly [learn more](https://ai-studio-docs.quiq.com/docs/assistant-basics#search):

<Image src="https://files.readme.io/622e79d-image.png" align="center" width="75% " />

You will then be taken into the `generate-answer` prompt editor view, where you can see that `Search Results` is an embeddable block that has been added after the user's `Conversation History`, and their `searchPhrase`:&#x20;

<Image src="https://files.readme.io/cb86f739a322d6e7e60dd9b9c711a612c8217b2fd62c040dcbf374d1f53b535a-image.png" align="center" width="80%" />

Click on the `Search Results` block in the prompt to see how it's configured:

<Image src="https://files.readme.io/cae4848-image.png" align="center" width="55% " />

Here, you can see that there's a [Search Resource](https://ai-studio-docs.quiq.com/docs/ai-resources#search-resources---basics) selected, as well as format that the results will follow. You can see the format mirrored in the event details for the`generate-answer` prompt you were just looking at:

<Image src="https://files.readme.io/c32eddd-image.png" align="center" width="80% " />

Congratulations 👏 you now understand how to insert Search Results into a prompt to help guide your assistant's answers!

## Handling Sensitive Messages

Send in another phrase, this time do something like:

> i just got in an accident and broke my arm,  wonder if I should see a doc.  Also my bike is damaged, is it under warranty?

Here, we're asking a two part question, one of which is the sort of question our assistant should answer ("Is \[my bike] under warranty?") the other is the sort of phrase we almost certainly don't want to answer ("i just got in an accident and broke my arm,  wonder if I should see a doc.")

<Callout icon="📘" theme="info">
  ### Alternate Messages & Classification Variance

  You can imagine the above phrase is on the cusp of an being `in-scope` or `out-of-scope`, or that the `next-action` prompt may decide the next step should be `escalate`depending on the model you're using, the conversation history, or other factors.

  Play around with a range of phrases, and examine the debug workbench, to get an understanding of where the line is.

  You can try a range of variations on this phrase, or ones like it, to see how it classifies them. Below are some additional phrases you can try:

  _"i just got in an accident because my handlebars slipped, and my arm really hurts, but i don't know if i should see a doctor.  Also my bike is damaged, is it under warranty?"_

  _"i just got in an accident and broke my arm, also my bike is damaged, is it under warranty?"_
</Callout>

<br />

With our current, somewhat limited guardrails in place in the **Examine Customer Message** behavior, our assistant will attempt to generate a response:

<Image src="https://files.readme.io/5dbb7a889913efebda6321821209ce26b487706b46a357571620b15bc5ed5580-image.png" align="center" width="60% " />

<br />

If you examine the `message-in-scope` prompt in the **Debug Workbench**, you can see the assistant has labeled this as in scope, meaning the assistant is going to then move on and generate an answer to the query:

<Image src="https://files.readme.io/57e4de9-image.png" align="center" width="50% " />

### Building a sensitive message prompt

Ideally, we don't want our QuiqSilver Mountain assistant generating answers to potentially sensitive question around whether or not a user needs to visit a doctor, so let's go ahead and create a prompt in our **Examine Customer Message** behavior to identify these types of inquiries.

Next, we're going to add in a new prompt to our **Examine Customer Message** behavior that we've been using to control the flow of our conversations. Select the behavior and click the **Add Prompt** button:

<Image src="https://files.readme.io/685e0802ed599f45c054a4f541e2ac0f839733360de592cd6e297e4d25fe66da-image.png" align="center" width="90%" />

Name your prompt `message-sensitive`, then press return:

<Image src="https://files.readme.io/4a9b319174ae3de10dc8861699b00bd0eca4d205c5b4a8c015698ec74ab45bbe-image.png" align="center" width="75%" />

This will take you into the prompt editing view:

<Image src="https://files.readme.io/5b9bd1c0a329c468c511faed6f4f6a7351442ed10b34cfc51a80eaec4531d708-image.png" align="center" width="90%" />

### Adding Configs

From here, enter the following text:

You are an AI assistant with

Instead of inserting our brand name (QuiqSilver Bikes) and brand info manually, we can use configs as a shorthand way of referencing pre-defined information:

<Image src="https://files.readme.io/ee5edc2-image.png" align="center" width="75% " />

As you can probably tell, the text containing `configs` is a bit different than the rest of the prompt.

To add a config, or other dynamic information, use the **Add** button in the top right of the Prompt Panel:

<Image src="https://files.readme.io/190ce77f4d78a0fe8b922a6f40c21c9c7c97bcba4e9231ae9f72ce9683dd16ac-image.png" align="center" width="75%" />

Next select the **Fields** section, and click into **configs**:&#x20;

<Image src="https://files.readme.io/7cb776160f414e55ba0a4b524dffd635585e6d9187020ed79abf74b33365845d-image.png" align="center" width="75%" />

From here, select `configs.BRAND` from the list, it will then be inserted into your prompt:

<Image src="https://files.readme.io/74473a6322d050ae534c4f5bebbaaefaea402dc8ba13e7d3fbb328cf9ea39970-image.png" align="center" width="75%" />

Next, add in the `configs.BRAND_DEF` and the following text:

Your job is to classify whether our conversation is highly sensitive.

Your prompt should now look like this:

<Image src="https://files.readme.io/981c887-image.png" align="center" width="60% " />

<Callout icon="📘" theme="info">
  You can use two curly brackets: \{\{ to insert dynamic content in addition to using the **Add** button:


  <Image src="https://files.readme.io/84050ea026f7edc8b0a0ca34cc676d687a8967298eb1049ebd190c3ce4d4f45c-image.png" align="center" width="50%" />

</Callout>

### Conversation History

In order for our classifier to work properly, we've got to pass it the conversation history. That can be achieved using the **Conversation History** option in within the **Blocks&#x20;**&#x73;ection. Blocks are inserted in the same way that Fields are:

<Image src="https://files.readme.io/80442b3a72f0ddc86def412b6a608dcc8bd38c2006ecf84621bfa3bd3f5fb6c0-image.png" align="center" width="75%" />

You'll want to pass in the following text surrounding your Conversation History block:

Here is the conversation so far:

\<conversation>

**INSERT CONVO HISTORY BLOCK HERE**

\</conversation>

### Adding the customer's last message

Next, you'll add in the last user message specifically, in addition to the Conversation History just added. You can either add `conversation.lastCustomerMessage` by navigating to **Fields** --> **conversation**, or by using the search:

<Image src="https://files.readme.io/817ec509a641e0237b62005c972d86887c89c0052981e52bdf817558ebe430d5-image.png" align="center" width="70%" />

You should add the follow text around the last customer message:

Here is the last user message:

\<last-user-message>

**INSERT LAST CUSTOMER MESSAGE HERE**

\</last-user-message>

### Finishing the prompt

Now that you've got the hang of adding text and dynamic content to your prompt, it's time to tie it out:

Add the following text to the end of your prompt, being careful to insert the correct configs where necessary:

> your job is to classify whether our conversation is highly sensitive. Normal personal information should not be considered sensitive in the context of a customer service inquiry with **INSERT CONFIGS.BRAND**
>
> Does our conversation sound like an highly sensitive conversation that may have negative legal, ethical, physical or psychological implications? \<yes, no, or unclear>
>
> Only answer yes when the most recent message is highly sensitive with potential negative legal, ethical, physical or psychological implications for the user or **INSERT CONFIGS.BRAND**
>
> Respond with a JSON formatted object like this:<br />﻿\{<br />﻿  "explanation": "<﻿**INSERT CONFIGS.EXPLANATION**>",<br />﻿  "sensitive": "\<yes, no, or unclear>"<br />﻿}<br />﻿Your JSON response:

When you're done, your prompt should look like this:

<Image src="https://files.readme.io/f4edefba6007943ffa6192b4f2b7420a87cabbf09e0572a9365ba68903f3e9ba-image.png" align="center" width="80% " />

<br />

### Using the prompt completion

Now that you've successfully created your first prompt, we'll need to use the prompt completion to help our assistant guide the flow of the conversation.

In the **Examine Customer Message** behavior, select the three dot **More** menu, then select **Make complex condition** button in the first condition that's currently handling the `message-in-scope` completion:

<Image src="https://files.readme.io/ec041cd5a57cbfec78ffd833a58040dd60c5790cf6ed4fcd9080e62f0c8a47a2-image.png" align="center" width="75%" />

Once you've selected Make complex condition, select `any` from the If `any` or `all` of these conditions are met:

<Image src="https://files.readme.io/d91bc8ac755cdda19548fcf4d45180999c912e67f65302b1e5743458bffb74ad-image.png" align="center" width="75%" />

Then select the **Add Another Condition** button:

<Image src="https://files.readme.io/c4901f2cf2ccf76cff54263322049832e42f5cced36775dbeeb2398a8752c80a-image.png" align="center" width="75%" />

From there, search for the `message-sensitive` prompt you just created, change the Condition to `contains text`, and then set the Value to `yes`:&#x20;

<Image src="https://files.readme.io/28b8654c78a68642e6fd8c6b8f376048b9696437ccc9cf40ae354457d9b789e0-image.png" align="center" width="75%" />

<br />

Congratulations 👏 your **Examine Customer Message** behavior will now be able to identify and handle sensitive inquiries, helping to control the scope of our assistant.

## Not enough evidence

Now send in another phrase, something like:

> My bike's frame was replaced under warranty. Does the new frame get its own new lifetime warranty, or does it follow the original purchase date?

Pay attention both to the response generated, as well as the search results that supposedly verify the statement the assistant made:

<Image src="https://files.readme.io/4a7da4f81034b2a711526228af331e0bfa0af515e3b584f117bf9052e2cc58e5-image.png" align="center" width="90% " />

If you click into each of the results returned, you will not find evidence for the claim the assistant has made. In the next lesson we'll cover how to prevent your assistant from delivering answers that are not verified by evidence from your dataset.

<br />

<Callout icon="📘" theme="info">
  ### Extra Credit

  Try coming up with some additional questions that you think your agent doesn't have the data to answer, but may attempt to answer anyway.
</Callout>

## Key Concepts

<Callout icon="👍" theme="okay">
  ### Resource Search

  - The **Resource Search** tool enables you to search an index with conversational phrases and see what documents get returned [Learn more](https://ai-studio-docs.quiq.com/docs/ai-resources#indexes).
</Callout>

<Callout icon="👍" theme="okay">
  ### Search Behavior

  - The **Search** Behavior enables you to use Retrieval Augmented Generation (RAG) to retrieve information from your knowledge base or other brand approved sources that have been uploaded, transformed, and indexed in AI Resources [Learn more](https://ai-studio-docs.quiq.com/docs/ai-resources).
</Callout>

<Callout icon="👍" theme="okay">
  ### Building Prompts

  - Prompts can be created using the no code prompt editor, and you can insert special content using the left hand tool panel or curly brackets.
  - You can use the completions of your prompts in the **On success** portion of your behavior to change locations in your flow, send messages, and more.
</Callout>

## What's Next

Congratulations, you finished the third lesson! You should be getting a handle on how you can ground your assistant with prompting techniques, RAG and rules. In [Lesson 4](https://ai-studio-docs.quiq.com/docs/knowledge-assistant-lesson) you'll learn how to take your grounding skills to the next level.

#### [Lesson 4: Knowledge Assistant](https://ai-studio-docs.quiq.com/docs/knowledge-assistant-lesson)

<br />