Skip to main content

langchain-reranker

PyPI version PyPI - Python Version License: MIT

Add init_reranker to the LangChain ecosystem, following the same conventions as init_chat_model and init_embeddings.

Installation

Available on PyPI:

pip install langchain-reranker

Provider integration packages are optional and installed on demand, e.g. pip install langchain-cohere.

Usage

from langchain_reranker.rerankers import init_reranker

reranker = init_reranker("cohere:rerank-v3.5")

compressed = reranker.compress_documents(documents, query="what is langchain?")

init_reranker returns a BaseDocumentCompressor, so it plugs directly into existing retrieval pipelines such as a contextual compression retriever.

reranker = init_reranker(model="jina-reranker-v2-base-multilingual", provider="jina")

Custom rerankers

Implement rerank and inherit compress_documents for free.

from langchain_reranker.rerankers import BaseReranker, RerankResult


class MyReranker(BaseReranker):
    model: str = "my-reranker"

    def rerank(self, query, documents, top_n=None):
        scores = my_api(query, [doc.page_content for doc in documents])
        ranked = sorted(zip(documents, scores), key=lambda pair: -pair[1])
        return [
            RerankResult(index=i, relevance_score=float(score), document=doc)
            for i, (doc, score) in enumerate(ranked)
        ]

Local cross encoders

reranker = init_reranker("huggingface:BAAI/bge-reranker-v2-m3")

Metadata

Release files for langchain-reranker 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-reranker 0.1.4
File Size Uploaded Provenance
langchain_reranker-0.1.4.tar.gz 7.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-reranker 0.1.4
File Interpreter ABI Platform
langchain_reranker-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / langchain_reranker-0.1.4.tar.gz

Download URL langchain_reranker-0.1.4.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
91d7875ea4a5f77a9e9223b43f4c91284d9431010459c84a126ce4893d5b4351
BLAKE2b-256 checksum
How to use checksums
3d29c2fb4e3b62c65682011c6508d809209e5219ac854c3c83fd6b686cd11279
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / langchain_reranker-0.1.4-py3-none-any.whl

Download URL langchain_reranker-0.1.4-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5e35165fa220f8f532b1542a4dc55a8da808d16faad735b88da20be5b3baaaf
BLAKE2b-256 checksum
How to use checksums
7479213cf7c82cdef95bb258cac08726847457539436ca9751057225932d430f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for langchain-reranker 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page