Skip to main content

Adding RAG to Your Flow

Summary

Okay, at this point, we have a ChatBot that can keep track of our conversation and our data indexed.

Now we need to modify our flow so the bot can answer questions using our data.

Add a Retriever Node

  1. Click the Add Node Icon.
  2. Drag the Retriever Node to your flow. Type in "R" the search for quick lookup.
  3. Attach the start node to the retrieved node. We will use the user's question to search the Index.
  4. Attach the Retriever node to the LLM.

alt text

Select your Index in the retriever Node

Now open up the retriever node and select the index we just created. alt text

Update your Prompt

Now that the retreiver has the question to lookup and our AI function will now received both the question and retrieval results we need to modify our prompt to include that data so the Languge Model can reason with it.

Open your LLM.

Lets replace System Prompt with the following

You are an expert Q&A system that is trusted around the world.

Always answer the query using the provided context information, and not prior knowledge.

Some rules to follow:
1. Never directly reference the given context in your answer.
2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines.

replace your user prompt with this:

Context information is below.
---------------------
{{#each results}}
{{{text}}}
###
{{/each}}
---------------------
Given the context information and not prior knowledge, answer the query.

Query: {{{text_input}}}
Answer:

BotDojo uses a templating language called Handle Bars that lets you generate prompts with data. In the above example we can inserting relvant information from the Index and stuffing it into the prompt.

Next step lets test it out...