LaserEmbeddings#

class langchain_community.embeddings.laser.LaserEmbeddings[source]#

Bases: BaseModel, Embeddings

LASER Language-Agnostic SEntence Representations. LASER is a Python library developed by the Meta AI Research team and used for creating multilingual sentence embeddings for over 147 languages as of 2/25/2024 See more documentation at: * facebookresearch/LASER * facebookresearch/LASER * https://arxiv.org/abs/2205.12654

To use this class, you must install the laser_encoders Python package.

pip install laser_encoders .. rubric:: Example

from laser_encoders import LaserEncoderPipeline encoder = LaserEncoderPipeline(lang=”eng_Latn”) embeddings = encoder.encode_sentences([β€œHello”, β€œWorld”])

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param lang: str | None = None#

The language or language code you’d like to use If empty, this implementation will default to using a multilingual earlier LASER encoder model (called laser2) Find the list of supported languages at facebookresearch/flores

async aembed_documents(texts: list[str]) β†’ list[list[float]]#

Asynchronous Embed search docs.

Parameters:

texts (list[str]) – List of text to embed.

Returns:

List of embeddings.

Return type:

list[list[float]]

async aembed_query(text: str) β†’ list[float]#

Asynchronous Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

list[float]

embed_documents(texts: List[str]) β†’ List[List[float]][source]#

Generate embeddings for documents using LASER.

Parameters:

texts (List[str]) – The list of texts to embed.

Returns:

List of embeddings, one for each text.

Return type:

List[List[float]]

embed_query(text: str) β†’ List[float][source]#

Generate single query text embeddings using LASER.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

List[float]

classmethod validate_environment(values: Dict) β†’ Dict[source]#

Validate that laser_encoders has been installed.

Parameters:

values (Dict)

Return type:

Dict

Examples using LaserEmbeddings