LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    Standard Tests
    Text Splitters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    Standard Tests
    Text Splitters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Language
    Theme
    Pythonlangchain-classicretrieversdocument_compressorscohere_rerankCohereRerankrerank
    Methodā—Since v1.0

    rerank

    Copy
    rerank(
      self,
      documents: Sequence[str | Document | dict],
      
    View source on GitHub
    query
    :
    str
    ,
    *
    ,
    model
    :
    str
    |
    None
    =
    None
    ,
    top_n
    :
    int
    |
    None
    =
    1
    ,
    max_chunks_per_doc
    :
    int
    |
    None
    =
    None
    )
    ->
    list
    [
    dict
    [
    str
    ,
    Any
    ]
    ]

    Parameters

    NameTypeDescription
    query*str

    The query to use for reranking.

    documents*Sequence[str | Document | dict]

    A sequence of documents to rerank.

    modelstr | None
    Default:None
    top_n *unknown
    max_chunks_per_doc *unknown

    Returns an ordered list of documents ordered by their relevance to the provided query.

    The model to use for re-ranking. Default to self.model.

    The number of results to return. If None returns all results.

    The maximum number of chunks derived from a document.