Skip to main content

vai rerank

Rerank a set of documents against a query using Voyage AI's cross-encoder reranking models.

Synopsis

vai rerank --query <text> [options]

Description

vai rerank takes a query and a set of documents, then re-scores each document by relevance using a cross-attention model. Unlike embedding-based search (which encodes query and document independently), reranking reads the query and each document together for higher-precision relevance scores.

Documents can be provided via --documents, --documents-file, or piped through stdin.

Options

FlagDescriptionDefault
--query <text>Search query (required)
--documents <docs...>Documents to rerank (inline, space-separated)
--documents-file <path>File with documents (JSON array or newline-delimited)
-m, --model <model>Reranking modelrerank-2.5
-k, --top-k <n>Return only top K resultsAll
--truncationEnable truncation for long inputs
--no-truncationDisable truncation
--return-documentsInclude document text in results
--estimateShow estimated tokens and cost without calling the API
--jsonMachine-readable JSON output
-q, --quietSuppress non-essential output

Examples

Rerank inline documents

vai rerank --query "vector search" \
--documents "MongoDB Atlas supports vector search" \
"PostgreSQL is a relational database" \
"Embeddings capture semantic meaning"

Rerank from a file

vai rerank --query "How do I deploy?" --documents-file candidates.json --top-k 3

Pipe documents from another command

cat search-results.json | vai rerank --query "deployment best practices"

Use the lite reranker for lower cost

vai rerank --query "authentication" --documents-file docs.txt --model rerank-2.5-lite

Get JSON output with document text included

vai rerank --query "scaling" --documents-file docs.json --return-documents --json

Tips

  • Reranking is most effective as a second stage after vector search. Use vai query to combine both stages automatically.
  • The --documents-file (CLI) accepts JSON arrays, newline-delimited text, or JSONL with a text field.
  • rerank-2.5 gives the best quality; rerank-2.5-lite is faster and cheaper for high-throughput use cases.