Skip to content

LangChain

LangChainBridgeMixin

Bases: BaseBridgeMixin

LangChain Bridge.

This mixin adds LangChain conversion capabilities to _RAGSystem. When mixed with an unbridged _RAGSystem, it allows direct conversion to LangChain's VectorStore and BaseLLM through the to_langchain() method.

Source code in src/fed_rag/_bridges/langchain/bridge.py
class LangChainBridgeMixin(BaseBridgeMixin):
    """LangChain Bridge.

    This mixin adds LangChain conversion capabilities to _RAGSystem.
    When mixed with an unbridged _RAGSystem, it allows direct conversion to
    LangChain's VectorStore and BaseLLM through the to_langchain() method.
    """

    _bridge_version = __version__
    _bridge_extra = "langchain"
    _framework = "langchain-core"
    _compatible_versions = {"min": "0.3.62"}
    _method_name = "to_langchain"

    def to_langchain(self: "_RAGSystem") -> tuple["VectorStore", "BaseLLM"]:
        """Converts the _RAGSystem to a tuple of ~langchain_core.vectorstores.VectorStore and ~langchain_core.language_models.BaseLLM."""
        self._validate_framework_installed()

        from fed_rag._bridges.langchain._bridge_classes import (
            FedRAGLLM,
            FedRAGVectorStore,
        )

        return FedRAGVectorStore(self), FedRAGLLM(self)

to_langchain

to_langchain()

Converts the _RAGSystem to a tuple of ~langchain_core.vectorstores.VectorStore and ~langchain_core.language_models.BaseLLM.

Source code in src/fed_rag/_bridges/langchain/bridge.py
def to_langchain(self: "_RAGSystem") -> tuple["VectorStore", "BaseLLM"]:
    """Converts the _RAGSystem to a tuple of ~langchain_core.vectorstores.VectorStore and ~langchain_core.language_models.BaseLLM."""
    self._validate_framework_installed()

    from fed_rag._bridges.langchain._bridge_classes import (
        FedRAGLLM,
        FedRAGVectorStore,
    )

    return FedRAGVectorStore(self), FedRAGLLM(self)