Gilang
10/06/2025, 2:09 AMapp.post('/kb/search', async (req, res) => {
try {
const { message } = req.body;
const userMessages = message.messages.filter(msg => msg.role === 'user');
const latestQuery = userMessages[userMessages.length - 1]?.content || '';
// Search your vector database
const index = pinecone.Index('your-knowledge-base');
const searchResults = await index.query({
vector: await getEmbedding(latestQuery),
topK: 5,
includeMetadata: true
});
// Format response
const documents = searchResults.matches.map(match => ({
content: match.metadata.content,
similarity: match.score,
uuid: match.id
}));
res.json({ documents });
} catch (error) {
res.status(500).json({ error: 'Search failed' });
}
@ivyChiranjeet Mishra
10/06/2025, 2:09 AMVapi Support Bot
10/06/2025, 2:10 AMpinecone.Index('your-knowledge-base') is the ID (name) of your Pinecone index.
To ensure your agent searches the correct documents, make sure this name matches the index where you uploaded your knowledge base files. For example, if your index is called product-kb, use:
js
const index = pinecone.Index('product-kb');
This way, all queries from your agent will search the correct set of documents in Pinecone.
For more details, see the [Vapi migration guide](https://docs.vapi.ai/knowledge-base/migrating-from-trieve#step-3-create-custom-knowledge-base-in-vapi).
Source:
- [Migrating from Trieve](https://docs.vapi.ai/knowledge-base/migrating-from-trieve)Gilang
10/06/2025, 2:40 AMGilang
10/09/2025, 7:36 AMChiranjeet Mishra
10/11/2025, 12:44 AMBuild > Files in your Vapi dashboard.
- Click "Upload" and select your files (.txt, .pdf, .docx, etc.).
2. Configure Your Assistant
- Navigate to Build > Assistant and select your assistant.
- In the configuration, locate the "Files" or "Knowledge Base" section and associate the uploaded files.
3. Publish the Assistant
- Add appropriate prompts to guide your assistant on when to use the knowledge base.
- Click "Publish" to make changes live.
For more detailed steps and options, check our [knowledge base documentation](https://docs.vapi.ai/knowledge-base).
API Method
This method provides more flexibility and is recommended if you need full control over your knowledge base setup via code. You can upload files, create complex query tools, and configure your assistant programmatically. Refer to [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool.mdx).
Let me know if you need further assistance on this.Gilang
10/13/2025, 1:34 AMivy
10/14/2025, 1:38 AMapp.post('/kb/search', async (req, res) => {
try {
const { message } = req.body;
const userMessages = message.messages.filter(msg => msg.role === 'user');
const latestQuery = userMessages[userMessages.length - 1]?.content || '';
// Search your vector database
const index = pinecone.Index('your-knowledge-base');
const searchResults = await index.query({
vector: await getEmbedding(latestQuery),
topK: 5,
includeMetadata: true
});
// Format response
const documents = searchResults.matches.map(match => ({
content: match.metadata.content,
similarity: match.score,
uuid: match.id
}));
res.json({ documents });
} catch (error) {
res.status(500).json({ error: 'Search failed' });
}Chiranjeet Mishra
10/14/2025, 6:46 PMBuild > Files and upload supported file types (e.g., .txt, .pdf, .docx).
- **Configure Assistant**: Go to Build > Assistant, select your assistant, and link the uploaded files.
- **Publish**: Add prompts to guide your assistant on when to use the Knowledge Base and publish your changes.
2. **API Method**:
- Use the API for advanced configuration, allowing more control over your Knowledge Base setup.
For creating a custom Knowledge Base, you can customize your document retrieval process via a webhook. This setup offers full control over data management, allowing integration with your systems.
For detailed guidance, refer to our [Introduction to Knowledge Bases](https://docs.vapi.ai/knowledge-base) and [custom Knowledge Base documentation](https://docs.vapi.ai/knowledge-base/custom-knowledge-base).Qper
12/03/2025, 12:03 AM