adverse-sapphire
adverse-sapphire4mo ago

How can I implement knowledge base in API call for create call?

I want to implement it in my API request because all my settings of the assistant are there.
13 Replies
Vapi Support Bot
To use a knowledge base in your API call for creating a call, first update your assistant to include the knowledge base via the Query Tool. Then, reference this assistant in your call creation request. Here’s how to attach a knowledge base to your assistant using the API:
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
After this, use the assistantId in your call creation API request.
Note: The knowledge base must be set at the assistant level before making the call; it cannot be set directly in the call creation request. Sources: - Using the Query Tool for Knowledge Bases - API Reference: Update Assistant
⤵️ Mention @Vapi Support Bot for follow-ups 🐥
sensitive-blue
sensitive-blue4mo ago
Use the assistantOverrides field to customize the system prompt, model, voice, transcriber, and dynamic variables directly within the API call.
Vapi Support Bot
To use a knowledge base in your API call for creating a call, you must first attach the knowledge base to your assistant. Here’s how to do it:
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
After this, use the updated assistantId in your call creation API request. The knowledge base cannot be set directly in the call creation request.
Reference: Using the Query Tool for Knowledge Bases Sources: - Using the Query Tool for Knowledge Bases - API Reference: Update Assistant
adverse-sapphire
adverse-sapphireOP4mo ago
will this work for a tool part?
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information. Including information, general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information. Including information, general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
Vapi Support Bot
Yes, your tool definition is in the correct format for a Query Tool, but you must also link it to your knowledge base files and attach it to your assistant. Here’s a sample structure:
{
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information. Including information, general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
}
{
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information. Including information, general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
}
Be sure to reference your knowledge base files and attach the tool to your assistant using the tool ID for it to work.
See full guide Source: - Using the Query Tool for Knowledge Bases
sensitive-blue
sensitive-blue4mo ago
Yes, just ensure the "type" is appropriate "function" if it’s executing an action and define a server if it’s calling an external API.
adverse-sapphire
adverse-sapphireOP4mo ago
i have to connect the knowledge base with this. do i just implement this into the tool? @Kings_big💫
"knowledgeBases": [
{
"name": "general_questions",
"provider": "google",
"model": "gemini-1.5-flash",
"description": "Use this knowledge base when a user requests information.",
"fileIds": [
"-----------------------------"
]
}
]
"knowledgeBases": [
{
"name": "general_questions",
"provider": "google",
"model": "gemini-1.5-flash",
"description": "Use this knowledge base when a user requests information.",
"fileIds": [
"-----------------------------"
]
}
]
Vapi Support Bot
To use a knowledge base in your API call for creating a call, you must first attach the knowledge base to your assistant.
Update your assistant with the Query Tool ID like this:
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
After this, use the updated assistantId in your call creation API request. The knowledge base cannot be set directly in the call creation request.
Full guide here Sources: - Using the Query Tool for Knowledge Bases - API Reference: Update Assistant
sensitive-blue
sensitive-blue4mo ago
Yes
Vapi Support Bot
Yes, you should include the knowledgeBases array in your Query Tool definition. Here’s a sample structure:
{
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information, including general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
},
"knowledgeBases": [
{
"name": "general_questions",
"provider": "google",
"model": "gemini-1.5-flash",
"description": "Use this knowledge base when a user requests information.",
"fileIds": ["<YOUR_FILE_ID>"]
}
]
}
{
"type": "query",
"function": {
"name": "query_tool",
"description": "This tool is used to retrieve information, including general or frequently asked questions.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
},
"knowledgeBases": [
{
"name": "general_questions",
"provider": "google",
"model": "gemini-1.5-flash",
"description": "Use this knowledge base when a user requests information.",
"fileIds": ["<YOUR_FILE_ID>"]
}
]
}
After creating the tool, attach it to your assistant using the tool ID.
See the Vapi Query Tool guide for full details. Source: - Using the Query Tool for Knowledge Bases
adverse-sapphire
adverse-sapphireOP4mo ago
so this is good enough to work?
Vapi Support Bot
To connect your knowledge base to your tool, include the knowledgeBases array in your tool definition and then attach the tool to your assistant. Update your assistant like this:
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
curl --location --request PATCH 'https://api.vapi.ai/assistant/ASSISTANT_ID' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": {
"provider": "openai",
"model": "gpt-4o",
"toolIds": ["<QUERY_TOOL_ID>"]
}
}'
After this, use the updated assistantId in your call creation API request.
The knowledge base must be attached to the assistant before making the call—this cannot be set directly in the call creation request.
Full guide here Source: - Using the Query Tool for Knowledge Bases Yes, your setup is good enough to work.
Just make sure your knowledgeBases array is included in your Query Tool definition, and that you attach the tool to your assistant using its tool ID. Here’s a quick checklist: - Define your Query Tool with the knowledgeBases array. - Attach the tool to your assistant. - Use the updated assistant in your call creation. Test your assistant to ensure it retrieves knowledge base info as expected.
See full guide Source: - Using the Query Tool for Knowledge Bases
Sahil
Sahil4mo ago
Please try it and let us know if you have any issues

Did you find this page helpful?