langchain.embeddings.deepinfra.DeepInfraEmbeddings¶

class langchain.embeddings.deepinfra.DeepInfraEmbeddings(*, model_id: str = 'sentence-transformers/clip-ViT-B-32', normalize: bool = False, embed_instruction: str = 'passage: ', query_instruction: str = 'query: ', model_kwargs: Optional[dict] = None, deepinfra_api_token: Optional[str] = None)[source]¶

Bases: BaseModel, Embeddings

Deep Infra’s embedding inference service.

To use, you should have the environment variable DEEPINFRA_API_TOKEN set with your API token, or pass it as a named parameter to the constructor. There are multiple embeddings models available, see https://deepinfra.com/models?type=embeddings.

Example

from langchain.embeddings import DeepInfraEmbeddings
deepinfra_emb = DeepInfraEmbeddings(
    model_id="sentence-transformers/clip-ViT-B-32",
    deepinfra_api_token="my-api-key"
)
r1 = deepinfra_emb.embed_documents(
    [
        "Alpha is the first letter of Greek alphabet",
        "Beta is the second letter of Greek alphabet",
    ]
)
r2 = deepinfra_emb.embed_query(
    "What is the second letter of Greek alphabet"
)

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 deepinfra_api_token: Optional[str] = None¶
param embed_instruction: str = 'passage: '¶

Instruction used to embed documents.

param model_id: str = 'sentence-transformers/clip-ViT-B-32'¶

Embeddings model to use.

param model_kwargs: Optional[dict] = None¶

Other model keyword args

param normalize: bool = False¶

whether to normalize the computed embeddings

param query_instruction: str = 'query: '¶

Instruction used to embed the query.

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

Embed documents using a Deep Infra deployed 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 Deep Infra deployed 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 DeepInfraEmbeddings¶