SparkLLMTextEmbeddings#
- class langchain_community.embeddings.sparkllm.SparkLLMTextEmbeddings[source]#
Bases:
BaseModel
,Embeddings
SparkLLM embedding model integration.
- Setup:
To use, you should have the environment variable “SPARK_APP_ID”,”SPARK_API_KEY” and “SPARK_API_SECRET” set your APP_ID, API_KEY and API_SECRET or pass it as a name parameter to the constructor.
export SPARK_APP_ID="your-api-id" export SPARK_API_KEY="your-api-key" export SPARK_API_SECRET="your-api-secret"
- Key init args — completion params:
- api_key: Optional[str]
Automatically inferred from env var SPARK_API_KEY if not provided.
- app_id: Optional[str]
Automatically inferred from env var SPARK_APP_ID if not provided.
- api_secret: Optional[str]
Automatically inferred from env var SPARK_API_SECRET if not provided.
- base_url: Optional[str]
Base URL path for API requests.
See full list of supported init args and their descriptions in the params section.
Instantiate:
from langchain_community.embeddings import SparkLLMTextEmbeddings embed = SparkLLMTextEmbeddings( api_key="...", app_id="...", api_secret="...", # other )
- Embed single text:
input_text = "The meaning of life is 42" embed.embed_query(input_text)
[-0.4912109375, 0.60595703125, 0.658203125, 0.3037109375, 0.6591796875, 0.60302734375, ...]
- Embed multiple text:
input_texts = ["This is a test query1.", "This is a test query2."] embed.embed_documents(input_texts)
[ [-0.1962890625, 0.94677734375, 0.7998046875, -0.1971435546875, 0.445556640625, 0.54638671875, ...], [ -0.44970703125, 0.06585693359375, 0.7421875, -0.474609375, 0.62353515625, 1.0478515625, ...], ]
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 base_url: str = 'https://emb-cn-huabei-1.xf-yun.com/'#
Base URL path for API requests
- param domain: Literal['para', 'query'] = 'para'#
This parameter is used for which Embedding this time belongs to. If “para”(default), it belongs to document Embedding. If “query”, it belongs to query Embedding.
- param spark_api_key: SecretStr | None [Optional] (alias 'api_key')#
Automatically inferred from env var SPARK_API_KEY if not provided.
- Constraints:
type = string
writeOnly = True
format = password
- param spark_api_secret: SecretStr | None [Optional] (alias 'api_secret')#
Automatically inferred from env var SPARK_API_SECRET if not provided.
- Constraints:
type = string
writeOnly = True
format = password
- param spark_app_id: SecretStr [Optional] (alias 'app_id')#
Automatically inferred from env var SPARK_APP_ID if not provided.
- Constraints:
type = string
writeOnly = True
format = password
- 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
Examples using SparkLLMTextEmbeddings