Custom Knowledge Base - Pinecone Database
# support
g
Hi, anyone explain process this code. In: https://docs.vapi.ai/knowledge-base/migrating-from-trieve#step-3-create-custom-knowledge-base-in-vapi Step 2: Set Up Your Custom Server How to link: Agent -> knowledge base file -> pinecode database. How i can make sure, the agent search the correct document in pinecone index. is this part used as ID: pinecone.Index('your-knowledge-base');
Copy code
app.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' });
  }
@ivy
c
Hi there, Thank you for your message. Our team is currently out of the office. We operate Monday through Friday, from 9:00 AM to 8:00 PM Pacific Standard Time (PST). We’ll get back to you as soon as possible during our normal business hours. If your message is urgent, please mark it accordingly or include “URGENT” in the subject line, and we’ll do our best to respond promptly. Warm regards, Vapi Customer Support Team
v
Yes, the string in
pinecone.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:
Copy code
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)
g
where can i get this is the ID (name) of your Pinecone index. is it attached on response /kb/search
i cant found a way to trigger /kb/search or see the configurations through /knowledge-base because API is legacy r@Vapi Support Bot @Vapi
c
Hi Gilang, To get started with creating a Knowledge Base in Vapi, you can choose between two methods: the Dashboard method for ease of use or the API method for advanced configurations. Here's a quick overview: Dashboard Method 1. Upload Your Files - Go to
Build > 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.
g
I tried migrating to pinecone database using custom-knowledge-base. this documentations is the only sources: https://docs.vapi.ai/knowledge-base/migrating-from-trieve#overview but, i cant make sure the knowledge base configurations is correct or not because /knowledge-base is removed
i
Hi @Shubham Bajaj can we please get some assistance here? Hi, anyone explain process this code. In: https://docs.vapi.ai/knowledge-base/migrating-from-trieve#step-3-create-custom-knowledge-base-in-vapi Step 2: Set Up Your Custom Server How to link: Agent -> knowledge base file -> pinecode database. How i can make sure, the agent search the correct document in pinecone index. is this part used as ID: pinecone.Index('your-knowledge-base');
Copy code
app.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' });
  }
c
Hi Gilang, To set up a Knowledge Base in Vapi, you have two main methods: 1. **Dashboard Method**: - **Upload Files**: Navigate to
Build > 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).
q
@Gilang did you get this figured out?
2 Views