ZhipuAIEmbeddings#
- class langchain_community.embeddings.zhipuai.ZhipuAIEmbeddings[source]#
Bases:
BaseModel
,Embeddings
ZhipuAI embedding model integration.
Setup:
To use, you should have the
zhipuai
python package installed, and the environment variableZHIPU_API_KEY
set with your API KEY.More instructions about ZhipuAi Embeddings, you can get it from https://open.bigmodel.cn/dev/api#vector
pip install -U zhipuai export ZHIPU_API_KEY="your-api-key"
- Key init args β completion params:
- model: Optional[str]
Name of ZhipuAI model to use.
- api_key: str
Automatically inferred from env var ZHIPU_API_KEY if not provided.
See full list of supported init args and their descriptions in the params section.
Instantiate:
from langchain_community.embeddings import ZhipuAIEmbeddings embed = ZhipuAIEmbeddings( model="embedding-2", # api_key="...", )
- Embed single text:
input_text = "The meaning of life is 42" embed.embed_query(input_text)
[-0.003832892, 0.049372625, -0.035413884, -0.019301128, 0.0068899863, 0.01248398, -0.022153955, 0.006623926, 0.00778216, 0.009558191, ...]
- Embed multiple text:
input_texts = ["This is a test query1.", "This is a test query2."] embed.embed_documents(input_texts)
[ [0.0083934665, 0.037985895, -0.06684559, -0.039616987, 0.015481004, -0.023952313, ...], [-0.02713102, -0.005470169, 0.032321047, 0.042484466, 0.023290444, 0.02170547, ...] ]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- param api_key: str [Required]#
Automatically inferred from env var ZHIPU_API_KEY if not provided.
- param dimensions: int | None = None#
The number of dimensions the resulting output embeddings should have.
Only supported in embedding-3 and later models.
- param model: str = 'embedding-2'#
Model name
- 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]#
Embeds a list of text documents using the AutoVOT algorithm.
- Parameters:
texts (List[str]) β A list of text documents to embed.
- Returns:
A list of embeddings for each document in the input list. Each embedding is represented as a list of float values.
- Return type:
List[List[float]]