Amazon Bedrock Knowledge Bases and RAG

AIP-C01 · Foundation Model Integration, Data Management, and Compliance · Updated

Retrieval Augmented Generation (RAG) lets a foundation model answer from your own data without retraining it. Amazon Bedrock Knowledge Bases is the managed way to do it, and it is one of the most tested topics on AIP-C01.

How a knowledge base works

You point a knowledge base at a data source (Amazon S3, web crawler, Confluence, SharePoint, Salesforce and others). During ingestion it parses the files, splits them into chunks, turns each chunk into a vector with an embeddings model (for example Amazon Titan Text Embeddings or Cohere Embed), and stores the vectors in a vector store. At query time the question is embedded, the closest chunks are retrieved, and they are added to the prompt.

Two APIs matter:

APIWhat it does
RetrieveReturns only the matching chunks and scores. You build the prompt yourself.
RetrieveAndGenerateRetrieves and then calls a model to produce an answer with citations.

Vector store choices

  • Amazon OpenSearch Serverless: the default quick-create choice, fully managed.
  • Amazon Aurora PostgreSQL with pgvector: good if the data already lives in Aurora.
  • Amazon Neptune Analytics: needed for GraphRAG.
  • Others: Pinecone, Redis Enterprise Cloud, MongoDB Atlas, and Amazon S3 Vectors for low-cost, large-scale storage.

The embeddings model chosen at creation fixes the vector dimension. You cannot change it later without re-creating the index.

Chunking strategies

Chunking controls answer quality.

  • Default: about 300 tokens per chunk.
  • Fixed-size: you set max tokens and overlap.
  • Hierarchical: small child chunks are matched, larger parent chunks are returned for more context.
  • Semantic: splits where the meaning changes.
  • None: one chunk per file, for already short documents.
  • Custom (Lambda): your own logic for special formats.

If answers lack context, use larger or hierarchical chunks. If retrieval is noisy, use smaller or semantic chunks.

Improving retrieval

  • Hybrid search combines vector and keyword search; use it for part numbers, names and acronyms.
  • Metadata filters limit results to, for example, one department or year.
  • Reranking models reorder the retrieved chunks by relevance.
  • Query decomposition splits a complex question into sub-questions.
  • GraphRAG uses a graph of entities for multi-hop questions.

Keeping data fresh

Changes in the source are not picked up automatically. Start a sync (ingestion job) on a schedule or from an event, for example an Amazon EventBridge rule. Deleted files are removed from the index on the next sync.

Exam traps

  • RAG adds knowledge at query time; fine-tuning changes model behaviour. For changing facts, choose RAG.
  • Retrieve returns chunks only; RetrieveAndGenerate also produces the answer.
  • A new file in S3 is not searchable until the data source is synced.
  • You cannot switch the embeddings model of an existing index without rebuilding it.
  • Keyword problems (exact codes) point to hybrid search, not a bigger model.

Practice questions

Choose an answer, then review the explanation to check your understanding.

1. A team wants a managed RAG solution over documents in Amazon S3 with the least operational work. What should they use?

Show answer

Answer: B.Knowledge Bases manages ingestion, chunking, embedding, storage and retrieval, so no custom pipeline is needed.

2. Users search for exact product codes and also ask natural-language questions. Which retrieval setting helps most?

Show answer

Answer: B.Hybrid search adds keyword matching to vector similarity, so exact identifiers are found as well as meaning.

3. Documents change daily in S3. How do you make the knowledge base reflect the changes?

Show answer

Answer: B.A sync (StartIngestionJob) re-reads the data source and updates the vector index with new, changed and deleted files.

4. Answers must follow relationships between entities, such as which company owns which subsidiary. Which option fits best?

Show answer

Answer: B.GraphRAG builds a graph of entities and links, which captures indirect relationships that plain vector search misses.

AIP-C01 course outline

All 6 lessons · Course overview
  1. Amazon Bedrock Knowledge Bases and RAGFoundation Model Integration, Data Management, and Compliance Free
  2. Choosing models and inference options in Amazon BedrockFoundation Model Integration, Data Management, and Compliance Free
  3. Amazon Bedrock Agents and orchestrationImplementation and Integration Full access
  4. Amazon Bedrock Guardrails and AI safetyAI Safety, Security, and Governance Full access
  5. Cost, latency and scaling for Bedrock applicationsOperational Efficiency and Optimization Full access
  6. Evaluating and troubleshooting generative AI applicationsTesting, Validation, and Troubleshooting Full access