Elsai Embeddings#
The Elsai Embeddings module enables seamless embedding generation using Azure OpenAI models. In version 0.2.0, Bedrock embeddings model support has been added.
Prerequisites#
Python >= 3.9
.env file with appropriate API keys and configuration variables
Installation#
To install the elsai-embeddings package:
pip install --extra-index-url https://elsai-core-package.optisolbusiness.com/root/elsai-embeddings/ elsai-embeddings==0.2.0
Components#
1. Azure Embeddings#
AzureOpenAIEmbeddingModel is a class that connects to the Azure OpenAI embedding service to generate vector representations of text queries and documents.
from elsai_embeddings.azure_embeddings import AzureOpenAIEmbeddingModel
embeddings = AzureOpenAIEmbeddingModel(
model="your_model_name",
azure_api_key="your_azure_api_key",
azure_api_version="your_azure_api_version",
azure_deployment="your_azure_deployment_name",
azure_endpoint="your_azure_endpoint"
) # Or set in environment variables AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_VERSION, AZURE_EMBEDDING_DEPLOYMENT_NAME
embed_text = embeddings.embed_query("Your text to embed")
embed_docs = embeddings.embed_documents(["Document 1 text", "Document 2 text"])
embedding_model = embeddings.get_embedding_model() # Returns the underlying embedding model instance
Required Environment Variables:
AZURE_OPENAI_API_KEY– API key for accessing the Azure OpenAI service.AZURE_OPENAI_ENDPOINT– Endpoint URL of your Azure OpenAI resource.OPENAI_API_VERSION– API version used for the embedding requests.AZURE_EMBEDDING_DEPLOYMENT_NAME– Deployment name for the embedding model on Azure.
2. Bedrock Embeddings#
BedrockEmbeddings is a class that connects to AWS Bedrock embedding service to generate vector representations of text. This feature was added in version 0.2.0.
from elsai_embeddings.bedrock_embeddings import BedrockEmbeddings
bedrock_embeddings = BedrockEmbeddings(
aws_access_key="",
aws_region="us-east-1",
aws_secret_key="",
aws_session_token="",
model_name="",
config=None
) # Or set in environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_SESSION_TOKEN, BEDROCK_EMBEDDING_MODEL_NAME
text = "Hello, this is a sample text to be embedded using Bedrock Embeddings."
texts = ["Hello, this is a sample text to be embedded using Bedrock Embeddings.", "Here is another text for embedding."]
embedding = bedrock_embeddings.embed_text(text)
embeddings = bedrock_embeddings.embed_texts(texts)
Required Environment Variables:
AWS_ACCESS_KEY_ID– AWS access key ID for accessing the Bedrock service.AWS_SECRET_ACCESS_KEY– AWS secret access key for authentication.AWS_REGION– AWS region where the Bedrock service is available (e.g., “us-east-1”).AWS_SESSION_TOKEN– AWS session token (optional, required for temporary credentials).BEDROCK_EMBEDDING_MODEL_NAME– Name of the Bedrock embedding model to use.
Supported Model Names:
The model_name parameter supports the following values:
titan-embed-v2– Amazon Titan Embeddings V2 modelcohere-multilingual– Cohere Multilingual embedding modelcohere-english– Cohere English embedding model