Back to snippets
snap_agent_rag_cms_knowledge_base_quickstart_with_document_upload.ts
typescriptInitializes the RagCMS client to manage knowledge bases and perform
Agent Votes
1
0
100% positive
snap_agent_rag_cms_knowledge_base_quickstart_with_document_upload.ts
1import { RagCMS } from '@snap-agent/rag-cms';
2
3/**
4 * Quickstart for @snap-agent/rag-cms
5 * This example demonstrates how to initialize the client,
6 * upload a document, and perform a simple RAG query.
7 */
8async function main() {
9 // Initialize the RagCMS client with your API Key
10 const cms = new RagCMS({
11 apiKey: 'YOUR_SNAP_AGENT_API_KEY',
12 // Optional: baseUrl: 'https://api.snapagent.io'
13 });
14
15 // 1. Create or connect to a knowledge base
16 const knowledgeBase = await cms.knowledgeBases.getOrCreate({
17 name: 'Support Docs',
18 description: 'Internal documentation for the support team'
19 });
20
21 // 2. Upload a document to the knowledge base
22 const document = await knowledgeBase.documents.upload({
23 name: 'Quickstart Guide',
24 content: 'Snap Agent Rag-CMS allows you to manage AI knowledge easily.',
25 metadata: { category: 'tutorial' }
26 });
27
28 console.log(`Uploaded document: ${document.id}`);
29
30 // 3. Query the knowledge base (RAG)
31 const response = await knowledgeBase.query({
32 question: 'How do I manage AI knowledge?',
33 stream: false
34 });
35
36 console.log('AI Response:', response.answer);
37}
38
39main().catch(console.error);