Problem with attaching knowledgebase programmatica...
# support
a
OK, I can't make the knowledgebase to work properly. Meaning that I don't receive answers that are relative to the knowledgebase I provide in my app, in contrast to Vapi dashboard where the answers I receive do seem to align with my knowledgebase. Things I tried: 1. I tried creating a temporary assistant in the client and pass the knowledgeBaseId (This would be my preferred approach):
Copy code
json
...
"model": {
    "provider": "openai",
    "model": "gpt-4o",
    "maxTokens": 250,
    "messages": [{"role": "system", "content": "..."}],
    "temperature": 0,
    "knowledgeBaseId": "knowledge_base_id"
}, ...
2. I made the assistant in Vapi dashboard and updated it with the knowledgebase id:
Copy code
python
assistant = client.assistants.get(id=assistant_id)
updated_model = assistant.model.model_copy(update={"knowledge_base_id": knowledge_base_id})
client.assistants.update(id=assistant_id, model=updated_model)
When I get the assistant, I can see that the knowledge_base_id is attached but it's responses show that it has no idea about that knowledgebase. In contrast, if I attach the file (that I used to make the knowledgebase) to the assistant in the dashboard and then test it, it seems to work OK. Although I'm not entirely sure because the assistant's messages show no
source
. This is how I create the knowledgebase in Python:
Copy code
python
data = {
    "name": name,
    "provider": "trieve",
    "searchPlan": {
        "scoreThreshold": 0.2,
        "searchType": "semantic"
    },
    "createPlan": {
        "type": "create",
        "chunkPlans": [
            {
                "fileIds": file_ids,
                "websites": [],
                "targetSplitsPerChunk": 50,
                "rebalanceChunks": True
            }
        ]
    }
}
response = requests.post('https://api.vapi.ai/knowledge-base', headers=headers, json=data)
What am I doing wrong?
a
HeyAGTGreg Thank you for creating the ticket! A member of our team will reach out to you shortly.
c
What does your prompt say?
a
I got the params from here: https://docs.vapi.ai/knowledgebase I also tried updating the assistant without the SDK:
Copy code
python
response = requests.patch(
    f'https://api.vapi.ai/assistant/{assistant_id}',
    headers=headers,
    json={
        "model": {
            "knowledgeBaseId": knowledge_base_id,
            "temperature": 0.2,
            "provider": "openai",
            "model": "gpt-4o",
            "messages": [
                {
                    "content": "You are a smart assistant who responds to user queries using the information you know, or information supplied by outside context.",
                    "role": "system"
                }
            ]
        }
    }
)
I get no error or warnings and all messages from bot in the logs do not have a source:
Copy code
json
{
  "role": "bot",
  "time": 1738335597677,
  "source": "",
  "endTime": 1738335613467,
  "message": "...",
  "duration": 14120,
  "secondsFromStart": 10.14
}
I am not sure if knowledgebase works at all.
c
That is not your prompt.
a
I tried these:
Copy code
You are a smart assistant who responds to user queries using the information you know, or information supplied by outside context. If you don't have any information say "I don't know"
Copy code
You are a smart assistant who responds to user queries using the information you know, or information supplied by outside context.
This is a dump from my console when I update the assistant.:
Copy code
"model": {
     "model": "gpt-4o",
     "messages": [
       {
         "role": "system",
         "content": "You are a smart assistant who responds to user queries using the information you know, or information supplied by outside context."
       }
     ],
     "provider": "openai",
     "temperature": 0.2,
     "knowledgeBaseId": "54aaba05-f5fe-4580-9bff-8a4745e10202"
   },
And this is a message from the logs. I believe it should have a source (unless
source
has nothing to do with knowledgebase):
Copy code
{
  "role": "bot",
  "time": 1738336498004,
  "source": "",
  "endTime": 1738336519474,
  "message": "...",
  "duration": 17929.9990234375,
  "secondsFromStart": 13.33
}
c
No it should not have a source.
Also that prompt does not say anything about using the KB it looks like. or you took the example from the docs.
a
Just like I said, I took the example from the docs: https://docs.vapi.ai/knowledgebase. What would be a good example for a prompt?
I just tried this as well:
Copy code
You are a smart assistant who responds to user queries using the information from your KnowledgeBase. If the answer is not in the KnowledgeBase say 'I do not know'.
Not better. Also, if it should not have a source, then how will I know what context it used (if any) to answer the question?
c
Lol you don't have to get smart. I am just simply asking. It would seem that example propmt is not working for your custom Assistant. So did you try changing that up. I mean I don't know the answer to that question, but i know when the question is answered it does not come from the source and it never has.
a
Thank you for trying to help me. I appreciate it, I really do. I have tried some prompts, yes. Nothing seems to work. Plus some of the docs seem outdated or wrong.
c
Docs ae not outdated or wrong at al. I use the API everyday. What is your document?
a
It's a txt file. I also tried other txt files with different knowledge bases.
I also tried to download it from the dashboard so I know it was uploaded successfully. Maybe the params I use for creating the knowledgebase are wrong.
c
No I would think its more of the prompt. That is what it is usually based on.
s
Hey @AGTGreg To help track down this issue, could you share: - The call ID - When exactly this happened (the timestamp) - What response you expected to get - What response you actually got instead This would really help me figure out what went wrong!
@AGTGreg Because of no response closing this ticket.
a
OK, here are my test results: What I have: A small TXT document with knowledge base of profoundly false facts. So that I know that when the assistant answers it uses the knowledgebase as the single source of truth. - When I ask: "What is the color of the sky?" I expect the answer to be "Purple." - When I ask: "What do you need in order to play football?" I expect the answer to be: "A square ball made out of stone." When I initially posted the problem here I did not have any success. Today, I've had mixed results without changing anything. So here are my results for today: The prompt of test 1 and 2 is the same:
You are a smart assistant who responds to user queries using the information from your KnowledgeBase. If the answer is not in the KnowledgeBase say 'I do not know'.
Test 1: Call ID:
90a8d16e-84d0-49b3-b09c-ab1a0e74baa9
If I use an assistant that was created in Vapi Dashboard and I update it programmatically with the knowledgebase I get good results. The assistant follows the knowledgebase correctly. Test 2: Call ID:
b0c051db-5124-442a-9cfe-b55ca94dff43
If I make a temporary assistant and pass the knowledgebase I get mixed results. The assistant is aware of the knowledgebase but it's not allways following it. For example: TS:
1738573301379
Q: What is the color of the sky? A: I do not know. TS:
1738573307989
Q: What is the color of the grass? A: According to the provided context, the color of the grass is black. Test 3: Call ID:
86013be6-e946-4994-ae3a-83210f64c42d
If I add to that prompt some conversation history I get some funny responses. The assistant is aware of the knowledgebase but chooses to ignore it: TS:
1738573089949
Q: What do you need in order to play football? A: To play football, you need a round ball made out of leather or a similar material, not a square ball made out of stone.
The model in all cases above is also the same:
Copy code
json
"model": {
    "knowledgeBaseId": knowledge_base_id,
    "temperature": 0.2,
    "provider": "openai",
    "model": "gpt-4o",
    "messages": [
        {
            "content": "You are a smart assistant who responds to user queries using the information from your KnowledgeBase. If the answer is not in the KnowledgeBase say 'I do not know'.",
            "role": "system"
        }
    ]
}
s
@AGTGreg As discussed in an another ticket, this issue has been resolved.
2 Views