BaichuanTextEmbeddings#

class langchain_community.embeddings.baichuan.BaichuanTextEmbeddings[source]#

Bases: BaseModel, Embeddings

Baichuan Text Embedding models.

Setup:

To use, you should set the environment variable BAICHUAN_API_KEY to your API key or pass it as a named parameter to the constructor.

export BAICHUAN_API_KEY="your-api-key"
Instantiate:
from langchain_community.embeddings import BaichuanTextEmbeddings

embeddings = BaichuanTextEmbeddings()
Embed:
# embed the documents
vectors = embeddings.embed_documents([text1, text2, ...])

# embed the query
vectors = 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 baichuan_api_key: SecretStr | None [Optional] (alias 'api_key')#

Automatically inferred from env var BAICHUAN_API_KEY if not provided.

Constraints:
  • type = string

  • writeOnly = True

  • format = password

param chunk_size: int = 16#

Chunk size when multiple texts are input

param model_name: str = 'Baichuan-Text-Embedding' (alias 'model')#

The model used to embed the documents.

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]] | None[source]#

Public method to get embeddings for a list of documents.

Parameters:

texts (List[str]) – The list of texts to embed.

Returns:

A list of embeddings, one for each text, or None if an error occurs.

Return type:

List[List[float]] | None

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

Public method to get embedding for a single query text.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text, or None if an error occurs.

Return type:

List[float] | None

Examples using BaichuanTextEmbeddings