Add native Document Reranking support to langchain-openrouter

Proposing Native Document Reranking Support for langchain-openrouter

Target Namespace: libs/partners/openrouter
Base Interface Class: langchain_core.documents.BaseDocumentCompressor

Use Case

OpenRouter natively supports document reranking and context compression endpoints. Currently, developers building RAG architectures completely within the OpenRouter ecosystem are forced to split their integration pipelines—relying on langchain-openrouter for token generation, but dropping down to external third-party cross-encoder wrappers or generic OpenAI hacks just to handle document reranking.

Integrating a native reranker class directly into the existing langchain-openrouter partner package will unify dependency tracking and streamline context compression in retrieval chains.

Proposed API Interface

I suggest implementing a new OpenRouterRerank class inside a rerank.py module within libs/partners/openrouter/langchain_openrouter/:

from typing import Any, Sequence
from langchain_core.documents import BaseDocumentCompressor, Document
from pydantic import ConfigDict

class OpenRouterRerank(BaseDocumentCompressor):
    """OpenRouter document reranker integration."""
    
    model: str
    """Model name to use for reranking."""
    
    model_config = ConfigDict(
        extra="forbid",
        arbitrary_types_allowed=True,
    )

    def compress_documents(
        self,
        documents: Sequence[Document],
        query: str,
        callbacks: Any = None,
    ) -> Sequence[Document]:
        """Compress/rerank documents using the OpenRouter API."""
        # Mapping logic to OpenRouter's native rerank payload specs
        pass

Hello @Umar4880 ,
Better if you open this as an issue here Issues · langchain-ai/langchain · GitHub, describing your use case rather than here on the forum.

I did, but langchain-fleet bot closed it as not planned. Even this is request to add feature within existing lib partner.

@Umar4880 Can you please share the link to the closed issue?

Thankyou for assisting, i comment in the issue and maintainer open it back. But now the issue is when i make a pull request the bot again block the PR and asked for assigned link. I again comment to assigne issue ot me, let see what happens.

If you have any exprerience related to that, i would love to discuss.