Lesson 10 of 10 Data Pipeline Design Patterns

Using Large Language Models in Data Pipelines

This lesson explains how large language models (LLMs) let pipelines classify, extract, summarise and enrich unstructured text that rules handle poorly, and how data engineers prepare and store the vector embeddings that retrieval-augmented generation depends on.

Learning outcomes

After completing this lesson, you will be able to:

  • Call Amazon Bedrock models from a pipeline, including with batch inference.
  • Describe how content is vectorised and stored for knowledge bases.

Calling LLMs from a pipeline

Amazon Bedrock provides foundation models from Amazon and other providers through one API, with no infrastructure to manage. A pipeline sends each record's text with a prompt, for example "classify this support ticket as billing, technical or account, and return JSON", and stores the structured response. Asking for a fixed JSON schema and validating the output keeps the results usable downstream.

How the model is called depends on the volume and urgency. A Lambda function or Step Functions task calling the Bedrock Converse or InvokeModel API suits records that must be processed as they arrive. Bedrock batch inference takes a JSONL file of prompts from S3 and writes the results back to S3 asynchronously, at a lower price than on-demand calls, which suits large, non-urgent backfills. SQL users can call models directly: Redshift ML can invoke Bedrock models as SQL functions, so analysts can summarise or classify text inside a query. The following table summarises the options.

ApproachSuits
Lambda or Step Functions calling the Bedrock APIRecords processed as they arrive, low to moderate volume
Bedrock batch inference (S3 in, S3 out)Large, non-urgent volumes at lower cost
Redshift ML with Bedrock modelsAnalysts applying an LLM to warehouse data in SQL

LLM calls are subject to quotas on tokens and requests, so pipelines throttle their concurrency, retry with backoff and, where possible, use batch inference. Sensitive data should be masked before it is sent to a model unless policy allows otherwise.

The following diagram shows the steps of a nightly pipeline that classifies support tickets with Bedrock batch inference.

The nightly ticket classification pipeline. A Glue job masks customer names and writes a JSONL file of prompts. Step Functions submits a Bedrock batch inference job, waits for it to finish and starts a second Glue job that validates the JSON responses and writes Parquet to the curated zone.
The scenario is illustrative.
Match the pairs

Calling models

Exam skills 1.2.10

Match each requirement with the way to call a model.

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

Vectorization and knowledge bases

Vectorization converts content into embeddings: arrays of numbers produced by an embedding model, such as Amazon Titan Text Embeddings, in which similar meanings lie close together. Documents are first split into chunks of a few hundred tokens, because a single vector cannot represent a long document well, and each chunk's embedding is stored in a vector index with its text and metadata. A question is embedded with the same model, and the nearest vectors identify the most relevant chunks.

Amazon Bedrock Knowledge Bases automates this pipeline: it reads documents from a data source such as S3, chunks them, creates embeddings, writes them to a vector store (for example OpenSearch Serverless, Aurora PostgreSQL with pgvector or S3 Vectors) and keeps them in sync when documents change. Applications then retrieve relevant chunks, or retrieve and generate an answer, in one API call, which is retrieval-augmented generation (RAG). Amazon Kendra provides managed intelligent search over enterprise documents and can also serve as the retriever. The following table summarises the steps.

StepWhat happensAWS option
IngestRead documents from the sourceS3 data source in Bedrock Knowledge Bases
ChunkSplit documents into passagesFixed-size, hierarchical or semantic chunking
EmbedConvert each chunk to a vectorTitan Text Embeddings or another embedding model
Store and indexWrite vectors to an index (HNSW or IVF)OpenSearch Serverless, Aurora pgvector, S3 Vectors
RetrieveFind the chunks nearest to the questionRetrieve or RetrieveAndGenerate API; Amazon Kendra
Put in order

A knowledge base pipeline

Exam skills 2.4.6 · 2.1.8

Put the steps of the vectorisation pipeline in order.

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

Classifying support tickets

A company receives 2 million support tickets a month as JSON files in S3 and wants each one classified and its product name extracted for reporting by the next morning. A nightly Glue job masks customer names and writes a JSONL file of prompts. A Step Functions workflow submits a Bedrock batch inference job, waits for it to finish, and starts a second Glue job that validates the JSON responses and writes them as Parquet to the curated zone. Batch inference keeps the cost below per-request pricing, and no one waits on individual calls.

Check yourself

How can a large, non-urgent LLM workload run at lower cost?

Show answer

With Amazon Bedrock batch inference, which reads inputs from S3 and writes results to S3.

Exam Tips

Remember for the exam

  • Classify, extract or summarise unstructured text in a pipeline: Amazon Bedrock.
  • Large, non-urgent LLM workloads at lower cost: Bedrock batch inference from S3 to S3.
  • Apply an LLM in SQL on warehouse data: Redshift ML with Bedrock.
  • Chunk, embed, store and sync documents for RAG with least effort: Amazon Bedrock Knowledge Bases.
  • Embeddings place similar meanings close together; the question must be embedded with the same model.