DashScopeEmbeddings#

class langchain_community.embeddings.dashscope.DashScopeEmbeddings[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_community.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_community.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: str | None = None#
param max_retries: int = 5#

Maximum number of retries to make when generating.

param model: str = 'text-embedding-v1'#
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]#

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

Parameters:
  • texts (List[str]) – 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.

Return type:

List[List[float]]

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

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

Parameters:

text (str) – The text to embed.

Returns:

Embedding for the text.

Return type:

List[float]

Examples using DashScopeEmbeddings