How can I implement knowledge base in API call for...
# support
w
I want to implement it in my API request because all my settings of the assistant are there.
v
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:
Copy code
bash
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](https://docs.vapi.ai/knowledge-base/using-query-tool) - [API Reference: Update Assistant](https://docs.vapi.ai/api-reference/assistants/update)
k
Use the assistantOverrides field to customize the system prompt, model, voice, transcriber, and dynamic variables directly within the API call.
v
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:
Copy code
bash
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](https://docs.vapi.ai/knowledge-base/using-query-tool) Sources: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool) - [API Reference: Update Assistant](https://docs.vapi.ai/api-reference/assistants/update)
w
will this work for a tool part?
Copy code
"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": []
    }
  }
v
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:
Copy code
json
{
  "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](https://docs.vapi.ai/knowledge-base/using-query-tool) Source: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool)
k
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.
w
i have to connect the knowledge base with this. do i just implement this into the tool? @User
Copy code
"knowledgeBases": [
    {
      "name": "general_questions",
      "provider": "google",
      "model": "gemini-1.5-flash",
      "description": "Use this knowledge base when a user requests information.",
      "fileIds": [
        "-----------------------------"
      ]
    }
  ]
v
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:
Copy code
bash
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](https://docs.vapi.ai/knowledge-base/using-query-tool) Sources: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool) - [API Reference: Update Assistant](https://docs.vapi.ai/api-reference/assistants/update)
k
Yes
v
Yes, you should include the
knowledgeBases
array in your Query Tool definition. Here’s a sample structure:
Copy code
json
{
  "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](https://docs.vapi.ai/knowledge-base/using-query-tool) for full details. Source: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool)
w
so this is good enough to work?
v
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:
Copy code
bash
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](https://docs.vapi.ai/knowledge-base/using-query-tool) Source: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool)
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](https://docs.vapi.ai/knowledge-base/using-query-tool) Source: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool)
k
Please try it and let us know if you have any issues
4 Views