langchain.embeddings.localai.LocalAIEmbeddings¶
- class langchain.embeddings.localai.LocalAIEmbeddings(*, client: Any = None, model: str = 'text-embedding-ada-002', deployment: str = 'text-embedding-ada-002', openai_api_version: Optional[str] = None, openai_api_base: Optional[str] = None, openai_proxy: Optional[str] = None, embedding_ctx_length: int = 8191, openai_api_key: Optional[str] = None, openai_organization: Optional[str] = None, allowed_special: Union[Literal['all'], Set[str]] = {}, disallowed_special: Union[Literal['all'], Set[str], Sequence[str]] = 'all', chunk_size: int = 1000, max_retries: int = 6, request_timeout: Optional[Union[float, Tuple[float, float]]] = None, headers: Any = None, show_progress_bar: bool = False, model_kwargs: Dict[str, Any] = None)[source]¶
Bases:
BaseModel,EmbeddingsLocalAI embedding models.
To use, you should have the
openaipython package installed, and the environment variableOPENAI_API_KEYset to a random string. You need to specifyOPENAI_API_BASEto point to your LocalAI service endpoint.Example
from langchain.embeddings import LocalAIEmbeddings openai = LocalAIEmbeddings( openai_api_key="random-key", openai_api_base="http://localhost:8080" )
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 allowed_special: Union[Literal['all'], Set[str]] = {}¶
- param chunk_size: int = 1000¶
Maximum number of texts to embed in each batch
- param deployment: str = 'text-embedding-ada-002'¶
- param disallowed_special: Union[Literal['all'], Set[str], Sequence[str]] = 'all'¶
- param embedding_ctx_length: int = 8191¶
The maximum number of tokens to embed at once.
- param headers: Any = None¶
- param max_retries: int = 6¶
Maximum number of retries to make when generating.
- param model: str = 'text-embedding-ada-002'¶
- param model_kwargs: Dict[str, Any] [Optional]¶
Holds any model parameters valid for create call not explicitly specified.
- param openai_api_base: Optional[str] = None¶
- param openai_api_key: Optional[str] = None¶
- param openai_api_version: Optional[str] = None¶
- param openai_organization: Optional[str] = None¶
- param openai_proxy: Optional[str] = None¶
- param request_timeout: Optional[Union[float, Tuple[float, float]]] = None¶
Timeout in seconds for the LocalAI request.
- param show_progress_bar: bool = False¶
Whether to show a progress bar when embedding.
- async aembed_documents(texts: List[str], chunk_size: Optional[int] = 0) List[List[float]][source]¶
Call out to LocalAI’s embedding endpoint async for embedding search docs.
- Parameters
texts – 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.
- async aembed_query(text: str) List[float][source]¶
Call out to LocalAI’s embedding endpoint async for embedding query text.
- Parameters
text – The text to embed.
- Returns
Embedding for the text.
- validator build_extra » all fields[source]¶
Build extra kwargs from additional params that were passed in.
- embed_documents(texts: List[str], chunk_size: Optional[int] = 0) List[List[float]][source]¶
Call out to LocalAI’s embedding endpoint for embedding search docs.
- Parameters
texts – 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.
- embed_query(text: str) List[float][source]¶
Call out to LocalAI’s embedding endpoint for embedding query text.
- Parameters
text – The text to embed.
- Returns
Embedding for the text.