langchain.embeddings.mosaicml.MosaicMLInstructorEmbeddings¶

class langchain.embeddings.mosaicml.MosaicMLInstructorEmbeddings(*, endpoint_url: str = 'https://models.hosted-on.mosaicml.hosting/instructor-xl/v1/predict', embed_instruction: str = 'Represent the document for retrieval: ', query_instruction: str = 'Represent the question for retrieving supporting documents: ', retry_sleep: float = 1.0, mosaicml_api_token: Optional[str] = None)[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.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: Optional[str] = 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

embed_documents(texts: List[str]) List[List[float]][source]¶

Embed documents using a MosaicML deployed instructor embedding model.

Parameters

texts – The list of texts to embed.

Returns

List of embeddings, one for each text.

embed_query(text: str) List[float][source]¶

Embed a query using a MosaicML deployed instructor embedding model.

Parameters

text – The text to embed.

Returns

Embeddings for the text.

validator validate_environment  »  all fields[source]¶

Validate that api key and python package exists in environment.

model Config[source]¶

Bases: object

Configuration for this pydantic object.

extra = 'forbid'¶

Examples using MosaicMLInstructorEmbeddings¶