AIP-C01 RAG Retrieval: Chunking, Embeddings, Vector Search and Query Handling
Retrieval mechanisms for foundation model (FM) augmentation are the chunking, embedding, vector search, ranking and query-handling steps that find the most relevant passages in your own content and pass them to an FM as context in a retrieval-augmented generation (RAG) system. This lesson covers AIP-C01 Task 1.5: Amazon Bedrock Knowledge Bases chunking strategies and custom transformation Lambda functions, Titan and Cohere embedding choices and how to evaluate and batch-generate them, OpenSearch, Aurora pgvector and S3 Vectors as vector search solutions, hybrid search and Bedrock reranker models, query expansion, decomposition and rewriting with Bedrock, Lambda and Step Functions, and consistent access through Retrieve, Converse tool use, MCP and standard retrieval APIs.
On this page10 sections
- What are retrieval mechanisms for FM augmentation?
- How do you choose a chunking strategy in a Bedrock knowledge base?
- When should you implement custom chunking with Lambda?
- How do you select and configure an embedding model?
- How do you evaluate embedding models and generate embeddings at scale?
- Which vector search solution should you deploy?
- How do you configure OpenSearch k-NN vector search?
- How do hybrid search and reranking improve relevance?
- How do you transform queries before and during retrieval?
- How do applications and agents access retrieval consistently?
- Choose a Bedrock knowledge base chunking strategy, chunk size and overlap from document structure, and know when custom chunking needs a transformation Lambda function.
- Select an embedding model, dimension and vector type for language, modality, cost and accuracy, and keep documents and queries in the same vector space.
- Evaluate embedding models on your own labelled questions and generate embeddings at scale with batch inference or batched Lambda requests.
- Choose and configure a vector search solution: knowledge base quick create, OpenSearch k-NN, Aurora PostgreSQL with pgvector or Amazon S3 Vectors.
- Improve relevance with hybrid search, score normalization and Bedrock reranker models, and tell a recall problem from a ranking problem.
- Design query expansion, decomposition and conversational rewriting with Bedrock, Lambda and Step Functions.
- Expose retrieval consistently through the Retrieve and RetrieveAndGenerate APIs, Converse tool use, MCP servers and a versioned retrieval contract.
What are retrieval mechanisms for FM augmentation?
Retrieval mechanisms are the parts of a retrieval-augmented generation (RAG) system that find the right passages in your own content and hand them to a foundation model (FM) as context. The FM only knows what it was trained on plus what you put in its prompt, so the quality of a RAG answer is capped by the quality of retrieval: if the passage that holds the answer is never found, or is found but ranked too low to reach the prompt, no prompt wording can recover it.
Task 1.5 follows the path a query takes, and each stage has its own AWS tools and its own failure modes:
| Stage | Decision you make | Typical AWS tools |
|---|---|---|
| Segment documents | Where chunk boundaries fall and how big chunks are | Bedrock Knowledge Bases chunking strategies, custom transformation Lambda functions |
| Embed | Which embedding model, how many dimensions, which vector data type | Amazon Titan Text Embeddings V2, Cohere Embed, Bedrock batch inference, Lambda |
| Store and search vectors | Which vector store and how its index is tuned | OpenSearch Serverless and OpenSearch Service, Aurora PostgreSQL with pgvector, Amazon S3 Vectors |
| Improve relevance | Whether to add keyword matching and a second-pass reranker | Hybrid search, OpenSearch search pipelines, Bedrock reranker models and the Rerank API |
| Handle the query | Whether to expand, decompose or rewrite the question before searching | Bedrock FMs, query decomposition, Lambda, AWS Step Functions |
| Expose retrieval | How applications and agents call search the same way every time | Retrieve and RetrieveAndGenerate, Converse tool use, MCP, AgentCore Gateway, API Gateway |
A useful diagnostic habit runs through the whole topic: first ask whether the right passage is never retrieved (a chunking, embedding, vocabulary or keyword problem), retrieved but ranked too low (a ranking problem that reranking fixes), or retrieved and ranked well but answered badly (a prompt or generation problem). Each symptom has a different fix, and many wrong designs apply a fix from the wrong row.
Designing the vector store itself (metadata frameworks, sharding, multi-index layouts and keeping indexes in sync with changing sources) belongs to Task 1.4 and its vector store lesson. This lesson covers how retrieval uses that store.
How do you choose a chunking strategy in a Bedrock knowledge base?
Choose the chunking strategy from the structure of the documents and the shape of the questions: split by size when any cut point is acceptable, split by meaning when the text has no structure but changes subject, split into two levels when narrow questions need wide context, and do not split at all when each file is already one self-contained unit. Amazon Bedrock Knowledge Bases offers these strategies on every data source:
| Strategy | Settings | How it cuts | Fits |
|---|---|---|---|
| Default | None | About 300 tokens per chunk, keeping sentences whole | A reasonable start when nothing else is known |
| Fixed-size | Maximum tokens per chunk, overlap percentage between consecutive chunks | By token count | A set chunk budget (for example, five passages must fit a prompt) and a chosen overlap |
| Semantic | Maximum tokens, buffer size (neighbouring sentences compared), breakpoint percentile threshold | Where the meaning of neighbouring sentences diverges, using a foundation model at ingestion (extra cost) | Unstructured text that drifts between subjects, such as notes without headings |
| Hierarchical | Parent maximum tokens, child maximum tokens, overlap tokens | By token count into child chunks nested inside larger parent chunks | Narrow questions that must be matched precisely but answered with the whole surrounding section |
| No chunking | None | Each file becomes one chunk | Files already split into one unit each (one FAQ entry per file), or files pre-split by your own code |
Chunk size and overlap
Chunk size is a precision-versus-context trade-off. An embedding is one vector for the whole chunk, so a very large chunk averages many facts together and a narrow question (one torque value, one clause) matches it weakly; it also fills the prompt and can push a RetrieveAndGenerate call past the model's input limit, and the FM may quote a neighbouring fact from the same chunk. A very small chunk matches precisely but can cut an answer in half. Overlap repairs that boundary problem without making chunks large: the text near each boundary is copied into both neighbours, so an answer that crosses a boundary appears whole in at least one chunk. Overlap does not fix a chunk that mixes two subjects; it repeats text and makes prompts slightly longer.
Hierarchical chunking in detail
With hierarchical chunking, the vector search runs over the small child chunks, and each matching child is replaced in the response by its parent chunk. Two consequences matter in practice:
- Fewer results than requested.
numberOfResultscounts child chunks searched. Children that share a parent collapse into that single parent, so asking for 20 results can return a handful of long passages. That is expected behaviour, not an ingestion fault. (When parsed content holds tables or figures, any chunking strategy can replace a match with the whole page or table and likewise return fewer results.) - Vector store fit. Large parent text is stored with the vectors. AWS does not recommend hierarchical chunking with an S3 vector bucket at all; large parents (over about 8,000 tokens combined) can also exceed its per-vector metadata limits. A store such as OpenSearch Serverless suits hierarchical chunking.
Both hierarchical levels are cut by size, not by meaning, so hierarchical chunking does not stop a chunk from straddling two subjects, and a parent smaller than a document unit still splits that unit.
Changing chunking later
A data source's chunking configuration is fixed when the data source is created; an update that tries to change it is rejected. To change chunk size or strategy, create a new data source with the new configuration, sync it, and remove the old one.
When should you implement custom chunking with Lambda?
Use custom chunking when the rule that decides chunk boundaries or chunk metadata cannot be expressed by the built-in strategies, for example one chunk per numbered contract clause, one chunk per table, or a split driven by a document's own heading structure. There are two Lambda patterns inside a Bedrock knowledge base and one outside it:
| Pattern | What the Lambda function does | Use when |
|---|---|---|
| No chunking + custom transformation Lambda | Splits the content itself and writes the chunks (with any per-chunk metadata) for Bedrock to embed as they are | You need your own boundary logic (clauses, sections, structure-aware hierarchy) but still want Bedrock to handle ingestion, embedding and sync |
| Native strategy (for example fixed-size) + custom transformation Lambda | Runs after Bedrock has chunked the files (the post-chunking step) and adds or edits metadata on each chunk | Built-in chunking works well, but every chunk needs its own metadata, such as chapter title or page range |
| Your own pipeline outside a knowledge base | Reads documents, splits them (for example fixed-size with overlap), embeds and writes to the vector store | You run a self-managed store such as OpenSearch Service or Aurora and own the whole ingestion path |
A custom transformation function is attached to the data source's ingestion configuration and exchanges files with Bedrock through an intermediate S3 bucket: Bedrock writes the content there, the function reads it, transforms it and writes the result back for Bedrock to continue ingesting. If the function does its own splitting, set the chunking strategy to no chunking so Bedrock does not re-split the function's chunks. If the function only adds metadata, keep the native strategy so the function does not have to reimplement chunking.
Keep the levels of metadata apart. A .metadata.json file next to a source document attaches file-level attributes that every chunk of that file inherits, so it cannot say which chapter or page a particular chunk came from. Chunk-level values need the transformation function. Implicit metadata filtering (where an FM builds a filter from the user's question) can only filter on metadata that is already stored; it never creates values. Parsing options, such as a foundation-model or Bedrock Data Automation parser, extract text and structure from complex files but do not decide where chunks are cut; the chunking strategy still does.
Structure-aware hierarchical chunking follows the same rule: when parent and child boundaries must follow headings or sections rather than token counts, write that logic in the transformation function (or pre-split the files) and use no chunking.
How do you select and configure an embedding model?
Select an embedding model by the language, modality and vocabulary of both the documents and the questions, then pick the smallest vector size and cheapest data type that keeps retrieval accuracy within tolerance on your own data. Every vector in an index must come from the same model with the same settings as the query vectors compared against it.
| Model (Bedrock) | Output | Notes for retrieval |
|---|---|---|
| Amazon Titan Text Embeddings V2 | 1,024 (default), 512 or 256 dimensions; float32 or binary vectors | One text per request in inputText; long inputs accepted; good general default |
| Amazon Titan Embeddings G1 - Text | Fixed 1,536 dimensions | Older model; no dimension choice, so larger vectors |
| Cohere Embed English v3 / Cohere Embed Multilingual v3 | 1,024 dimensions | Accept a list of texts per request; require an input_type; Multilingual maps the same meaning in different languages to nearby vectors |
| Amazon Titan Multimodal Embeddings G1 | Image and text vectors in one space | Search images with text, or text with images |
Dimensions and data type
Vector storage grows with dimensions times bytes per dimension. Moving Titan V2 from 1,024 to 512 float32 dimensions roughly halves storage; to 256, cuts it by about 75 percent. Binary vectors store one bit per dimension instead of 32 bits, a cut of about 97 percent, at the cost of coarser similarity and lower first-pass recall; pairing binary vectors with a reranker restores the ordering of the passages that reach the FM. In a knowledge base, binary vectors are stored only by OpenSearch Serverless and OpenSearch Service managed clusters, so keeping float32 keeps the vector store choice open. Measure the accuracy loss on your own queries before shrinking.
Domain fit and query/document consistency
- Cross-language search needs a multilingual model applied to both sides. An English-only model cannot match a German question to an English passage, and keyword (hybrid) search does not help because the two share almost no words.
- Same model, same settings, both sides. Each embedding model has its own vector space. Questions embedded by Cohere and documents embedded by Titan can have the same dimension and still return meaningless neighbours with no error. Changing the distance metric does not make two spaces comparable.
- Cohere input types. Cohere Embed is trained to pair
search_documentvectors for stored passages withsearch_queryvectors for questions. Embedding passages as queries (or usingclassificationorclustering, which serve other tasks) lowers retrieval quality. - Dimension mismatches fail loudly. A query or document vector whose length differs from the index field's dimension is rejected. The only real fix is to embed both sides with the same model and dimension.
Changing the embedding model or dimension
A knowledge base's embedding model configuration is fixed at creation; UpdateKnowledgeBase changes only details such as name, description and service role. An OpenSearch knn_vector field's dimension is also fixed once the index exists. So a new model or dimension means a new knowledge base on a new index (or, in a self-managed pipeline, a new index and a full re-embed). To keep answering during the change, build and sync the new one in parallel, test it, then switch the application to the new knowledge base ID or index.
How do you evaluate embedding models and generate embeddings at scale?
Evaluate embedding models with a retrieve-only Bedrock evaluation on your own labelled questions, and generate embeddings at scale with batch inference jobs for backfills or batched, quota-aware requests for continuous loads.
Evaluating Bedrock embedding models
Evaluate embedding models by retrieval quality on your own labelled questions, not by public leaderboard rank or by the raw similarity scores the models return. The least-code way on AWS is an Amazon Bedrock retrieve-only knowledge base evaluation job: build one knowledge base per candidate model over the identical documents, run the same prompt dataset against each, and compare the metrics.
- Why not similarity scores? Scores from different models live on different scales; a higher average says nothing about whether the right passage was returned.
- Why not a leaderboard? Public benchmarks measure other corpora and other question styles. Your runbooks, codes and jargon are what matter.
- Why retrieve-only? A retrieve-and-generate evaluation mixes in the generator's behaviour. Retrieve-only isolates the part the embedding model controls.
| Retrieve-only metric | What it measures | Needs ground truth? |
|---|---|---|
| Context relevance | How relevant each retrieved passage is to the question, judged by the evaluator model | No |
| Context coverage | How much of the information needed for a complete answer the retrieved passages contain | Yes, a ground-truth response per prompt |
Retrieve-and-generate evaluations add generation metrics, such as correctness, faithfulness and citation precision and coverage, which describe the generated answer and its citations rather than the retrieval step alone. Evaluate performance characteristics too: vector size and storage cost, maximum input length (which constrains chunk size), multilingual or multimodal support, and throughput limits for the embedding volume you expect.
Generating embeddings at scale
For a large backfill that is not urgent, write the chunks as JSONL records to Amazon S3 and run Amazon Bedrock batch inference jobs with the embedding model: the jobs run asynchronously, avoid per-request throttling and retry code, and batch pricing is lower than on-demand for supported models. Split very large corpora across several jobs, because each job has a record quota.
When embeddings must be produced continuously (new documents every night, or a few at a time), a Lambda function that calls the model on demand is fine, but design it around the model's requests-per-minute quota:
- Send many texts per request where the model allows it. Cohere Embed accepts a list of
textsin one request, so batching chunks cuts the request count, which is what the quota limits. Titan Text Embeddings V2 takes one string per request, so it gains nothing from that pattern. - Do not just add concurrency. Raising reserved concurrency sends requests faster into the same quota.
- Back off and retry on throttling for the on-demand path; a quota increase or Provisioned Throughput adds capacity but keeps per-request calls, and Provisioned Throughput is billed for the commitment, which rarely suits a one-off backfill.
- Set the right input type per side (Cohere
search_documentfor passages) and use the same model and dimension as the index.
Inside a Bedrock knowledge base, the sync job generates embeddings for you; the batching decisions above matter when you run your own pipeline into a self-managed store.
Which vector search solution should you deploy?
Deploy the vector store whose operating model matches the requirement that dominates: no vector database skills (let the knowledge base quick create one), vectors that must join and commit with relational rows (Aurora PostgreSQL with pgvector), low latency with hybrid search and tuning control (OpenSearch), or a huge, rarely queried corpus where storage cost leads (Amazon S3 Vectors).
| Option | Strengths | Trade-offs |
|---|---|---|
| Knowledge base quick create (for example an OpenSearch Serverless collection or an S3 vector bucket created by Bedrock) | Bedrock provisions the store and an index with the required fields; no sizing or index design | Less control over index tuning |
| Amazon OpenSearch Serverless | No cluster to size; low latency; hybrid search; binary vectors | Always-on compute units cost money even when queries are rare |
| Amazon OpenSearch Service managed cluster | Full control of k-NN engine, HNSW parameters, search pipelines; binary vectors | A cluster to size and operate |
| Amazon Aurora PostgreSQL with pgvector | Vectors sit beside relational columns: one SQL query filters on price or stock and orders by vector distance, and embeddings update in the same transactions | Database capacity and index memory to manage at very large vector counts |
| Amazon S3 Vectors | Very low storage cost for very large vector sets, nothing to provision, sub-second queries | Suits infrequent queries; semantic search with metadata filters, not hybrid; float vectors only; per-vector metadata limits |
Knowledge bases also integrate with other stores, such as MongoDB Atlas, Pinecone, Redis Enterprise Cloud and Amazon Neptune Analytics for graph-based retrieval. Copying relational data into a separate vector store (by streaming changes or by exporting files for a knowledge base to sync) creates copies that lag the source; when filters must reflect the latest transaction, keep the vectors in the database.
Aurora PostgreSQL as a knowledge base vector store
Bedrock reaches Aurora through the RDS Data API and authenticates with a database user whose credentials are stored in AWS Secrets Manager; the knowledge base's storage configuration takes the cluster ARN and the secret ARN. The DBA prepares:
- The
vectorextension (pgvector) and a table with an ID primary key, anembeddingvector column whose dimension matches the model, achunkstext column, ametadatacolumn for Bedrock's source attribution, and optionally a JSONBcustom_metadatacolumn that holds all metadata-file attributes. - An HNSW index on the embedding column with
vector_cosine_ops. - A GIN full-text index on
to_tsvector('simple', chunks), which serves the keyword half of hybrid search. - A GIN index on
custom_metadatawhen that column is used, so metadata filters run efficiently.
How do you configure OpenSearch k-NN vector search?
Configure OpenSearch vector search by creating a k-NN index whose knn_vector field declares the dimension, the engine, the distance (space type) and the approximate-search method, then tune recall at query time. The settings fall into two groups, and the group decides whether a change needs a reindex:
| Setting | Controls | When it takes effect |
|---|---|---|
dimension | Vector length; must equal the embedding model's output | Fixed at index creation; a new dimension needs a new index and a re-embed |
engine (Faiss or Lucene) | The library that builds and searches the graph | Fixed at index creation |
space_type (for example l2, cosinesimil, innerproduct) | How similarity is computed; match what the embedding model was designed for | Fixed at index creation |
HNSW m | Links per graph node; higher improves recall, costs memory | Build time; needs a rebuild |
HNSW ef_construction | Candidate list size while building the graph; higher gives a better graph, slower indexing | Build time; needs a reindex |
HNSW ef_search | Candidates explored per query; higher raises recall at some latency cost | Query time; can be passed per query in method_parameters (OpenSearch 2.16 and later) |
A minimal mapping looks like this:
PUT /manuals
{
"settings": { "index.knn": true },
"mappings": { "properties": {
"embedding": {
"type": "knn_vector",
"dimension": 1024,
"method": {
"name": "hnsw",
"engine": "faiss",
"space_type": "l2",
"parameters": { "m": 16, "ef_construction": 128 }
}
},
"text": { "type": "text" }
} }
}
To diagnose recall, compare approximate results with an exact (brute-force) search on a sample of queries. If recall is short and latency has headroom, raise ef_search first, because it needs no rebuild. Writes whose vectors have the wrong length fail with a mapping error on the vector field, and a mapping's dimension cannot be edited in place, so the fix is always a new index. A Bedrock knowledge base that uses OpenSearch needs the vector, text and metadata fields it is told about at creation; quick create builds them for you.
How do hybrid search and reranking improve relevance?
Hybrid search improves recall for exact strings, and reranking improves the order of what was already retrieved. They fix different symptoms, so the first question is always whether the right passage is missing from the candidates or present but ranked too low.
Hybrid search: keywords plus vectors
Embeddings place similar meanings close together, which is why an error code such as ERR-2093 or a part number can match passages about similar faults instead of the one containing the exact code. Hybrid search adds a keyword (full-text) search over the raw text, so exact identifiers, SKUs, error codes and rare names rank high. In a knowledge base, set overrideSearchType to HYBRID in the Retrieve or RetrieveAndGenerate vector search configuration (SEMANTIC forces vector-only). Hybrid search is available for Aurora PostgreSQL (RDS), OpenSearch Serverless and MongoDB Atlas stores with a filterable text field; S3 Vectors stores are semantic only. Keyword matching cannot bridge languages, so it does not fix cross-language retrieval.
On a self-managed OpenSearch index, run a hybrid query (a keyword sub-query plus a knn sub-query) through a search pipeline with a normalization processor. BM25 scores and vector scores sit on very different scales, so merging raw scores in application code lets one side dominate, and a fixed boost does not help because the BM25 scale changes per query. The processor rescales each sub-query's scores (for example min_max) and then combines them (for example an arithmetic mean with weights) inside OpenSearch, with no extra model call.
Reranking: retrieve wide, keep narrow
A reranker is a model that reads the query and each candidate passage together and scores their relevance more precisely than the vector similarity that produced the candidates. Bedrock offers reranker models such as Amazon Rerank and Cohere Rerank 3.5. Two ways to use them:
- Inside a knowledge base query: add a
rerankingConfiguration(typeBEDROCK_RERANKING_MODEL, the model ARN andnumberOfRerankedResults) to the Retrieve or RetrieveAndGenerate vector search configuration. - For any candidate list: call the Rerank API on the Agents for Amazon Bedrock runtime with the query and inline text sources, for example 60 candidates from a self-managed OpenSearch index, and keep the top results. The knowledge base
rerankingConfigurationcannot point at a store outside a knowledge base.
A reranker can only choose among the passages it receives. If numberOfResults equals numberOfRerankedResults, it merely reorders the same set and the FM sees the same passages. Set numberOfResults well above the number you keep: if the right passage tends to sit around rank 10 and the prompt holds four passages, retrieve 30 to 50 and rerank to 4. Reranking also cannot recover a passage that was never retrieved; that needs better chunking, query handling or hybrid search. Re-embedding candidates with the same embedding model is not reranking, because it repeats the same kind of similarity score.
How do you transform queries before and during retrieval?
Transform the query when the user's words are a poor search key: expand it when users and documents use different vocabulary, decompose it when one question needs several retrievals, and rewrite it into a standalone question when it is a conversational follow-up. Each transformation happens before retrieval, because nothing done after retrieval can bring back passages the search missed.
| Technique | Symptom it fixes | How to implement on AWS |
|---|---|---|
| Query expansion | Acronyms, brand names or jargon in questions that documents spell out differently | A Bedrock FM rewrites the question with expansions or synonyms (optionally from a glossary in DynamoDB) and the expanded text is the search query |
| Query decomposition (managed) | Comparison or multi-part questions retrieve passages for only one part | QUERY_DECOMPOSITION in the RetrieveAndGenerate orchestration configuration (queryTransformationConfiguration) |
| Query decomposition (your code) | The same, when the app calls Retrieve and generates with its own prompt, or sub-questions go to different knowledge bases | A Lambda function asks an FM for sub-questions, runs one Retrieve per sub-question, then merges and de-duplicates passages |
| Orchestrated transformation | Sub-questions must run in parallel with retries and per-sub-question visibility | A Step Functions workflow: an FM step that splits, a Map state running Retrieve per sub-question with Retry rules, then a merge step |
| Conversational rewrite | Follow-ups such as "and for contractors?" retrieve unrelated passages | A small FM rewrites the follow-up into a standalone question from the chat history before Retrieve; or, with RetrieveAndGenerate, reuse its sessionId |
Rules that keep transformation correct
- Search with the transformed query; answer the original. Expanded text is a search key. Send the user's question as written, plus the retrieved passages, to the generation step so the answer responds to what was asked.
- Managed decomposition belongs to RetrieveAndGenerate. The Retrieve API has no query transformation setting. Switching to RetrieveAndGenerate to get it also hands generation to Bedrock, which a team that must keep its own Converse prompt cannot accept; such teams decompose in their own code.
- Managed decomposition stays inside one knowledge base. Routing each sub-question to a different knowledge base needs your own orchestration; Step Functions gives parallelism (Map), declarative retries (Retry) and execution history per iteration with the least custom code, which a hand-written loop or an SQS fan-out does not.
- Do not search with the whole chat history. One long string blurs the embedding across earlier topics and can exceed query length limits. Rewrite to one standalone question instead.
- Decomposition is not expansion. Decomposition splits; it adds no synonyms. Expansion adds words; it does not split.
Fixing vocabulary at query time leaves the index untouched, which is usually less change than rewriting the corpus. More results (numberOfResults), more output tokens, or reranking do not substitute for transformation when the query itself points the search at the wrong place.
How do applications and agents access retrieval consistently?
Give every consumer the same, well-defined way to retrieve: pick the right Bedrock API for who generates the answer, expose search as a structured tool when a model decides when to search, serve it over the Model Context Protocol (MCP) when many agents or frameworks share it, and put one versioned contract in front of different vector stores.
Bedrock retrieval APIs
| API (Agents for Amazon Bedrock runtime) | Returns | Use when |
|---|---|---|
Retrieve | Matching chunks with content, relevance score, source location and metadata | You generate yourself: your own Converse prompt, or a model on a SageMaker AI endpoint |
RetrieveAndGenerate | A generated answer with citations; supports sessions, query decomposition and generation prompt templates | Bedrock may do the generation; works on a knowledge base or on supplied external sources |
InvokeAgent | An agent's reasoned response | You want a Bedrock agent to plan, call actions and use knowledge bases |
Rerank | Reranked scores for the passages you send | You need Bedrock reranking for candidates from any source |
Converse (on the Bedrock runtime) sends messages to a model; it does not query a knowledge base on its own.
Vector search as a function-calling tool
With Converse tool use the model decides on each turn whether to search, and the application does the searching. The loop is:
- Declare a tool in
toolConfigwith a name, a description and a JSON input schema (for example aquerystring). - When the response's
stopReasonistool_use, read thetoolUseblock, run Retrieve (or any search) with its input. Converse never runs the tool itself;end_turnmeans the model finished without asking. - Append the model's assistant message containing the
toolUseblock to the conversation, then send a user-role message with atoolResultcarrying the sametoolUseIdand the passages as text or JSON content.
Leaving out the assistant toolUse message puts two user messages back to back with a toolResult that answers nothing, and the request fails validation. Describing a tool in plain prompt text and parsing the reply is the fragile alternative that structured tool use replaces.
MCP clients for vector queries
MCP lets any MCP-capable client (an agent framework such as Strands Agents, or an AI assistant in an IDE) discover a server's tools and their input schemas at runtime, so one search tool serves many frameworks without per-framework wrapper code.
- Shared, hosted tool: put the search behind Amazon Bedrock AgentCore Gateway, which exposes APIs and Lambda functions as MCP tools and authenticates callers (for example with IAM). Agents connect with MCP clients.
- Local developer tool: the open-source AWS Labs Bedrock Knowledge Base Retrieval MCP server runs locally under the developer's AWS profile and discovers only knowledge bases that carry its inclusion tag, so tagging is how a security team limits which knowledge bases are reachable.
A plain REST endpoint or a Bedrock agent is not an MCP server, so an MCP client cannot discover it as a tool without extra work.
A standard retrieval contract across stores
When teams search different stores (knowledge bases, an OpenSearch index, Aurora pgvector) but want to share prompt-building code, define one versioned request and response schema (query, filters, top-k in; passages with text, score and source out) and put an Amazon API Gateway API in front of Lambda adapters, one per store, that translate each backend's native results into that shape. No data moves between stores, and the contract can evolve by version. Letting each team convert native responses in its own code lets shapes drift; consolidating all vectors into one store moves data.
Tip. Task 1.5 questions are production scenarios about a RAG application that retrieves the wrong passages, too few passages, or passages in the wrong order, and they state several constraints at once: keep the team's own Converse prompt, keep float32 vectors, keep native chunking, move no data, add no hosted infrastructure, keep answering during the change, or keep the same result count. Every option is a real AWS mechanism and the wrong ones miss one constraint, such as reranking a passage that was never retrieved, decomposition configured on an API that does not accept it, editing a chunking or embedding setting that is fixed at creation, a reranker with no larger candidate pool, hybrid search for a cross-language problem, or a store that cannot hold large parent chunks. Expect symptom-led items (unrelated neighbours with no error, a mapping error on new writes, fewer results than requested, a ValidationException in a tool-use loop, keyword results swamping vector results) that ask for the root cause, request snippets to read, and Select TWO items that pair steps such as no chunking with a custom transformation function or a wide retrieval with a reranker.
- Diagnose first: a passage that is never retrieved needs better chunking, embeddings, query handling or hybrid search; a passage retrieved but ranked low needs reranking.
- Fixed-size chunking sets max tokens and overlap percentage; semantic chunking splits where meaning changes; hierarchical matches small children and returns their parents, so it can return fewer results than requested; no chunking keeps one file as one chunk.
- Chunking configuration is fixed per data source and the embedding model is fixed per knowledge base: changing either means a new data source or a new knowledge base, synced before cut-over.
- Own chunking rules = no chunking plus a custom transformation Lambda function; chunk-level metadata on native chunks = native strategy plus a custom transformation Lambda function.
- Embed documents and queries with the same model, dimension and settings; use Cohere search_document for passages and search_query for questions; cross-language search needs a multilingual model.
- Titan Text Embeddings V2 offers 1,024, 512 or 256 dimensions and float32 or binary vectors; binary plus a reranker gives the largest storage cut with ordering protected.
- OpenSearch dimension, engine, space type, m and ef_construction are set when the index is built; ef_search tunes recall per query with no reindex.
- Aurora as a knowledge base store needs pgvector, the RDS Data API, a Secrets Manager secret, an HNSW index, a GIN text index and, when used, a GIN index on custom_metadata.
- A reranker needs numberOfResults well above numberOfRerankedResults, and the Rerank API reranks candidates from any source.
- Search with the expanded or rewritten query but generate from the user's original question; managed QUERY_DECOMPOSITION exists only in RetrieveAndGenerate.
Frequently asked questions
What is the difference between semantic chunking and hierarchical chunking in Amazon Bedrock Knowledge Bases?
Semantic chunking places chunk boundaries where the meaning of neighbouring sentences changes, so each chunk stays on one subject even in text without headings. Hierarchical chunking cuts by token count into small child chunks nested inside larger parent chunks; the search matches children and returns their parents, giving precise matching with wide context. Semantic chunking follows meaning, while hierarchical chunking follows size at two levels.
Why does a hierarchical chunking knowledge base return fewer results than numberOfResults?
With hierarchical chunking, numberOfResults counts the child chunks that the vector search matches. Each matching child is replaced by its parent chunk in the response, and children that share a parent collapse into that one parent, so a request for 10 results can return only a few longer passages. This is expected behaviour, not a sync or ingestion error.
Can you change the chunking strategy or embedding model of an existing Bedrock knowledge base?
No. A data source's chunking configuration is fixed when the data source is created, and a knowledge base's embedding model configuration is fixed when the knowledge base is created. To change chunking, create a new data source and sync it; to change the embedding model or dimension, create a new knowledge base on a new vector index, sync and test it, then switch the application over while the old one keeps serving.
When should you use hybrid search instead of semantic search?
Use hybrid search when questions contain exact strings that embeddings treat as merely similar, such as error codes, part numbers, SKUs, IDs or rare names. Hybrid search adds keyword matching over the raw text to the vector search, so passages that contain the exact string rank high. It does not help with cross-language questions, because keyword search needs shared words.
Why did adding a Bedrock reranker model not change answer quality?
A reranker can only reorder the candidates the vector search returns. If numberOfResults equals numberOfRerankedResults, the reranker reorders the same passages and the FM receives the same set. Retrieve a larger pool, for example 25 to 50 candidates, and keep only the few passages the prompt can hold.
What is the difference between the Retrieve and RetrieveAndGenerate APIs?
Retrieve queries an Amazon Bedrock knowledge base and returns the matching chunks with their text, relevance scores, source locations and metadata, leaving generation to your application. RetrieveAndGenerate also generates an answer with a Bedrock model and returns citations, and it adds managed features such as sessions for follow-up questions and query decomposition. Use Retrieve when you keep your own prompt or model.
How do you give an agent vector search through MCP on AWS?
Serve the search as a tool on an MCP server and connect the agent with an MCP client, which discovers the tool and its input schema at runtime. For a shared tool, Amazon Bedrock AgentCore Gateway can expose a Lambda function or API as an MCP tool with authentication in front of it. For developers' local tools, the AWS Labs Bedrock Knowledge Base Retrieval MCP server runs under their AWS profile and reaches only knowledge bases tagged for it.
Should you embed documents and user questions with different embedding models?
No. Each embedding model produces its own vector space, so distances between a question embedded by one model and documents embedded by another are meaningless, even when the dimensions match and no error occurs. Use the same model, dimension and settings for both, with only model-defined role settings such as Cohere's search_document and search_query input types differing.
Source
This lesson covers the "Foundation Model Integration, Data Management, and Compliance" domain of the official AIP-C01 exam guide. Vendors revise their guides — check the source for the current version.
- AWS Certified Generative AI Developer – Professional (AIP-C01) exam guide — Amazon Web Services
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.