Using the Query Tool for Knowledge Bases

Learn how to configure and use the query tool to enhance your voice AI assistants with custom knowledge bases.

What is the Query Tool?

The Query Tool is a powerful feature that allows your voice AI assistant to access and retrieve information from custom knowledge bases. By configuring a query tool with specific file IDs, you can enable your assistant to provide accurate and contextually relevant responses based on your custom data.

Benefits of Using the Query Tool

  • Enhanced contextual understanding: Your assistant can access specific knowledge to answer domain-specific questions.
  • Improved response accuracy: Responses are based on your verified information rather than general knowledge.
  • Customizable knowledge retrieval: Configure multiple knowledge bases for different topics or domains.

Currently, the Query Tool only supports Google as a provider with the gemini-1.5-flash model for knowledge base retrieval.

How to Configure a Query Tool for Knowledge Bases

Step 1: Upload Your Files

Before creating a query tool, you need to upload the files that will form your knowledge base. You can upload files via the API:

$curl --location 'https://api.vapi.ai/file' \
>--header 'Authorization: Bearer <YOUR_API_KEY>' \
>--form 'file=@"<PATH_TO_YOUR_FILE>"'

After uploading, you’ll receive file IDs that you’ll need for the next step.

Step 2: Create a Query Tool

Use the following API call to create a query tool that references your knowledge base files:

$curl --location 'https://api.vapi.ai/tool/' \
>--header 'Content-Type: application/json' \
>--header 'Authorization: Bearer <YOUR_API_KEY>' \
>--data '{
> "type": "query",
> "function": {
> "name": "product-query"
> },
> "knowledgeBases": [
> {
> "provider": "google",
> "name": "product-kb",
> "description": "Use this knowledge base when the user asks or queries about the product or services",
> "fileIds": [
> "41a2bd44-d13c-4914-bbf7-b19807dd2cf4",
> "ef82ae15-21b2-47bd-bde4-dea3922c1e49"
> ]
> }
> ]
>}'

The description field in the knowledge base configuration helps your assistant understand when to use this particular knowledge base. Make it descriptive of the content.

Step 3: Attach the Query Tool to Your Assistant

After creating the query tool, you’ll receive a tool ID. Use this ID to attach the tool to your assistant:

Option 1: Using the API

$curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
>--header 'Authorization: Bearer <YOUR_API_KEY>' \
>--data '{
> "model": {
> "temperature": 0.2,
> "provider": "openai",
> "model": "gpt-4o",
> "toolIds": [
> "9441840b-6f2f-4b0f-a0fc-de8512549a0c"
> ]
> }
>}'

When using the PATCH request, you must include the entire model object, not just the toolIds field. This will overwrite any existing model configuration.

Option 2: Using the Dashboard

  1. Navigate to the Assistant section in your Vapi dashboard
  2. Select the assistant you want to configure
  3. Go to the Tools section
  4. Add the query tool by selecting it from the available tools
  5. Save and publish your assistant
Adding a query tool to your assistant
Adding a query tool to your assistant

Advanced Configuration Options

Multiple Knowledge Bases

You can configure multiple knowledge bases within a single query tool:

1"knowledgeBases": [
2 {
3 "provider": "google",
4 "name": "product-documentation",
5 "description": "Use this knowledge base for product specifications and features",
6 "fileIds": ["file-id-1", "file-id-2"]
7 },
8 {
9 "provider": "google",
10 "name": "troubleshooting-guide",
11 "description": "Use this knowledge base for troubleshooting and support questions",
12 "fileIds": ["file-id-3", "file-id-4"]
13 }
14]

Knowledge Base Description

The description field helps your assistant understand when to use a particular knowledge base. Make it specific and clear:

1"description": "Use this knowledge base when the user asks about pricing, subscription plans, or billing information"

Best Practices for Query Tool Configuration

  • Organize by topic: Create separate knowledge bases for distinct topics to improve retrieval accuracy.
  • Use descriptive names: Name your knowledge bases clearly to help your assistant understand their purpose.
  • Keep descriptions specific: Write clear descriptions that tell the assistant exactly when to use each knowledge base.
  • Update regularly: Refresh your knowledge bases as information changes to ensure accuracy.
  • Test thoroughly: After configuration, test your assistant with various queries to ensure it retrieves information correctly.

For optimal performance, keep individual files under 300KB and ensure they contain clear, well-structured information.

By following these steps and best practices, you can effectively configure the query tool to enhance your voice AI assistant with custom knowledge bases, making it more informative and responsive to user queries.