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.embeddings.
This module lets you build standalone embedding clients using AWS Bedrock or Azure OpenAI as backends.
Installation
Install the elsai-embeddings extra when using embedding clients with elsai-agents:
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents[elsai-embeddings]==0.3.0"For similarity retrieval or semantic memory you also need vector stores — use the convenience bundle instead:
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents[elsai-memory]==0.3.0"See Memory Overview — Installation for the full extra-to-feature map.
Embedding 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.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.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.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.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")