Generating Embeddings for Text and Images
This lesson explains embeddings, dense vectors in which similar meanings lie close together, which power semantic search, RAG, clustering, recommendations and classification features.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how embedding models map inputs to vectors.
- Use embedding models on Amazon Bedrock, including multimodal embeddings.
- Choose consistent embedding configurations.
How embeddings work
An embedding model maps an input, such as a sentence, a document or an image, to a fixed-length vector of numbers, for example 1,024 of them. The model is trained so that inputs with similar meaning produce vectors that are close together. Similarity is measured with cosine similarity, the angle between vectors, the dot product, or Euclidean distance. When vectors are normalised to unit length, cosine similarity and dot product give the same ranking.
Unlike one-hot or TF-IDF vectors, which treat each word as an independent symbol, embeddings capture synonyms and context, so "car" and "automobile" are close, and "bank" in a financial sentence differs from "bank" in a sentence about a river. This makes embeddings the basis of semantic search, retrieval for RAG, clustering and recommendation.
The following diagram sketches how embeddings place inputs by meaning.

What an embedding is
Embedding models on AWS
Amazon Bedrock provides managed embedding models through the same runtime API as text models. Amazon Titan Text Embeddings V2 accepts up to 8,192 tokens, outputs 1,024, 512 or 256 dimensions and can normalise vectors. Amazon Titan Multimodal Embeddings embeds images and text into the same space, so text queries can find images. Cohere Embed models provide English and multilingual embeddings, with input types that distinguish documents from queries. Open-source embedding models can be hosted on SageMaker AI endpoints through JumpStart.
import boto3, json
brt = boto3.client("bedrock-runtime")
resp = brt.invoke_model(
modelId="amazon.titan-embed-text-v2:0",
body=json.dumps({"inputText": "How do I reset my router?", "dimensions": 512, "normalize": True}),
)
vector = json.loads(resp["body"].read())["embedding"] # 512 floats8,192tokens
Maximum input to Titan Text Embeddings V2
1,024dimensions
Largest Titan Text Embeddings V2 output (also 512 or 256)
Pick the embedding model
Configuration choices
Use the same model, version and settings for documents and queries; vectors from different models are not comparable, so changing the model means re-embedding the whole corpus. Dimensions trade accuracy against storage and search cost. Inputs longer than the model's limit are truncated, so long documents are chunked first. Batch embedding through Bedrock batch inference reduces cost for large corpora. The following table summarises the choices.
| Choice | Effect |
|---|---|
| Model | Language coverage, domain quality, modality; documents and queries must match |
| Dimensions (for example 1,024 vs 256) | Higher: more accurate, larger index; lower: cheaper, faster |
| Normalization | Makes cosine similarity equal to dot product |
| Maximum input tokens | Determines maximum chunk size |
| Multimodal model | Search images with text and vice versa |
The following diagram shows the indexing and query paths of a multimodal product search that matches text queries to product images.

Vector storage
Product search across text and images
An online retailer wants shoppers to type "red leather ankle boots" and see matching products, including products whose descriptions are sparse but whose photos match.
- Embed every product image (and its title) with Titan Multimodal Embeddings into one vector space.
- Store vectors with product metadata (category, price, stock) in a vector index.
- At query time, embed the text query with the same model and search for the nearest image vectors, filtered by in-stock items.
A text-only embedding model would only match products with good descriptions. Because the multimodal model places text and images in the same space, the photo of a red leather boot is found even when its description says only "autumn collection".
What must happen when the embedding model is changed?
Show answer
All content must be re-embedded, because vectors from different models are not comparable.
Exam Tips
Remember for the exam
- Documents and queries must use the same embedding model and settings.
- Changing the embedding model requires re-embedding all content.
- Titan Text Embeddings V2: 1,024, 512 or 256 dimensions with optional normalisation.
- Search images with text: Titan Multimodal Embeddings.
- Fewer dimensions reduce storage and search cost with a small accuracy loss.