Skip to main content
Agentset provides built-in reranking, but you can also implement custom ranking logic to tune results for your specific use case.

Built-in reranking

Agentset reranks results by default using a cross-encoder model. Configure this behavior in your search request.
const results = await ns.search("product features", {
  topK: 50,
  rerank: true,
  rerankLimit: 10,
  rerankModel: "cohere:rerank-v3.5",
});
See Search for available rerank models and parameters.

Custom score weighting

Apply weights to boost or penalize results based on metadata. This is useful when certain document types should rank higher or lower for your use case.
const results = await ns.search(query, { topK: 20 });

// Apply weights based on document type
const weighted = results
  .map((result) => {
    let weight = 1.0;

    // Boost official documentation
    if (result.metadata?.category === "official-docs") {
      weight = 1.2;
    }

    // Penalize older content
    if (result.metadata?.year < 2023) {
      weight = 0.8;
    }

    return {
      ...result,
      weightedScore: result.score * weight,
    };
  })
  .sort((a, b) => b.weightedScore - a.weightedScore);

Combining strategies

Combine reranking with custom weighting for fine-grained control.
// 1. Get reranked results
const results = await ns.search(query, {
  topK: 50,
  rerank: true,
  rerankLimit: 20,
});

// 2. Apply custom weights
const final = results
  .map((result) => {
    let score = result.score;

    // Apply domain-specific weighting
    if (result.metadata?.docType === "faq") {
      score *= 1.1; // Boost FAQs
    }

    return { ...result, finalScore: score };
  })
  .sort((a, b) => b.finalScore - a.finalScore)
  .slice(0, 10);

Next steps