Client Referenceencoders
semantic_router.encoders.fastembed
FastEmbedEncoder Objects
class FastEmbedEncoder(DenseEncoder)Dense encoder that uses local FastEmbed to embed documents. Supports text only.
Requires the fastembed package which can be installed with pip install 'semantic-router[fastembed]'
Arguments:
name: The name of the embedding model to use.max_length: The maximum length of the input text.cache_dir: The directory to cache the embedding model.threads: The number of threads to use for the embedding.
__init__
def __init__(**data)Initialize the FastEmbed encoder.
__call__
def __call__(docs: List[str]) -> List[List[float]]Embed a list of documents. Supports text only.
Arguments:
docs(List[str]): The documents to embed.
Raises:
ValueError: If the embedding fails.
Returns:
List[List[float]]: The vector embeddings of the documents.
acall
async def acall(docs: List[str]) -> List[List[float]]Embed a list of documents asynchronously. Supports text only.
FastEmbed itself is synchronous, so this offloads the embedding call to a thread to avoid blocking the event loop.
Arguments:
docs(List[str]): The documents to embed.
Raises:
ValueError: If the embedding fails.
Returns:
List[List[float]]: The vector embeddings of the documents.