rerank_stage#
- langchain_mongodb.pipelines.rerank_stage(query: str, path: str | List[str], num_docs_to_rerank: int, model: str | None = None) List[Dict[str, Any]][source]#
$rerank aggregation stage for Native Reranking in Atlas.
Requires MongoDB 8.3+ and Native Reranking enabled via Atlas Project Settings. Best used after a $search, $vectorSearch, $rankFusion, or $scoreFusion stage.
Will migrate to pymongo_search_utils once available there. (PYTHON-5876)
- Parameters:
query (str) – Text query used for reranking
path (str | List[str]) – Field or list of fields to rerank on
num_docs_to_rerank (int) – Number of documents to pass to the reranker (max 1000)
model (str | None) – Voyage AI reranking model (e.g. “rerank-2.5”, “rerank-2”, “rerank-2.5-lite”). Omit to use the latest available model.
- Returns:
$rerank followed by $set to update the score field
- Return type:
List of pipeline stages