Skip to content

Skill 1.2.5: Configure and use embedding models to transform text and image data into numerical representations

Task 1.2: Data Preparation for ML and AI - Perform data transformation, feature engineering, and pre-processing

Core concept

  • Embedding = dense numerical vector capturing semantic meaning; similar meaning → closer vectors.
  • Primary objective = enable semantic search, RAG retrieval, clustering, classification, recommendation, deduplication, and cross-modal (text↔image) search.
  • Not for tabular categories — use encoding for discrete labels; use embeddings for unstructured text/images.

AWS embedding stack

Service Role Key exam notes
Amazon Bedrock Managed embedding models Titan Text Embeddings V2, Titan Multimodal G1, Cohere Embed English/Multilingual. InvokeModel for real-time.
Bedrock Knowledge Bases Managed RAG ingestion Chunking → embedding → vector store sync. Use for managed RAG instead of custom pipeline.
Amazon OpenSearch Service Vector store k-NN, cosine/dot/Euclidean, metadata filters. Common Bedrock KB target.
Aurora PostgreSQL pgvector Vector store SQL + vector search; transactional.
Amazon S3 Source docs/images KMS, VPC endpoint, event triggers.
Amazon Textract Extract text from PDFs/images Run before embedding scanned docs.
Amazon Comprehend PII detection Mask/redact before embedding.
Amazon Macie Sensitive data discovery in S3 Locate data needing redaction.

Model selection matrix

Model Modality Dimensions Max tokens Use when Gotcha
Titan Text Embeddings V2 Text 1024 default, 512, 256 8k General text, multilingual, cost/latency tuning Lower dims = cheaper but less accurate
Titan Text Embeddings G1 Text 1536 8k Legacy English text Larger vectors, older model
Cohere Embed English v3 Text 1024 512 English retrieval/classification input_type required
Cohere Embed Multilingual v3 Text 1024 512 100+ languages input_type required
Titan Multimodal Embeddings G1 Text + image 1024 Text ~128 tokens Cross-modal search, image retrieval, multimodal RAG Same model must embed both text and image

Configuration parameters & gotchas

  • Model ID consistency: index and query must use the exact same embedding model and version.
  • Dimensions: must match vector store index dimension. Changing dimensions requires full re-embedding.
  • Normalize: Titan V2 can normalize vectors. If normalized, dot product ≈ cosine similarity.
  • Distance metric: cosine is standard for text; dot product requires normalized vectors; Euclidean for unnormalized. Match index metric to embedding behavior.
  • Cohere input_type: search_document for corpus chunks, search_query for user queries. Mismatch silently degrades retrieval.
  • Batch vs real-time: Bedrock InvokeModel for real-time; Bedrock batch inference or Spark/Glue for bulk embedding. Knowledge Bases syncs automatically.
  • Token limits: exceeding model max truncates or errors. Chunk text to fit before embedding.

Chunking & metadata for RAG

  • Chunking strategies: default fixed-size (~300 tokens), fixed-size with overlap, no chunking (one logical unit), hierarchical (parent/child), semantic (meaning-based).
  • Trade-off: too large = irrelevant text dilutes embedding; too small = lost context. Semantic/hierarchical often best for complex docs.
  • Metadata extraction: title, source, page, product ID, access level. Enables filtering, citations, and access control.
  • Vector store index: dimension = embedding dimension; metadata filters narrow retrieval before similarity search.

Image embeddings

  • Use cases: visual search, product recommendation, duplicate detection, multimodal RAG.
  • Model: Titan Multimodal G1 embeds images and text into the same vector space; text query can retrieve images.
  • Preprocessing: resize, normalize format; use Textract if image contains text.
  • Gotcha: image embeddings are not interchangeable with text-only embeddings unless same multimodal model.

Security & compliance

  • IAM: least-privilege roles for Bedrock, OpenSearch, S3, KMS.
  • Encryption: TLS in transit; KMS at rest for S3, OpenSearch, Aurora, Bedrock custom models.
  • VPC: Bedrock VPC endpoints (PrivateLink), S3 gateway endpoint, OpenSearch VPC.
  • PII: Comprehend/Macie to detect; mask, redact, or anonymize before embedding. Vector stores are sensitive data stores.
  • Data privacy: Bedrock does not train base models on customer data. Verify model provider terms.

When to use X vs Y

Need Use Avoid
Tabular categories Encoding (one-hot, ordinal) Embeddings
Semantic text/image search Embeddings + vector store Keyword search only
Dynamic knowledge Q&A RAG with embeddings Fine-tuning
Static behavior/tone Prompting, then fine-tuning RAG
Multilingual retrieval Multilingual embedding model English-only model
Low latency/cost Lower dimensions High dimensions
High accuracy Higher dimensions, larger model Low dimensions

Anti-patterns

  • Mixing models: using different embedding models for index vs query.
  • No re-embedding: changing model/dimensions without rebuilding the vector index.
  • Ignoring input_type: Cohere query/document mismatch.
  • Metric mismatch: using cosine on unnormalized vectors or dot product on unnormalized vectors.
  • PII leakage: embedding raw sensitive data without redaction.
  • Bad chunking: chunks too large (noise) or too small (lost context).
  • Encoding semantics: using embeddings for tabular categorical features.
  • No metadata: missing filters, citations, and access control.

Exam gotchas - Embeddings are model-specific and dimension-specific. Changing either requires re-embedding the entire corpus. - Cohere Embed v3 input_type must match: search_document for chunks, search_query for queries. - Normalize vectors or match distance metric. Cosine is standard for text embeddings; dot product requires normalized vectors. - Bedrock Knowledge Bases handles chunking, embedding, and vector store sync. Use it for managed RAG. - Mask/redact PII before embedding. Once in a vector store, encryption and IAM are required.