langchain.embeddings.dashscope.DashScopeEmbeddings¶

class langchain.embeddings.dashscope.DashScopeEmbeddings(*, client: Any = None, model: str = 'text-embedding-v1', dashscope_api_key: Optional[str] = None, max_retries: int = 5)[source]¶

Bases: BaseModel, Embeddings

DashScope embedding models.

To use, you should have the dashscope python package installed, and the environment variable DASHSCOPE_API_KEY set with your API key or pass it as a named parameter to the constructor.

Example

from langchain.embeddings import DashScopeEmbeddings
embeddings = DashScopeEmbeddings(dashscope_api_key="my-api-key")

Example

import os
os.environ["DASHSCOPE_API_KEY"] = "your DashScope API KEY"

from langchain.embeddings.dashscope import DashScopeEmbeddings
embeddings = DashScopeEmbeddings(
    model="text-embedding-v1",
)
text = "This is a test query."
query_result = embeddings.embed_query(text)

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 client: Any = None¶

The DashScope client.

param dashscope_api_key: Optional[str] = None¶
param max_retries: int = 5¶

Maximum number of retries to make when generating.

param model: str = 'text-embedding-v1'¶
embed_documents(texts: List[str]) List[List[float]][source]¶

Call out to DashScope’s embedding endpoint for embedding search docs.

Parameters
  • texts – The list of texts to embed.

  • chunk_size – The chunk size of embeddings. If None, will use the chunk size specified by the class.

Returns

List of embeddings, one for each text.

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

Call out to DashScope’s embedding endpoint for embedding query text.

Parameters

text – The text to embed.

Returns

Embedding for the text.

validator validate_environment  »  all fields[source]¶
model Config[source]¶

Bases: object

Configuration for this pydantic object.

extra = 'forbid'¶

Examples using DashScopeEmbeddings¶