Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions fern/knowledge-base/implement-custom-endpoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,29 @@ Return an array of relevant documents that the AI will use to formulate a respon
{
"content": "Our return policy allows customers to return items within 30 days of purchase for a full refund. Items must be in original condition with tags attached.",
"similarity": 0.92,
"uuid": "doc-return-policy-1" // optional
"uuid": "3f1c2b9e-8d4a-4f6b-9c2e-7a5d1e0b4c3f" // optional, must be a UUID v4
},
{
"content": "Extended return periods apply during holiday seasons - customers have up to 60 days to return items purchased between November 1st and December 31st.",
"similarity": 0.78,
"uuid": "doc-return-policy-holiday" // optional
"uuid": "9b7e4d21-5c3a-4e8f-a1d6-2f0c8b9e7a54" // optional, must be a UUID v4
}
]
}
```

<Warning>
Vapi validates the whole response. If `uuid` is present it must be a UUID v4; any other value, such as a document title or a numeric ID, fails validation and Vapi discards the entire response, so the assistant answers without your documents. Omit `uuid` if your IDs are not UUIDs.
</Warning>

#### Option 2: Return Direct Response

Return a complete response that the assistant will speak directly:
Return a `custom-message` that the assistant will speak directly instead of generating a response. `content` is limited to 1,000 characters:

```json title="Direct Response"
{
"message": {
"role": "assistant",
"type": "custom-message",
"content": "You have 30 days to return items for a full refund. Items must be in original condition with tags attached. During the holiday season (November 1st to December 31st), you get an extended 60-day return period."
}
}
Expand Down Expand Up @@ -144,7 +148,6 @@ app.post('/kb/search', (req, res) => {
documents: relevantDocs.map(doc => ({
content: doc.content,
similarity: doc.similarity,
uuid: doc.id
}))
});

Expand Down Expand Up @@ -239,7 +242,6 @@ async def knowledge_base_search(request: Request):
{
"content": doc['content'],
"similarity": doc['similarity'],
"uuid": doc['id']
}
for doc in relevant_docs
]
Expand Down Expand Up @@ -301,7 +303,6 @@ app.post('/kb/search', async (req, res) => {
const documents = searchResults.matches.map(match => ({
content: match.metadata.content,
similarity: match.score,
uuid: match.id
}));

res.json({ documents });
Expand Down Expand Up @@ -338,7 +339,6 @@ async def search_with_weaviate(request: Request):
documents.append({
"content": doc['content'],
"similarity": doc['_additional']['certainty'],
"uuid": doc.get('title', 'unknown')
})

return {"documents": documents}
Expand Down
Loading