Source code for langchain.embeddings.baidu_qianfan_endpoint
from __future__ import annotations
import logging
from typing import Any, Dict, List, Optional
from langchain.pydantic_v1 import BaseModel, root_validator
from langchain.schema.embeddings import Embeddings
from langchain.utils import get_from_dict_or_env
logger = logging.getLogger(__name__)
[docs]class QianfanEmbeddingsEndpoint(BaseModel, Embeddings):
    """`Baidu Qianfan Embeddings` embedding models."""
    qianfan_ak: Optional[str] = None
    """Qianfan application apikey"""
    qianfan_sk: Optional[str] = None
    """Qianfan application secretkey"""
    chunk_size: int = 16
    """Chunk size when multiple texts are input"""
    model: str = "Embedding-V1"
    """Model name
    you could get from https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlks5zkzu
    
    for now, we support Embedding-V1 and 
    - Embedding-V1 （默认模型）
    - bge-large-en
    - bge-large-zh
    
    preset models are mapping to an endpoint.
    `model` will be ignored if `endpoint` is set
    """
    endpoint: str = ""
    """Endpoint of the Qianfan Embedding, required if custom model used."""
    client: Any
    """Qianfan client"""
    max_retries: int = 5
    """Max reties times"""
    @root_validator()
    def validate_environment(cls, values: Dict) -> Dict:
        """
        Validate whether qianfan_ak and qianfan_sk in the environment variables or
        configuration file are available or not.