Lesson 1 of 4 Embeddings and Vector Stores

Choosing and Configuring Embedding Models

This lesson explains how embeddings represent the meaning of content as vectors that make semantic search possible, and how to choose and configure an embedding model.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how embeddings enable semantic search.
  • Configure Bedrock embedding models.
  • Choose dimensions and evaluate domain fit.
  • Generate embeddings at scale.

How embeddings enable semantic search

Keyword search finds documents that contain the words in a query, but users often describe what they need in different words from the ones documents use. Semantic search addresses this by comparing meaning rather than words, and embeddings make that possible.

An embedding model converts an input, such as a sentence, a passage or an image, into a fixed-length list of numbers called a vector, for example 1,024 numbers. The model is trained so that inputs with similar meaning produce vectors that are close together. Closeness is measured with cosine similarity, which compares the angle between vectors, Euclidean (L2) distance or the inner (dot) product. Semantic search embeds the documents in advance and stores their vectors; at query time it embeds the query with the same model and finds the stored vectors nearest to it. As a result, "how do I reset my password" matches a document titled "Recovering account access" even though the two share no words.

The following diagram shows a query and passages as points in a vector space.

How embeddings support semantic search. The embedding model turns the query and each passage into vectors, and passages with similar meaning lie close to the query even when they share no words with it, such as recovering account access. Similarity is measured with cosine similarity, Euclidean distance or the dot product.
Real embeddings have hundreds of dimensions; the positions and scores are illustrative.
True or false

How embeddings work

Exam skills 1.5.2

Check four claims about embeddings and similarity.

Log in to try this activity Interactive activities are free with an account.

Embedding models on Amazon Bedrock

Amazon Titan Text Embeddings V2 accepts up to 8,192 tokens of text, supports more than 100 languages, and outputs 1,024, 512 or 256 dimensions, with an option to normalise vectors. Amazon Titan Multimodal Embeddings embeds images and text into one space for image search by text or image. Amazon Nova Multimodal Embeddings embeds text, documents, images, video and audio into a single space. Cohere Embed models offer strong English and multilingual retrieval and distinguish query and document input types.

import boto3, json
brt = boto3.client("bedrock-runtime")
body = {"inputText": "How do I reset my password?", "dimensions": 512, "normalize": True}
r = brt.invoke_model(modelId="amazon.titan-embed-text-v2:0", body=json.dumps(body))
vector = json.loads(r["body"].read())["embedding"]   # 512 floats

8,192tokens

Maximum input to Titan Text Embeddings V2

1,024 / 512 / 256dimensions

Output sizes of Titan Text Embeddings V2

100+languages

Supported by Titan Text Embeddings V2

Choosing dimensions and evaluating domain fit

More dimensions capture more nuance but cost more storage, memory and query time. Reducing Titan V2 from 1,024 to 256 dimensions cuts vector storage by three quarters with a modest loss of retrieval accuracy, which is often acceptable for large corpora. The only reliable way to choose is to evaluate: build a set of real queries with the documents that should be found, embed the corpus with each candidate model and dimension, and compare recall at k and latency.

Domain fit matters most for specialised vocabularies such as medical, legal or internal product names, and for languages other than English. The following table summarises the trade-offs.

ChoiceBenefitCost
Higher dimensions (1,024)Best accuracyMore storage, memory and latency
Lower dimensions (256 or 512)Smaller, faster indexesSlightly lower accuracy
Multimodal modelImages and text in one searchUsually lower text-only accuracy than text models
Multilingual modelCross-language retrievalEvaluate per language

The following diagram compares two embedding dimension settings for a vector index on recall, storage and memory.

Trading dimensions for cost. At 1,024 dimensions the index has recall at 10 of 0.91; at 256 dimensions recall is 0.89 and vector storage and memory fall by about 75%. Documents and queries must use the same setting, so the switch is a full re-index into a new index followed by a cut-over.
Bar lengths show relative vector storage.
Fill in the number

Dimensions and storage

Exam skills 1.5.2 · 4.1.1

Work out the storage effect of choosing fewer embedding dimensions.

Log in to try this activity Interactive activities are free with an account.

Generating embeddings at scale

A knowledge base may contain millions of chunks, and embedding them one request at a time is slow and quickly reaches the model's request quota. Three approaches handle this scale. Lambda functions can consume chunks from an SQS queue in batches, with reserved concurrency to keep the request rate below the quota and automatic retries for throttled calls. Bedrock batch inference processes large sets of embedding requests asynchronously at a lower price for supported models. And Bedrock Knowledge Bases embed documents automatically during each sync, managing throughput themselves.

Whatever the method, documents and queries must be embedded with the same model and the same number of dimensions. Vectors produced by different models, or by the same model at different dimensions, are not comparable, so changing the embedding model means re-embedding the entire corpus and rebuilding the index, usually into a new index that replaces the old one once it is complete.

Scenario questions

Embedding a large corpus

Exam skills 1.5.2 · 4.2.3

Choose how to generate embeddings at scale.

Log in to try this activity Interactive activities are free with an account.
Worked example

Shrinking an index

A vector index of 300 million chunks at 1,024 dimensions has become expensive, and query latency is rising. An evaluation shows recall at 10 of 0.91 at 1,024 dimensions and 0.89 at 256.

Re-embedding with Titan Text Embeddings V2 at 256 dimensions cuts vector storage and memory by about 75% and improves latency for a two-point recall loss, which a reranker can recover. Both documents and queries must use the new setting, so the switch is a full re-index into a new index followed by a cut-over.

Check yourself

Which embeddings let a text query find relevant images?

Show answer

Multimodal embeddings, which place images and text in the same vector space.

Exam Tips

Remember for the exam

  • Titan Text Embeddings V2: up to 8,192 tokens; 1,024, 512 or 256 dimensions.
  • Fewer dimensions: smaller, faster indexes with a small accuracy loss.
  • Images and text together: multimodal embeddings.
  • Same model and dimensions for documents and queries; a model change requires re-embedding.