Appearance
Embedding Model Connectors
To compute vector representations of user questions and conversation logs for similarity searches, Elsai provides a modular embeddings interface under elsai.integrations.elsai_embeddings.
This module lets you build standalone embedding clients using AWS Bedrock or Azure OpenAI as backends.
Installation
To use embedding connectors, ensure you have the elsai-embeddings extra (or the standalone elsai-model package) installed:
bash
pip install --extra-index-url https://core-packages.elsai.ai/root/elsai-model/ elsai-modelEmbedding Clients Factory
Elsai provides two main entry-points to initialize embedding clients:
1. build_embedding_client(config: EmbeddingBackendConfig)
Initializes an embedding client from an explicit configuration object.
python
from elsai.integrations.elsai_embeddings import EmbeddingBackendConfig, build_embedding_client
config = EmbeddingBackendConfig(
provider="bedrock",
aws_region="us-east-1",
model_name="amazon.titan-embed-text-v1",
)
client = build_embedding_client(config)2. build_embedding_client_from_env(provider=None)
Loads credentials and backend settings directly from standard environment variables (e.g. EMBEDDING_PROVIDER="azure" or EMBEDDING_PROVIDER="bedrock").
python
import os
from elsai.integrations.elsai_embeddings import build_embedding_client_from_env
# Configure environment
os.environ["EMBEDDING_PROVIDER"] = "bedrock"
os.environ["AWS_REGION"] = "us-east-1"
os.environ["BEDROCK_EMBEDDING_MODEL_NAME"] = "amazon.titan-embed-text-v1"
# Initialize
client = build_embedding_client_from_env()Provider Support
Amazon Bedrock
AWS Bedrock hosting allows you to compute high-performance embeddings using models like Titan or Cohere Embed.
- Client configuration attributes (
EmbeddingBackendConfig):provider:"bedrock"model_name: Bedrock embedding model name. Defaults toBEDROCK_EMBEDDING_MODEL_NAMEenv var.aws_access_key_id: AWS Access Key. Defaults toAWS_ACCESS_KEY_IDenv var.aws_secret_access_key: AWS Secret Access Key. Defaults toAWS_SECRET_ACCESS_KEYenv var.aws_region: AWS Region. Defaults toAWS_REGIONenv var.
Example
python
from elsai.integrations.elsai_embeddings import EmbeddingBackendConfig, build_embedding_client
client = build_embedding_client(
EmbeddingBackendConfig(
provider="bedrock",
model_name="amazon.titan-embed-text-v1",
aws_region="us-east-1",
)
)
# Returns a float vector list
vector = client.embed_query("Sample query for similarity search")Azure OpenAI
Azure OpenAI provides robust, managed endpoints for models like text-embedding-3-small or text-embedding-ada-002.
- Client configuration attributes (
EmbeddingBackendConfig):provider:"azure"azure_api_key: Azure OpenAI API Key. Defaults toAZURE_OPENAI_API_KEYenv var.azure_endpoint: Azure OpenAI resource endpoint URL. Defaults toAZURE_OPENAI_ENDPOINTenv var.azure_api_version: OpenAI API Version. Defaults toOPENAI_API_VERSIONenv var.azure_deployment: Deployment name for your embedding model. Defaults toAZURE_EMBEDDING_DEPLOYMENT_NAMEenv var.
Example
python
import os
from elsai.integrations.elsai_embeddings import EmbeddingBackendConfig, build_embedding_client
client = build_embedding_client(
EmbeddingBackendConfig(
provider="azure",
azure_api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
azure_endpoint="https://my-resource.openai.azure.com",
azure_api_version="2024-02-01",
azure_deployment="my-embedding-deployment",
)
)
vector = client.embed_query("Query statement")