buster/packages/rerank
dal 2833c6bb0c
dry run
2025-07-25 18:29:35 -06:00
..
scripts Use tsx and .ts files for validation 2025-07-21 16:07:14 -06:00
src lint and slack 2025-07-18 10:49:34 -06:00
tests Remove old test files after moving to source directories 2025-07-17 16:14:13 +00:00
.env.example Mastra braintrust (#391) 2025-07-02 14:33:40 -07:00
.gitignore Enhance Slack event handling by adding hourglass reaction on app mentions and refactoring reaction management in slack-agent-task. Update CLAUDE.md and global.mdc with new guidelines for testing and development workflows. Adjust .gitignore for rerank package to ensure proper directory exclusion. 2025-07-18 21:40:20 -06:00
README.md Mastra braintrust (#391) 2025-07-02 14:33:40 -07:00
biome.json Mastra braintrust (#391) 2025-07-02 14:33:40 -07:00
env.d.ts Mastra braintrust (#391) 2025-07-02 14:33:40 -07:00
package.json dry run 2025-07-25 18:29:35 -06:00
tsconfig.json Update inlcude 2025-07-12 23:46:09 -06:00
vitest.config.ts Mastra braintrust (#391) 2025-07-02 14:33:40 -07:00

README.md

@buster/rerank

A TypeScript package for reranking search results using semantic relevance scoring via configurable reranking APIs.

Installation

bun add @buster/rerank

Configuration

The package requires the following environment variables:

  • RERANK_API_KEY - Your reranking API key
  • RERANK_BASE_URL - The base URL for the reranking API (e.g., https://api.cohere.ai/v1/rerank)
  • RERANK_MODEL - The model to use for reranking (e.g., rerank-english-v3.0)

Usage

Basic Usage

import { rerankResults } from '@buster/rerank';

const query = 'What is the capital of France?';
const documents = [
  'Paris is the capital of France',
  'London is the capital of England',
  'Berlin is the capital of Germany'
];

const results = await rerankResults(query, documents);
// Returns: [{ index: 0, relevance_score: 0.95 }, ...]

Using the Reranker Class

import { Reranker } from '@buster/rerank';

const reranker = new Reranker();
const results = await reranker.rerank(query, documents, topN);

Custom Configuration

import { Reranker } from '@buster/rerank';

const reranker = new Reranker({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.example.com/rerank',
  model: 'custom-model'
});

API

rerankResults(query, documents, topN?, config?)

Reranks documents based on relevance to a query.

  • query: The search query string
  • documents: Array of document strings to rerank
  • topN: Optional number of top results to return (defaults to 10 or document count)
  • config: Optional configuration override

Returns: Array of RerankResult objects with index and relevance_score

Error Handling

The package handles errors gracefully by returning all documents with equal relevance scores (1.0) when:

  • The API is unavailable
  • Invalid credentials are provided
  • Rate limits are exceeded
  • Network errors occur

Development

# Run tests
bun test

# Run tests in watch mode
bun test:watch

# Run tests with coverage
bun test:coverage

# Type checking
bun typecheck

# Linting
bun lint
bun lint:fix

# Formatting
bun format
bun format:fix

Testing

The package includes comprehensive unit and integration tests. Integration tests require valid API credentials and will be skipped if not available.