You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: customization/knowledgebase.mdx
+132Lines changed: 132 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -57,4 +57,136 @@ Customize your assistant's system prompt to utilize the Knowledge Base for respo
57
57
For more information on creating effective Knowledge Bases, check out our tutorial on [Best Practices for Knowledge Base Creation](https://youtu.be/i5mvqC5sZxU).
58
58
</Tip>
59
59
60
+
## Custom Knowledge Base Documentation
61
+
62
+
### Overview
63
+
64
+
This guide is about setting up your own custom knowledge base. You can hook up your own server to handle knowledge requests, which are then sent to a language model to generate responses based on the info you provide.
65
+
66
+
---
67
+
68
+
### Custom Knowledge Base Class
69
+
70
+
#### CustomKnowledgeBase
71
+
72
+
This is where you define your custom knowledge base setup. It tells the system where to send requests and how to handle them.
73
+
74
+
**Properties:**
75
+
76
+
-**provider**: Set this to `custom-knowledge-base` since you're using a custom setup.
77
+
-**server**: This is where you configure your server's details, like the URL, secret key (if you have one), and the request timeout.
78
+
79
+
---
80
+
81
+
### Server Configuration
82
+
83
+
#### Server
84
+
85
+
This class defines your server settings, which is where the system will send all the requests.
86
+
87
+
**Properties:**
88
+
89
+
-**url**: The endpoint where requests will be sent. Needs to be a valid HTTPS URL. Example: `https://my-restaurant-knowledgebase.com`.
90
+
91
+
-**secret**: Optional. A secret key to add as a header (`x-vapi-secret`) for extra security.
92
+
93
+
-**timeoutSeconds**: How long to wait for a response before timing out. Default is 20 seconds, but you can set it anywhere between 1 and 60 seconds.
94
+
95
+
---
96
+
97
+
### Making a Request
98
+
99
+
When the system needs info from your knowledge base, it sends a `POST` request to your server’s URL.
100
+
101
+
#### Example 1: Restaurant Opening Hours
102
+
103
+
Let’s say a user asks for your restaurant’s opening hours. Here's the request:
104
+
105
+
```bash
106
+
curl -X POST https://my-restaurant-knowledgebase.com \
107
+
-H "Content-Type: application/json" \
108
+
-H "x-vapi-secret: your-secret-key" \
109
+
-d '{
110
+
"message": {
111
+
"type": "knowledge-base-request",
112
+
"messages": [
113
+
{
114
+
"role": "user",
115
+
"content": "What are your opening hours?"
116
+
}
117
+
]
118
+
}
119
+
}'
120
+
```
121
+
122
+
---
123
+
124
+
### Expected Response
125
+
126
+
When your server gets the request, it’ll return one of two things:
127
+
1. A direct answer that the assistant can speak or display.
128
+
2. A list of documents that the system will use to generate a reply.
129
+
130
+
#### Example 1: Direct Response for Opening Hours
131
+
132
+
```json
133
+
{
134
+
"message": {
135
+
"role": "assistant",
136
+
"content": "Our restaurant is open from 10 AM to 9 PM, Monday to Saturday."
137
+
}
138
+
}
139
+
```
140
+
141
+
The assistant will say:
142
+
**"Our restaurant is open from 10 AM to 9 PM, Monday to Saturday."**
143
+
144
+
#### Example 2: Document-Based Response for Opening Hours
145
+
146
+
```json
147
+
{
148
+
"documents": [
149
+
{
150
+
"content": "The restaurant is open from 10 AM to 9 PM, Monday to Saturday. Sunday hours are 11 AM to 6 PM.",
151
+
"similarity": 1
152
+
},
153
+
{
154
+
"content": "We are closed on Thanksgiving and Christmas.",
155
+
"similarity": 0.9
156
+
}
157
+
]
158
+
}
159
+
```
160
+
161
+
The assistant might respond with:
162
+
**"We’re open from 10 AM to 9 PM, Monday to Saturday, and from 11 AM to 6 PM on Sundays."**
163
+
164
+
---
165
+
166
+
### Server Message Request Structure
167
+
168
+
`ServerMessageKnowledgeBaseRequest` is how the system sends messages to your server.
169
+
170
+
-**type**: Always `"knowledge-base-request"` to ask for info from the knowledge base.
171
+
-**messages**: The user’s question or conversation context, which gets sent to your server.
172
+
-**messagesOpenAIFormatted**: If you’re using OpenAI or something similar, this is where you send formatted messages.
173
+
174
+
---
175
+
176
+
### Response Message Structure
177
+
178
+
`ServerMessageResponseKnowledgeBaseRequest` defines how your server should respond.
179
+
180
+
-**documents**: An array of documents, each containing a piece of content (e.g., a menu item or a policy) and its relevance (similarity score).
181
+
-**message**: Optional. This is where you can send a direct response instead of letting the system process the documents.
182
+
183
+
---
184
+
185
+
186
+
### Choosing Between Response Types
187
+
188
+
-**Custom Message Response**: Use this when you already have a simple answer ready to go, like stating opening hours.
189
+
190
+
-**Document-Based Response**: Use this when the assistant requires to be provided with more context or pull from additional documents more context or detail, like explaining the full menu or availability rules.
191
+
60
192
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.
0 commit comments