Knowledge bases in DumplingAI 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
You can combine knowledge base queries with AI completions to build a simple Q&A system:
Copy
async function answerQuestion(knowledgeBaseId, question) { // First, query the knowledge base for relevant information const results = await queryKnowledgeBase(knowledgeBaseId, question, 3); // Extract content from results to use as context const context = results.map(result => result.content).join('\n\n'); // Use the agent completion endpoint to generate an answer try { 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 ID parseJson: 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 = await answerQuestion( 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 DumplingAI. Knowledge bases are a powerful tool for building information retrieval systems, Q&A applications, and chatbots that can access your organization’s information.