Knowledge bases in Dumpling AI allow you to store, organize, and query large amounts of unstructured data. They’re powered by vector embeddings, which enable semantic search capabilities to find information based on meaning rather than just keywords.
Key use cases include:
Creating chatbots that can answer questions from your documentation
Building internal search engines for company wikis or knowledge repositories
Developing tools that can analyze and extract insights from large collections of text
The first step is to create a knowledge base to store your information:
const axios =require('axios');asyncfunctioncreateKnowledgeBase(name, description){try{const response =await axios.post('https://app.dumplingai.com/api/v1/knowledge-bases',{name: name,description: description},{headers:{'Content-Type':'application/json','Authorization':'Bearer YOUR_API_KEY'}});console.log('Knowledge Base Created:', response.data);return response.data.id;// Save this ID for later use}catch(error){console.error('Error:', error.response? error.response.data: error.message);}}// Create a new knowledge baseconst kbId =awaitcreateKnowledgeBase('Product Documentation','Contains all product documentation for customer support');
Once you have a knowledge base, you can add content to it:
asyncfunctionaddToKnowledgeBase(knowledgeBaseId, content, metadata ={}){try{const response =await axios.post('https://app.dumplingai.com/api/v1/knowledge-bases/add',{knowledgeBaseId: knowledgeBaseId,content: content,metadata: metadata},{headers:{'Content-Type':'application/json','Authorization':'Bearer YOUR_API_KEY'}});console.log('Content Added:', response.data);return response.data;}catch(error){console.error('Error:', error.response? error.response.data: error.message);}}// Add content to the knowledge baseawaitaddToKnowledgeBase( kbId,'Our product offers real-time analytics with customizable dashboards. Users can track key metrics and set up alerts for important thresholds.',{title:'Analytics Features',section:'Features',author:'Product Team',lastUpdated:newDate().toISOString()});
You can combine knowledge base queries with AI completions to build a simple Q&A system:
asyncfunctionanswerQuestion(knowledgeBaseId, question){// First, query the knowledge base for relevant informationconst results =awaitqueryKnowledgeBase(knowledgeBaseId, question,3);// Extract content from results to use as contextconst context = results.map(result=> result.content).join('\n\n');// Use the agent completion endpoint to generate an answertry{const response =await axios.post('https://app.dumplingai.com/api/v1/agents/generate-completion',{messages:[{role:'system',content:`You are a helpful assistant answering questions based on the following information. Only use this information to answer the question. If you don't know the answer, say so.\n\nContext:\n${context}`},{role:'user',content: question}],agentId:'your_agent_id',// Replace with your agent IDparseJson:false},{headers:{'Content-Type':'application/json','Authorization':'Bearer YOUR_API_KEY'}});console.log('Answer:', response.data.text);return response.data.text;}catch(error){console.error('Error:', error.response? error.response.data: error.message);}}// Answer a question using the knowledge baseconst answer =awaitanswerQuestion( kbId,'What kind of alerts can I set up in the dashboard?');console.log('Final Answer:', answer);
You’ve learned how to create knowledge bases, add content, and query them using Dumpling AI. Knowledge bases are a powerful tool for building information retrieval systems, Q&A applications, and chatbots that can access your organization’s information.