Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentset.ai/llms.txt

Use this file to discover all available pages before exploring further.

Search your namespace to retrieve relevant chunks from your documents. Agentset uses semantic and keyword search to return the most relevant results. Pass a query string to search your namespace and retrieve chunks.
import { Agentset } from "agentset";

const agentset = new Agentset({
  apiKey: process.env.AGENTSET_API_KEY,
});

const ns = agentset.namespace("YOUR_NAMESPACE_ID");

const results = await ns.search("What is machine learning?");

for (const result of results) {
  console.log(result.text);
}

Limiting results

Control the number of results returned with topK. The default is 10, with a maximum of 100.
const results = await ns.search("quarterly revenue", {
  topK: 20,
});

Reranking

Agentset reranks results by default using a cross-encoder model to improve relevance. You can adjust reranking behavior or disable it.
const results = await ns.search("product roadmap", {
  topK: 50,
  rerank: true,
  rerankLimit: 10,
});
ParameterDefaultDescription
reranktrueEnable or disable reranking
rerankLimitSame as topKNumber of results to return after reranking
rerankModelcohere:rerank-v3.5Model used for reranking

Available rerank models

ModelDescription
cohere:rerank-v3.5Latest Cohere reranker (default)
cohere:rerank-english-v3.0English-optimized Cohere reranker
cohere:rerank-multilingual-v3.0Multilingual Cohere reranker
zeroentropy:zerank-1ZeroEntropy reranker
zeroentropy:zerank-1-smallSmaller, faster ZeroEntropy reranker

Minimum score threshold

Filter out low-relevance results by setting a minimum score.
const results = await ns.search("API documentation", {
  minScore: 0.7,
});

Search modes

Agentset supports two search modes.
const results = await ns.search("error code 500", {
  mode: "keyword",
});
ModeDescription
semanticUses embeddings to find semantically similar content (default)
keywordTraditional keyword-based search

Response structure

Each result includes an ID, relevance score, and text content. Metadata is included by default.
{
  "success": true,
  "data": [
    {
      "id": "chunk_abc123",
      "score": 0.92,
      "text": "Machine learning is a subset of artificial intelligence...",
      "metadata": {
        "filename": "ml-guide.pdf",
        "filetype": "application/pdf",
        "file_directory": "/documents"
      }
    }
  ]
}

Excluding metadata

const results = await ns.search("user authentication", {
  includeMetadata: false,
});

Next steps