Skip to content

Commit c615ded

Browse files
authoredMar 8, 2025··
VAP-3952 Add query tool to kb docs (#246)
* VAP-3952 Add query tool to kb docs * added screenshot * remove broken link
1 parent f6db907 commit c615ded

File tree

7 files changed

+235
-100
lines changed

7 files changed

+235
-100
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/.definition
22
**/.preview/**
33
.env
4+
.DS_Store

‎fern/docs.yml

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ navigation:
175175
- section: Knowledge Base
176176
path: knowledge-base/knowledge-base.mdx
177177
contents:
178+
- page: Using the Query Tool
179+
path: knowledge-base/using-query-tool.mdx
178180
- page: Integrating with Trieve
179181
path: knowledge-base/integrating-with-trieve.mdx
180182
- section: Squads

‎fern/knowledge-base/knowledge-base.mdx

+77-100
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,38 @@ slug: knowledge-base
88

99
## **What is Vapi's Knowledge Base?**
1010

11-
A [**Knowledge Base**](/api-reference/knowledge-bases/create) is a collection of custom files that contain information on specific topics or domains. By integrating a Knowledge Base into your voice AI assistant, you can enable it to provide more accurate and informative responses to user queries. This is currently available in Vapi via the API, and will be on the dashboard soon.
11+
A [**Knowledge Base**](/api-reference/knowledge-bases/create) is a collection of custom files that contain information on specific topics or domains. By integrating a Knowledge Base into your voice AI assistant, you can enable it to provide more accurate and informative responses to user queries based on your own data. Knowledge Bases are available through both the Vapi API and dashboard.
1212

1313
### **Why Use a Knowledge Base?**
1414

1515
Using a Knowledge Base with your voice AI assistant offers several benefits:
1616

17-
- **Improved accuracy**: By integrating custom files into your assistant, you can ensure that it provides accurate and up-to-date information to users.
18-
- **Enhanced capabilities**: A Knowledge Base enables your assistant to answer complex queries and provide detailed responses to user inquiries.
19-
- **Customization**: With a Knowledge Base, you can tailor your assistant's responses to specific domains or topics, making it more effective and informative.
17+
- **Improved accuracy**: Your assistant can provide responses based on your verified information rather than general knowledge.
18+
- **Enhanced capabilities**: A Knowledge Base enables your assistant to answer complex domain-specific queries with detailed, contextually relevant responses.
19+
- **Customization**: With a Knowledge Base, you can tailor your assistant's responses to specific domains or topics, making it more effective for your particular use case.
20+
- **Up-to-date information**: You control the content, ensuring your assistant always has access to the latest information.
2021

2122
<Info>
22-
Knowledge Bases are configured through the API, view all configurable properties in the [API Reference](/api-reference/knowledge-bases/create-knowledge-base).
23+
Knowledge Bases are configured through the API or dashboard. For advanced
24+
configuration options, view all configurable properties in the [API
25+
Reference](/api-reference/knowledge-bases/using-query-tool).
2326
</Info>
2427

2528
## **How to Create a Knowledge Base**
2629

27-
To create a Knowledge Base, follow these steps:
30+
There are two main approaches to creating a Knowledge Base in Vapi:
2831

29-
### **Step 1: Upload Your Files**
32+
1. **Dashboard method**: A simplified approach using the Vapi UI
33+
2. **API method**: A more customizable approach using direct API calls
3034

31-
Navigate to Platform > Files and upload your custom files in Markdown, PDF, plain text, or Microsoft Word (.doc and .docx) format to Vapi's Knowledge Base.
35+
### **Method 1: Using the Dashboard**
36+
37+
#### **Step 1: Upload Your Files**
38+
39+
1. Navigate to `Build > Files` in your Vapi dashboard
40+
2. Click the "Upload" button to add your files
41+
3. Select files in supported formats (`.txt`, `.pdf`, `.docx`, etc.)
42+
4. Wait for the upload to complete - you'll see your files listed in the Files section
3243

3344
<Frame caption="Adding files to your Knowledge Base">
3445
<img
@@ -37,101 +48,62 @@ Navigate to Platform > Files and upload your custom files in Markdown, PDF, plai
3748
/>
3849
</Frame>
3950

40-
Alternatively you can upload your files via the API.
41-
42-
```bash
43-
curl --location 'https://api.vapi.ai/file' \
44-
--header 'Authorization: Bearer <YOUR_API_KEY>' \
45-
--form 'file=@"<PATH_TO_YOUR_FILE>"'
46-
```
47-
48-
### **Step 2: Create a Knowledge Base**
49-
50-
Use the ID of the uploaded file to create a Knowledge Base along with the KB configurations.
51-
52-
1. Provider: [trieve](https://trieve.ai)
53-
54-
```bash
55-
curl --location 'http://localhost:3001/knowledge-base' \
56-
--header 'Content-Type: text/plain' \
57-
--header 'Authorization: Bearer <YOUR_API_KEY>' \
58-
--data '{
59-
"name": "v2",
60-
"provider": "trieve",
61-
"searchPlan": {
62-
"searchType": "semantic",
63-
"topK": 3,
64-
"removeStopWords": true,
65-
"scoreThreshold": 0.7
66-
},
67-
"createPlan": {
68-
"type": "create",
69-
"chunkPlans": [
70-
{
71-
"fileIds": ["<FILE_ID_1>", "<FILE_ID_2>"],
72-
"websites": ["<WEBSITE_1>", "<WEBSITE_2>"],
73-
"targetSplitsPerChunk": 50,
74-
"splitDelimiters": [".!?\n"],
75-
"rebalanceChunks": true
76-
}
77-
]
78-
}
79-
}'
80-
```
81-
82-
#### Configuration Options
83-
84-
##### Search Plan Options
85-
86-
- **searchType** (required): The search method used for finding relevant chunks. Available options:
87-
- `fulltext`: Traditional text search
88-
- `semantic`: Semantic similarity search
89-
- `hybrid`: Combines fulltext and semantic search
90-
- `bm25`: BM25 ranking algorithm
91-
- **topK** (optional): Number of top chunks to return. Default varies by implementation
92-
- **removeStopWords** (optional): When true, removes common stop words from the search query. Default: `false`
93-
- **scoreThreshold** (optional): Filters out chunks based on their similarity score:
94-
- For cosine distance: Excludes chunks below the threshold
95-
- For Manhattan Distance, Euclidean Distance, and Dot Product: Excludes chunks above the threshold
96-
- Set to 0 or omit for no threshold
97-
98-
##### Chunk Plan Options
99-
100-
- **fileIds** (optional): Array of file IDs to include in the vector store
101-
- **websites** (optional): Array of website URLs to crawl and include in the vector store
102-
- **targetSplitsPerChunk** (optional): Number of splits per chunk. Default: `20`
103-
- **splitDelimiters** (optional): Array of delimiters used to split text before chunking. Default: `[".!?\n"]`
104-
- **rebalanceChunks** (optional): When true, evenly distributes remainder splits across chunks. For example, 66 splits with `targetSplitsPerChunk: 20` will create 3 chunks with 22 splits each. Default: `true`
105-
106-
### **Step 3: Create an Assistant**
107-
108-
Create a new assistant in Vapi and, on the right sidebar menu. Add the Knowledge Base to your assistant via the PATCH endpoint. Also make sure you customize your assistant's system prompt to utilize the Knowledge Base for responding to user queries.
109-
110-
```bash
111-
curl --location --request PATCH 'https://api.vapi.ai/assistant/<ASSISTANT_ID>' \
112-
--header 'Content-Type: text/plain' \
113-
--header 'Authorization: Bearer <YOUR_API_KEY>' \
114-
--data '{
115-
"model": {
116-
"knowledgeBaseId": "<KNOWLEDGE_BASE_ID>",
117-
"temperature": 0.2,
118-
"provider": "openai",
119-
"model": "gpt-4o",
120-
"messages": [
121-
{
122-
"content": "You are a smart assistant who responds to user queries using the information you know, or information supplied by outside context.",
123-
"role": "system"
124-
}
125-
]
126-
}
127-
}'
128-
```
51+
#### **Step 2: Configure Your Assistant with the Knowledge Base**
52+
53+
1. Navigate to `Build > Assistant`
54+
2. Select the assistant you want to enhance with the Knowledge Base
55+
3. In the assistant configuration, locate the "Files" or "Knowledge Base" section
56+
4. Select the files you uploaded in Step 1 to associate them with this assistant
57+
58+
<Frame caption="Select files from your Assistant">
59+
<img
60+
src="../static/images/knowledge-base/assistant.png"
61+
alt="Select files from your Assistant"
62+
/>
63+
</Frame>
64+
65+
#### **Step 3: Publish the Assistant**
66+
67+
1. Review your assistant configuration to ensure all settings are correct
68+
2. Click the "Publish" button to make your changes live
69+
3. This automatically creates a default knowledge base (using the query tool) with the selected files for the assistant
70+
71+
<Note>
72+
When you publish an assistant with selected files, Vapi automatically creates
73+
a query tool with those files configured as a knowledge base. For more
74+
advanced configurations, use the API method described below or see our [Query
75+
Tool documentation](/knowledge-base/using-query-tool).
76+
</Note>
77+
78+
### **Method 2: Using the API**
79+
80+
For more advanced configurations, you can create and configure Knowledge Bases using the API through the Query Tool. This method offers greater flexibility and control over your knowledge base setup.
81+
82+
<Info>
83+
For detailed instructions on creating and configuring knowledge bases via the
84+
API, please refer to our dedicated guide: [Using the Query Tool for Knowledge
85+
Bases](/knowledge-base/using-query-tool).
86+
</Info>
87+
88+
The API method allows you to:
89+
90+
- Upload files and obtain file IDs
91+
- Create custom query tools with specific knowledge base configurations
92+
- Configure multiple knowledge bases within a single query tool
93+
- Attach query tools to your assistants
94+
- Set advanced parameters for knowledge retrieval
95+
96+
This approach is recommended for developers and users who need precise control over their knowledge base implementation or are integrating Vapi into existing systems programmatically.
12997

13098
## **Best Practices for Creating Effective Knowledge Bases**
13199

132-
- **Organize Your files**: Organize your files by topic or category to ensure that your assistant can quickly retrieve relevant information.
133-
- **Use Clear and concise language**: Use clear and concise language in your files to ensure that your assistant can accurately understand and respond to user queries.
134-
- **Keep your files up-to-date**: Regularly update your files to ensure that your assistant provides the most accurate and up-to-date information.
100+
- **Optimize file size**: Keep individual files smaller than 300KB to ensure quick processing and response times.
101+
- **Structure content logically**: Organize your files by topic or category with clear headings and sections.
102+
- **Use clear and concise language**: Write in plain language with well-defined terminology to improve retrieval accuracy.
103+
- **Update regularly**: Refresh your knowledge base files whenever information changes to maintain accuracy.
104+
- **Test thoroughly**: After configuration, test your assistant with various queries to ensure it retrieves information correctly.
105+
- **Provide context**: Include sufficient background information in your files to enable comprehensive responses.
106+
- **Consider file formats**: While plain text works well, structured formats can improve information retrieval for complex topics.
135107

136108
<Tip>
137109
For more information on creating effective Knowledge Bases, check out our
@@ -140,3 +112,8 @@ curl --location --request PATCH 'https://api.vapi.ai/assistant/<ASSISTANT_ID>' \
140112
</Tip>
141113

142114
By following these guidelines, you can create a comprehensive Knowledge Base that enhances the capabilities of your voice AI assistant and provides valuable information to users.
115+
116+
<Info>
117+
Currently, Vapi's Knowledge Base functionality supports Google as a provider
118+
with the gemini-1.5-flash model for knowledge retrieval.
119+
</Info>
+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: Using the Query Tool for Knowledge Bases
3+
subtitle: >-
4+
Learn how to configure and use the query tool to enhance your voice AI assistants with custom knowledge bases.
5+
slug: knowledge-base/using-query-tool
6+
---
7+
8+
## **What is the Query Tool?**
9+
10+
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.
11+
12+
### **Benefits of Using the Query Tool**
13+
14+
- **Enhanced contextual understanding**: Your assistant can access specific knowledge to answer domain-specific questions.
15+
- **Improved response accuracy**: Responses are based on your verified information rather than general knowledge.
16+
- **Customizable knowledge retrieval**: Configure multiple knowledge bases for different topics or domains.
17+
18+
<Info>
19+
Currently, the Query Tool only supports Google as a provider with the
20+
gemini-1.5-flash model for knowledge base retrieval.
21+
</Info>
22+
23+
## **How to Configure a Query Tool for Knowledge Bases**
24+
25+
### **Step 1: Upload Your Files**
26+
27+
Before creating a query tool, you need to upload the files that will form your knowledge base. You can upload files via the API:
28+
29+
```bash
30+
curl --location 'https://api.vapi.ai/file' \
31+
--header 'Authorization: Bearer <YOUR_API_KEY>' \
32+
--form 'file=@"<PATH_TO_YOUR_FILE>"'
33+
```
34+
35+
After uploading, you'll receive file IDs that you'll need for the next step.
36+
37+
### **Step 2: Create a Query Tool**
38+
39+
Use the following API call to create a query tool that references your knowledge base files:
40+
41+
```bash
42+
curl --location 'https://api.vapi.ai/tool/' \
43+
--header 'Content-Type: application/json' \
44+
--header 'Authorization: Bearer <YOUR_API_KEY>' \
45+
--data '{
46+
"type": "query",
47+
"function": {
48+
"name": "product-query"
49+
},
50+
"knowledgeBases": [
51+
{
52+
"provider": "google",
53+
"name": "product-kb",
54+
"description": "Use this knowledge base when the user asks or queries about the product or services",
55+
"fileIds": [
56+
"41a2bd44-d13c-4914-bbf7-b19807dd2cf4",
57+
"ef82ae15-21b2-47bd-bde4-dea3922c1e49"
58+
]
59+
}
60+
]
61+
}'
62+
```
63+
64+
<Note>
65+
The `description` field in the knowledge base configuration helps your
66+
assistant understand when to use this particular knowledge base. Make it
67+
descriptive of the content.
68+
</Note>
69+
70+
### **Step 3: Attach the Query Tool to Your Assistant**
71+
72+
After creating the query tool, you'll receive a tool ID. Use this ID to attach the tool to your assistant:
73+
74+
#### Option 1: Using the API
75+
76+
```bash
77+
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
78+
--header 'Authorization: Bearer <YOUR_API_KEY>' \
79+
--data '{
80+
"model": {
81+
"temperature": 0.2,
82+
"provider": "openai",
83+
"model": "gpt-4o",
84+
"toolIds": [
85+
"9441840b-6f2f-4b0f-a0fc-de8512549a0c"
86+
]
87+
}
88+
}'
89+
```
90+
91+
<Warning>
92+
When using the PATCH request, you must include the entire model object, not
93+
just the toolIds field. This will overwrite any existing model configuration.
94+
</Warning>
95+
96+
#### Option 2: Using the Dashboard
97+
98+
1. Navigate to the Assistant section in your Vapi dashboard
99+
2. Select the assistant you want to configure
100+
3. Go to the Tools section
101+
4. Add the query tool by selecting it from the available tools
102+
5. Save and publish your assistant
103+
104+
<Frame caption="Adding a query tool to your assistant">
105+
<img
106+
src="../static/images/knowledge-base/query-tool.png"
107+
alt="Adding a query tool to your assistant"
108+
/>
109+
</Frame>
110+
111+
## **Advanced Configuration Options**
112+
113+
### **Multiple Knowledge Bases**
114+
115+
You can configure multiple knowledge bases within a single query tool:
116+
117+
```json
118+
"knowledgeBases": [
119+
{
120+
"provider": "google",
121+
"name": "product-documentation",
122+
"description": "Use this knowledge base for product specifications and features",
123+
"fileIds": ["file-id-1", "file-id-2"]
124+
},
125+
{
126+
"provider": "google",
127+
"name": "troubleshooting-guide",
128+
"description": "Use this knowledge base for troubleshooting and support questions",
129+
"fileIds": ["file-id-3", "file-id-4"]
130+
}
131+
]
132+
```
133+
134+
### **Knowledge Base Description**
135+
136+
The description field helps your assistant understand when to use a particular knowledge base. Make it specific and clear:
137+
138+
```json
139+
"description": "Use this knowledge base when the user asks about pricing, subscription plans, or billing information"
140+
```
141+
142+
## **Best Practices for Query Tool Configuration**
143+
144+
- **Organize by topic**: Create separate knowledge bases for distinct topics to improve retrieval accuracy.
145+
- **Use descriptive names**: Name your knowledge bases clearly to help your assistant understand their purpose.
146+
- **Keep descriptions specific**: Write clear descriptions that tell the assistant exactly when to use each knowledge base.
147+
- **Update regularly**: Refresh your knowledge bases as information changes to ensure accuracy.
148+
- **Test thoroughly**: After configuration, test your assistant with various queries to ensure it retrieves information correctly.
149+
150+
<Tip>
151+
For optimal performance, keep individual files under 300KB and ensure they
152+
contain clear, well-structured information.
153+
</Tip>
154+
155+
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.
59.7 KB
Loading
13.1 KB
Loading
74.5 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.