Model reference · open weights
Titan-text-embeddings is an open-weight embedding model from amazon. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | amazon |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Runs with | transformers |
| Released | 2024-04-30 |
| Popularity | 518 downloads / month |
| Licence | Commercial licence needed |
About
This repository contains the MTEB scores and usage examples of Bedrock Titan Text Embeddings v2. You can use the embedding model either via the Bedrock InvokeModel API or via Bedrock's batch jobs. For RAG use cases we recommend the former to embed queries during search (latency optimized) and the latter to index corpus (throughput optimized).
import json
import boto3
class TitanEmbeddings(object):
accept = "application/json"
content_type = "application/json"
def __init__(self, model_id="amazon.titan-embed-text-v2:0"):
self.bedrock = boto3.client(service_name='bedrock-runtime')
self.model_id = model_id
def __call__(self, text, dimensions, normalize=True):
"""
Returns Titan Embeddings
Args:
text (str): text to embed
dimensions (int): Number of output dimensions.
normalize (bool): Whether to return the normalized embedding or not.
Return:
List[float]: Embedding
"""
body = json.dumps({
"inputText": text,
"dimensions": dimensions,
"normalize": normalize
})
response = self.bedrock.invoke_model(
body=body, modelId=self.model_id, accept=self.accept, contentType=self.content_type
)
response_body = json.loads(response.get('body').read())
return response_body['embedding']
if __name__ == '__main__':
"""
Entrypoint for Amazon Titan Embeddings V2 - Text example.
"""
dimensions = 1024
normalize = True
titan_embeddings_v2 = TitanEmbeddings(model_id="amazon.titan-embed-text-v2:0")
input_text = "What are the different services that you offer?"
embedding = titan_embeddings_v2(input_text, dimensions, normalize)
print(f"{input_text=}")
print(f"{embedding[:10]=}")
import requests
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
region = "us-east-1"
base_uri = f"bedrock.{region}.amazonaws.com"
batch_job_uri = f"https://{base_uri}/model-invocation-job/"
# For details on how to set up an IAM role for batch inference, see
# https://docs.aws.amazon.com/bedrock/latest/userguide/batch-inference-permissions.html
role_arn = "arn:aws:iam::111122223333:role/my-batch-inference-role"
payload = {
"inputDataConfig": {
"s3InputDataConfig": {
"s3Uri": "s3://my-input-bucket/batch-input/",
"s3InputFormat": "JSONL"
}
},
"jobName": "embeddings-v2-batch-job",
"modelId": "amazon.titan-embed-text-v2:0",
"outputDataConfig": {
"s3OutputDataConfig": {
"s3Uri": "s3://my-output-bucket/batch-output/"
}
},
"roleArn": role_arn
}
request_auth = BotoAWSRequestsAuth(
aws_host=base_uri,
aws_region=region,
aws_service="bedrock"
)
response= requests.request("POST", batch_job_uri, json=payload, auth=request_auth)
print(response.json())
From the published model card. Full card on the HuggingFace links in the sidebar.
How it works
Benchmarks
As published on the model card — the maker's own numbers, not measured by AxForge.
| Task | Dataset | Metric | Score |
|---|---|---|---|
| Classification | MTEB AmazonCounterfactualClassification (en) | accuracy | 79.313 |
| Classification | MTEB AmazonCounterfactualClassification (en) | ap | 43.947 |
| Classification | MTEB AmazonCounterfactualClassification (en) | f1 | 73.613 |
| Classification | MTEB AmazonCounterfactualClassification (de) | accuracy | 70.942 |
| Classification | MTEB AmazonCounterfactualClassification (de) | ap | 82.301 |
| Classification | MTEB AmazonCounterfactualClassification (de) | f1 | 69.380 |
| Classification | MTEB AmazonCounterfactualClassification (en-ext) | accuracy | 82.294 |
| Classification | MTEB AmazonCounterfactualClassification (en-ext) | ap | 29.957 |
| Classification | MTEB AmazonCounterfactualClassification (en-ext) | f1 | 68.882 |
| Classification | MTEB AmazonCounterfactualClassification (ja) | accuracy | 80.064 |
| Classification | MTEB AmazonCounterfactualClassification (ja) | ap | 25.244 |
| Classification | MTEB AmazonCounterfactualClassification (ja) | f1 | 65.538 |
| Classification | MTEB AmazonPolarityClassification | accuracy | 76.664 |
| Classification | MTEB AmazonPolarityClassification | ap | 70.770 |
| Classification | MTEB AmazonPolarityClassification | f1 | 76.541 |
| Classification | MTEB AmazonReviewsClassification (en) | accuracy | 35.276 |
| Classification | MTEB AmazonReviewsClassification (en) | f1 | 34.906 |
| Classification | MTEB AmazonReviewsClassification (de) | accuracy | 38.826 |
| Classification | MTEB AmazonReviewsClassification (de) | f1 | 37.713 |
| Classification | MTEB AmazonReviewsClassification (es) | accuracy | 39.386 |
| Classification | MTEB AmazonReviewsClassification (es) | f1 | 38.243 |
| Classification | MTEB AmazonReviewsClassification (fr) | accuracy | 39.472 |
| Classification | MTEB AmazonReviewsClassification (fr) | f1 | 38.372 |
| Classification | MTEB AmazonReviewsClassification (ja) | accuracy | 35.898 |
Using it via the API
Once AxForge deploys titan-text-embeddings for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (titan-text-embeddings below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"titan-text-embeddings","input":"text to embed"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.