Installation
Basic Usage
Creating an Ingest Job
Here’s how you can use the Agentset TypeScript SDK to create an ingest job:
import { Agentset } from 'agentset';
const agentset = new Agentset({
apiKey: process.env.AGENTSET_API_KEY,
});
const ns = agentset.namespace('ns_123');
// Create an ingest job
const job = 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(`Job created with ID: ${job.id}`);
Ingest jobs are processed asynchronously. After creating a job, you’ll need to check its
status to know when processing is complete.
Checking Job Status
Since ingestion is asynchronous, you can check the status of your job:
// Get the job status
let currentJob = await ns.ingestion.get(job.id);
console.log(`Job status: ${currentJob.status}`);
// Poll for completion
while (currentJob.status !== 'COMPLETED' && currentJob.status !== 'FAILED') {
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds
currentJob = await ns.ingestion.get(job.id);
console.log(`Job status: ${currentJob.status}`);
}
console.log(`Job status: ${currentJob.status}`);
Searching Documents
Once your documents are ingested, you can search through them:
// Perform a search
const searchResults = await ns.search('financial performance Q4 2024', {
topK: 20,
rerank: true,
rerankLimit: 10,
includeMetadata: true,
filters: {
$or: [{ documentType: 'financial' }, { year: { $gte: 2024 } }],
},
});
// Process results
searchResults.forEach(result => {
console.log(`Score: ${result.score}`);
console.log(`Content: ${result.text}`);
console.log(`Metadata: ${JSON.stringify(result.metadata)}`);
console.log('---');
});
Additional Resources