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][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 baichuan_api_key: SecretStr [Optional] (alias 'api_key')#

Automatically inferred from env var BAICHUAN_API_KEY if not provided.

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