| title | Using the Query Tool for Knowledge Bases |
|---|---|
| subtitle | Learn how to configure and use the query tool to enhance your AI assistants with custom knowledge bases. |
| slug | knowledge-base/using-query-tool |
The Query Tool is a powerful feature that allows your 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.
- 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.
Before creating a query tool, you need to upload the files that will form your knowledge base.
- Navigate to Files in your Vapi dashboard
- Click Upload File or Choose file
- Select the files you want to upload from your computer
- Wait for the upload to complete and note the file IDs that are generated
Alternatively, 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.
Create a query tool that references your knowledge base files:
- Navigate to Tools in your Vapi dashboard
- Click Create Tool
- Select Query as the tool type
- Configure the tool:
- Tool Name: "Product Query"
- Knowledge Bases: Add your knowledge base with:
- Name:
product-kb - Description: "Contains comprehensive product information, service details, and company offerings"
- File IDs: Select the files you uploaded in Step 1
- Name:
Alternatively, you can create the tool via API:
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": "Contains comprehensive product information, service details, and company offerings",
"fileIds": [
"41a2bd44-d13c-4914-bbf7-b19807dd2cf4",
"ef82ae15-21b2-47bd-bde4-dea3922c1e49"
]
}
]
}'After creating the query tool, you need to attach it to your assistant:
- Navigate to Assistants in your Vapi dashboard
- Select the assistant you want to configure
- Go to the Tools section
- Click Add Tool and select your query tool from the dropdown
- Update the system prompt to instruct when to use the tool (see examples below)
- Save and publish your assistant
Alternatively, you can attach the tool via API using the tool ID:
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"
]
}
}'You can configure multiple knowledge bases within a single query tool:
"knowledgeBases": [
{
"provider": "google",
"name": "product-documentation",
"description": "Contains detailed product specifications, feature descriptions, and technical details",
"fileIds": ["file-id-1", "file-id-2"]
},
{
"provider": "google",
"name": "troubleshooting-guide",
"description": "Contains troubleshooting guides, support procedures, and problem resolution steps",
"fileIds": ["file-id-3", "file-id-4"]
}
]The description field should explain what content the knowledge base contains:
"description": "Contains pricing information, subscription plans, and billing documentation"Add clear instructions to your assistant's system messages, explicitly naming the tool:
{
"role": "system",
"content": "You are a helpful customer support assistant. When users ask about products, pricing, features, or need troubleshooting help, use the 'knowledge-search' tool to search our knowledge base for accurate information. Always call the knowledge-search tool before providing answers to ensure accuracy."
}Example system prompt instructions with specific tool names:
- Product Support: "When users ask about product features, specifications, or troubleshooting, use the 'product-support-search' tool to find relevant information."
- Billing Questions: "For any questions about pricing, billing, or subscription plans, use the 'billing-query' tool to find the most current information."
- Technical Documentation: "When users need API documentation, code examples, or integration help, use the 'api-docs-search' tool to search the technical knowledge base."
- 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.
- Include system prompt instructions: Always add explicit instructions to your assistant's system prompt about when to use the query tool.
- 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.
By following these steps and best practices, you can effectively configure the query tool to enhance your AI assistant with custom knowledge bases, making it more informative and responsive to user queries.
