2024-04-09 00:50:23 +00:00
|
|
|
"""**Cross encoders** are wrappers around cross encoder models from different APIs and
|
2024-03-31 20:51:31 +00:00
|
|
|
services.
|
|
|
|
|
|
|
|
**Cross encoder models** can be LLMs or not.
|
|
|
|
|
|
|
|
**Class hierarchy:**
|
|
|
|
|
|
|
|
.. code-block::
|
|
|
|
|
|
|
|
BaseCrossEncoder --> <name>CrossEncoder # Examples: SagemakerEndpointCrossEncoder
|
|
|
|
"""
|
2024-04-09 00:50:23 +00:00
|
|
|
import importlib
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from langchain_community.cross_encoders.base import (
|
2024-04-30 17:13:48 +00:00
|
|
|
BaseCrossEncoder,
|
2024-04-09 00:50:23 +00:00
|
|
|
)
|
|
|
|
from langchain_community.cross_encoders.fake import (
|
2024-04-30 17:13:48 +00:00
|
|
|
FakeCrossEncoder,
|
2024-04-09 00:50:23 +00:00
|
|
|
)
|
|
|
|
from langchain_community.cross_encoders.huggingface import (
|
2024-04-30 17:13:48 +00:00
|
|
|
HuggingFaceCrossEncoder,
|
2024-04-09 00:50:23 +00:00
|
|
|
)
|
|
|
|
from langchain_community.cross_encoders.sagemaker_endpoint import (
|
2024-04-30 17:13:48 +00:00
|
|
|
SagemakerEndpointCrossEncoder,
|
2024-04-09 00:50:23 +00:00
|
|
|
)
|
2024-03-31 20:51:31 +00:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"BaseCrossEncoder",
|
|
|
|
"FakeCrossEncoder",
|
|
|
|
"HuggingFaceCrossEncoder",
|
|
|
|
"SagemakerEndpointCrossEncoder",
|
|
|
|
]
|
2024-04-09 00:50:23 +00:00
|
|
|
|
|
|
|
_module_lookup = {
|
|
|
|
"BaseCrossEncoder": "langchain_community.cross_encoders.base",
|
|
|
|
"FakeCrossEncoder": "langchain_community.cross_encoders.fake",
|
|
|
|
"HuggingFaceCrossEncoder": "langchain_community.cross_encoders.huggingface",
|
|
|
|
"SagemakerEndpointCrossEncoder": "langchain_community.cross_encoders.sagemaker_endpoint", # noqa: E501
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
|
|
if name in _module_lookup:
|
|
|
|
module = importlib.import_module(_module_lookup[name])
|
|
|
|
return getattr(module, name)
|
|
|
|
raise AttributeError(f"module {__name__} has no attribute {name}")
|