Querying a Knowledge Base

#Tags:
No items found.

Querying a knowledge base with MindStudio is an easy way to provide context and train your AI on information related to the goals of your application. 

Before diving into this guide, make sure you have a basic understanding of using Data Sources and message processing in MindStudio. 

Connecting Your Knowledge Base

Data Sources

Upload any text-based file as a Data Source to be referenced by the AI. To create a Data Source, select the (+) icon next to the Data Source resource folder in the Explorer panel. 

 Make sure to name your Data Source and check to make sure the correct files have been uploaded via the file previewer. 

Once you have created your Data Source(s), you will be able to access and edit them at any time via the Data Source folder.

Setup Your Workflow Query 

The Query Data Block

The Query Data block in an Automation block that runs a Data Source query anywhere you place it in your Workflow. To add a Query Data block, select the (+) icon in the space in which you’d like the query to happen. Select your Data Source from the dropdown menu and assign a Variable name to the results output.

Type your query into the Query Template. The AI will send this query at the specific stage in the Workflow you have placed the block. Your query can include Variables from other inputs in your Workflow. 

Query Data block

Retrieval Augmented Generation (RAG)

If you are creating an AI application that needs to query a Data Source before every response to the user, you can do so by using a technique called Retrieval Augmented Generation (RAG) in your message processing. 

To enable RAG, select the Terminator block at the end of your Automation Workflow. Under Message Processing, select the Data Source you wish to query and set your Max Results.

Using RAG

Crafting Effective Queries

Uploading a Data Sources or connecting any other knowledge base does not automatically train your AI on that information. You must provide the AI with a query that it can use to pull relevant data into your application. Here are some tips to help you craft effective queries:

Use specific keywords

Instead of using generic terms, be specific about what you're looking for. This will help narrow down the results to the most relevant information.

Include Variables

Craft queries that include Variables from other User Inputs. This allows you to pass data extracted from a user and query that data against your knowledge base. Make sure to add double braces around each Variable name. Example: {{MyVar1}}

Experiment and test

If your initial query doesn't yield satisfactory results, experiment with different combinations of keywords and phrases. Sometimes a slight adjustment can make all the difference.

Refining Your Query

Improve your query results by refining the query before it is sent to the AI. Before executing a user query, run it through a refiner with tools like a Send Message block and then send the refined query to your Query Data block.

Refine with Send Message blocks

Send Message blocks allow you to format messages that are passed through the AI to generate a response. You can include other Variables from your Workflow inside of every Send Message. 

Use a Send Message block to refine your query by placing it after the user input where you are capturing the original query. Then, pass the User Input Variable through the Send Message block and create a new Variable by setting the response behavior to “Assign to Variable”. You can then use that new Variable name into the Query Template. 

Here is an example of what this might look like:

  1. Collect the user query.

  1. Refine the query with a Send Message. Set the response behavior to “Assign to Variable”. 

  1. Add the Send Message Variable name to the Query Template 

Conclusion 

Creating and utilizing a knowledge base allows you to train your applications on all kinds of information. By familiarizing yourself with using Data Sources, crafting effective queries, and refining your results, you can make the most of your MindStudio projects.

#Tags:
No items found.
No items found.