A Namespace in Agentset organizes your documents and provides a context for RAG operations. Here’s how to create one:
// Create a namespaceconst namespace =await agentset.namespaces.create({ name:"Company Documentation",// Optional: provide custom embedding model embeddingConfig:{ provider:"OPENAI", model:"text-embedding-3-small", apiKey:"your_openai_api_key_here",},});console.log(`Namespace created with ID: ${namespace.id}`);
Next, create an ingest job to upload documents to your namespace:
// Get a namespace by ID or slugconst ns = agentset.namespace("company-documentation");// Upload documents to your namespaceconst ingestJob =await ns.ingestion.create({ payload:{ type:"FILE", fileUrl:"https://example.com/annual-report-2024.pdf", name:"Annual Report 2024"}, config:{ metadata:{ documentType:"financial", year:2024}}});console.log(`Ingest job created with ID: ${ingestJob.id}`);console.log(`Processing document: ${ingestJob.payload.name}`);
// Search the namespaceconst searchResults =await ns.search("financial metrics 2024",{ topK:5, rerank:true, includeMetadata:true});console.log("Search results:", searchResults.data);// Or have a conversation with your documentsconst chatResponse =await ns.chat("What were our key financial metrics for 2024?",{ messages:[{ role:"user", content:"What were our key financial metrics for 2024?"}], topK:10, rerank:true});console.log("Answer:", chatResponse.data.text);console.log("Sources:", chatResponse.data.sources);
For more advanced examples and complete workflows, check out our Examples page.