MosaicMLInstructorEmbeddings#

class langchain_community.embeddings.mosaicml.MosaicMLInstructorEmbeddings[source]#

Bases: BaseModel, Embeddings

MosaicML embedding service.

To use, you should have the environment variable MOSAICML_API_TOKEN set with your API token, or pass it as a named parameter to the constructor.

Example

from langchain_community.llms import MosaicMLInstructorEmbeddings
endpoint_url = (
    "https://models.hosted-on.mosaicml.hosting/instructor-large/v1/predict"
)
mosaic_llm = MosaicMLInstructorEmbeddings(
    endpoint_url=endpoint_url,
    mosaicml_api_token="my-api-key"
)

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

Raises ValidationError if the input data cannot be parsed to form a valid model.

param embed_instruction: str = 'Represent the document for retrieval: '#

Instruction used to embed documents.

param endpoint_url: str = 'https://models.hosted-on.mosaicml.hosting/instructor-xl/v1/predict'#

Endpoint URL to use.

param mosaicml_api_token: str | None = None#
param query_instruction: str = 'Represent the question for retrieving supporting documents: '#

Instruction used to embed the query.

param retry_sleep: float = 1.0#

How long to try sleeping for if a rate limit is encountered

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]#

Embed documents using a MosaicML deployed instructor embedding model.

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]#

Embed a query using a MosaicML deployed instructor embedding model.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

List[float]

Examples using MosaicMLInstructorEmbeddings