Lesson 2 of 2 Amazon Bedrock

Using Knowledge Bases, Agents and Batch Inference in Applications

This lesson explains the managed Amazon Bedrock features that applications call instead of building: knowledge bases for answers from company documents, agents for multi-step tasks, and batch inference, prompt caching and prompt management for cost and change control.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how Retrieve and RetrieveAndGenerate use a knowledge base.
  • Explain how agents use action groups, user confirmation and return of control.
  • Choose the Bedrock feature that fits a given requirement.

Knowledge Bases

An Amazon Bedrock knowledge base answers questions from an organisation's own content, a pattern called retrieval augmented generation (RAG). Documents are stored in a data source such as an S3 bucket; a sync (ingestion job) splits them into chunks, converts them to vector embeddings and stores them in a vector store. Designing RAG architectures is outside the scope of the Developer exam, but calling a knowledge base from code is within it.

Applications call the bedrock-agent-runtime endpoint. Retrieve returns the most relevant chunks with their source locations, which the application can pass to a model itself. RetrieveAndGenerate retrieves the chunks, sends them to a model and returns a generated answer with citations that point to the source documents. Metadata filters restrict retrieval, for example to documents tagged with the user's department. When documents change, a new sync must run before the answers reflect them.

The following diagram shows how documents reach a knowledge base and how an application queries it.

An Amazon Bedrock knowledge base. A sync job splits documents from an S3 data source into chunks, converts them to embeddings and stores them in a vector store; changed documents need a new sync. At query time the application calls Retrieve, which returns relevant chunks with their sources, or RetrieveAndGenerate, which also sends them to a model and returns an answer with citations. Metadata filters restrict retrieval.
Retrieve leaves the model call to the application; RetrieveAndGenerate makes it and adds citations.

Agents for Amazon Bedrock

An agent uses a model to plan and complete a multi-step task, such as checking an order, applying a refund and confirming by email. In Agents for Amazon Bedrock, the developer configures the agent with instructions, a model, optional knowledge bases and action groups. Each action group describes operations with an OpenAPI schema or function details and is fulfilled by a Lambda function, which receives the operation name and parameters and returns a result.

Applications call InvokeAgent with an agent alias, a sessionId that keeps the conversation together and the user's input; the response arrives as a stream of chunks. Two features keep a person in control. User confirmation makes the agent ask the user before it runs a chosen action group function, and return of control sends the chosen action and parameters back to the application instead of calling Lambda, so the application can apply its own checks or approval before acting.

Scenario questions

Agents for Amazon Bedrock

Exam skills 1.1.10 · 2.3.4

Practise configuring and calling a managed Bedrock agent.

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

Batch inference, prompt caching and prompt management

Batch inference processes many prompts asynchronously. The application writes the requests as a JSONL file to S3 and calls CreateModelInvocationJob with an IAM service role that can read the input and write the output; Bedrock writes the results to S3 when the job finishes. Batch inference costs less than on-demand inference, so it suits nightly enrichment, classification of a backlog or evaluation runs that have no latency requirement.

Prompt caching stores a long, repeated prefix of a prompt, such as detailed instructions or a reference document, for a short time, so later requests that begin with the same prefix are cheaper and faster. Prompt management stores prompts as versioned resources with variables, so they can be changed and reviewed without redeploying code. The following table summarises when each Bedrock feature fits.

RequirementBedrock feature
Answer questions from company documents, with citationsKnowledge base with RetrieveAndGenerate
Complete multi-step tasks that call business APIsAgents for Amazon Bedrock with action groups, or an agent on AgentCore
Process thousands of prompts with no latency requirement at lower costBatch inference
Reduce the cost of prompts that repeat long instructionsPrompt caching
Change prompts without redeploying, with version historyPrompt management
Sort into groups

Which Bedrock feature?

Exam skills 1.1.10

Choose the Bedrock feature for each requirement.

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

Other managed AI services in scope

Amazon Bedrock AgentCore, covered in the next module, hosts and secures agents built with any framework, where Agents for Amazon Bedrock is a configured, fully managed agent. Amazon Quick is an agentic workspace for business users, combining chat over company data, research, dashboards and workflow automation; developers make an application's data and actions available in Quick through its integrations rather than by calling a model API. Amazon Quick Sight, the business intelligence capability within Quick, is out of scope for this exam.

Worked example

An internal policy assistant

Employees need answers about HR policies stored as PDFs in S3, each answer must link to its source, and staff must see only their own country's policies.

The developer creates a knowledge base on the bucket, adds a country metadata field to each document and calls RetrieveAndGenerate with a metadata filter set from the signed-in user's Cognito attributes. The citations in the response provide the links.

A scheduled EventBridge rule starts an ingestion job each night so updated documents are reflected the next day. A request to "also let the assistant book leave" would add an action that changes data, so it calls for an agent with an action group and user confirmation, not a larger knowledge base.

Check yourself

Documents in a knowledge base's S3 bucket were updated yesterday, but answers still quote the old text. Why?

Show answer

A knowledge base reflects changes only after a sync (ingestion job) re-processes the data source. Running a sync, for example on a schedule or after each upload, updates the vector store.

Exam Tips

Remember for the exam

  • Answers grounded in company documents with citations: a knowledge base with RetrieveAndGenerate.
  • Updated documents not reflected in answers: run a new knowledge base sync.
  • Agent must ask before acting: user confirmation; application must perform the action: return of control.
  • Large offline workloads at lower cost: batch inference from JSONL in S3.