Lesson 2 of 7 Retrieval Augmented Generation

Building Managed RAG with Amazon Bedrock Knowledge Bases

This lesson explains Amazon Bedrock Knowledge Bases, the managed RAG service that handles ingestion, chunking, embedding, vector storage, retrieval and generation, so teams configure rather than build the pipeline.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the components of a knowledge base.
  • Configure parsing and chunking for each data source.
  • Choose between the Retrieve and RetrieveAndGenerate APIs.

Components

A knowledge base has an embedding model (such as Titan Text Embeddings V2 or Cohere Embed), a vector store and one or more data sources. Supported vector stores include Amazon OpenSearch Serverless, OpenSearch Service managed clusters, Amazon S3 Vectors, Amazon Aurora PostgreSQL (pgvector), Amazon Neptune Analytics (GraphRAG) and third-party stores such as Pinecone, Redis Enterprise Cloud and MongoDB Atlas. Quick create provisions an OpenSearch Serverless or S3 Vectors store automatically. Data sources include Amazon S3, a web crawler, Confluence, SharePoint, Salesforce and custom sources that push documents through the API. A knowledge base can also connect to structured stores for text-to-SQL retrieval.

Put in order

How a knowledge base ingests

Exam skills 3.2.7

Arrange the steps a Bedrock knowledge base follows when it syncs a data source.

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

Ingestion configuration

Each data source sets a parsing strategy (default, Bedrock Data Automation or FM parsing), a chunking strategy (fixed-size, hierarchical, semantic, none or custom Lambda) and an optional custom transformation Lambda function. An ingestion job (sync) reads the source, processes new, changed and deleted documents incrementally, embeds chunks and writes them to the vector store. Metadata files supply filterable attributes. The knowledge base service role needs access to the source bucket, the embedding model, the vector store and any KMS keys.

True or false

Knowledge base settings

Exam skills 3.2.7

Check which knowledge base settings can change after creation.

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

Retrieval APIs

The Retrieve API returns relevant chunks with scores and source locations, for applications that build their own prompts. RetrieveAndGenerate retrieves and then generates an answer with citations using a chosen model, and supports sessions for follow-up questions, a custom prompt template, guardrails and retrieval settings such as number of results, search type, metadata filters and reranking. Knowledge bases can also be attached to Bedrock Agents. The following table summarises the configuration points.

SettingWhereCan change after creation
Embedding modelKnowledge baseNo (create a new knowledge base)
Vector storeKnowledge baseNo
Chunking and parsingData sourceNo (create a new data source)
Number of results, search type, filters, rerankingEach queryYes, per request
Generation model, prompt template, guardrailRetrieveAndGenerate requestYes, per request

The following diagram shows the configuration and query path of an HR policy knowledge base built entirely through configuration.

The HR policy knowledge base, built entirely by configuration. 2,000 policy PDFs in S3 with country metadata files are parsed with the default parser and split into 500-token chunks with 15% overlap, embedded with Titan Text Embeddings V2 and stored in an S3 Vectors store created by quick create. Employees query through RetrieveAndGenerate with a country filter and a guardrail.
The scenario is illustrative.
Scenario questions

Which API?

Exam skills 3.2.7 · 3.1.8

Choose between the knowledge base retrieval APIs for each application.

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

An HR policy assistant

An HR team wants employees to ask questions about 2,000 policy PDFs in S3, with answers citing the source, within two weeks and without ML engineers.

  • Create a knowledge base with Titan Text Embeddings V2 and quick create of an S3 Vectors store, because query volume is modest and cost matters.
  • Add the S3 data source with default parsing and fixed-size chunking of 500 tokens with 15% overlap; add country metadata files.
  • Run the ingestion job, then call RetrieveAndGenerate with a metadata filter on the employee's country and a guardrail.

Everything is configuration; no vector database or embedding pipeline is built. If testing later shows that a different chunking strategy is needed, a new data source is created and synced.

Check yourself

What is the difference between Retrieve and RetrieveAndGenerate?

Show answer

Retrieve returns matching chunks. RetrieveAndGenerate also generates an answer with citations.

Exam Tips

Remember for the exam

  • Managed RAG with least effort: Bedrock Knowledge Bases.
  • Retrieve returns chunks; RetrieveAndGenerate also generates a cited answer.
  • Embedding model and vector store cannot be changed after creation.
  • Ingestion (sync) jobs process new, changed and deleted documents incrementally.
  • Quick create provisions OpenSearch Serverless or S3 Vectors automatically.