Client Referenceencoders
semantic_router.encoders.litellm
litellm_to_list
def litellm_to_list(embeds: "litellm.EmbeddingResponse") -> list[list[float]]Convert a LiteLLM embedding response to a list of embeddings.
Arguments:
embeds: The LiteLLM embedding response.
Returns:
A list of embeddings.
LiteLLMEncoder Objects
class LiteLLMEncoder(DenseEncoder, AsymmetricDenseMixin)LiteLLM encoder class for generating embeddings using LiteLLM.
The LiteLLMEncoder class is a subclass of DenseEncoder and utilizes the LiteLLM SDK to generate embeddings for given documents. It supports all encoders supported by LiteLLM.
litellm is an optional dependency: install it with
pip install "semantic-router[litellm]".
__init__
def __init__(name: str | None = None, api_key: str | None = None)Initialize the LiteLLMEncoder.
Arguments:
name(str): The name of the embedding model to use. Must use LiteLLM naming convention (e.g. "openai/text-embedding-3-small" or "mistral/mistral-embed").
Raises:
ImportError: If litellm is not installed.
__call__
def __call__(docs: list[Any], **kwargs) -> list[list[float]]Encode a list of text documents into embeddings using LiteLLM.
Arguments:
docs: List of text documents to encode.
Returns:
List of embeddings for each document.
acall
async def acall(docs: list[Any], **kwargs) -> list[list[float]]Encode a list of documents into embeddings using LiteLLM asynchronously.
Arguments:
docs: List of documents to encode.
Returns:
List of embeddings for each document.