Installation

Install the Agentset SDK with your preferred package manager:

npm install agentset

Authentication

To use Agentset, you’ll need an API key. You can get one by signing up on the Agentset Dashboard.

import { Agentset } from 'agentset';

// Initialize the client with your API key
const agentset = new Agentset({
  apiKey: 'your_api_key',
});

Creating Your First Namespace

A Namespace in Agentset organizes your documents and provides a context for RAG operations. Here’s how to create one:

// Create a namespace
const 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}`);

Uploading Documents

Next, create an ingest job to upload documents to your namespace:

// Get a namespace by ID or slug
const ns = agentset.namespace("company-documentation");

// Upload documents to your namespace
const 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}`);

Searching and Chatting with Your Documents

Now you can search or chat with your documents:

// Search the namespace
const 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 documents
const 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.

Next Steps