Bedrock Knowledge Bases Best Practices
Chunking strategy, metadata filtering, and retrieval-quality evaluation.
Busca en todas las páginas de la documentación
Chunking strategy, metadata filtering, and retrieval-quality evaluation.
This is the checklist to run before and after putting a Bedrock Knowledge Base into production. Each item is a rule stated positively with a one-line rationale, grouped from setup outward through ingestion, retrieval, cost, and security. Work top to bottom - early groups keep your Knowledge Base structurally sound; later ones keep it accurate, cheap, and safe.
FIXED_SIZE is the safe default; changing strategy later means re-ingesting the whole Data Source, not a config toggle.BEDROCK_FOUNDATION_MODEL parsing costs an extra model call per document - use it for PDFs/tables/complex layout, not already-clean plain text.roleArn passed to CreateKnowledgeBase should read only the intended Data Sources and invoke only the intended embedding model.StartIngestionJob runs per Data Source at a time; check ListIngestionJobs status before starting another in an automated scheduler.statistics, not just job status. A job can report COMPLETE while numberOfDocumentsFailed is nonzero - alert on that field, not just overall success.StartIngestionJob to S3 write events (via EventBridge) or a pipeline's last step rather than relying on someone to remember.Configure the control-plane client with sane retries, since ingestion and creation calls can be throttled under load.
# --- Python (boto3) ---
import boto3
from botocore.config import Config
cfg = Config(retries={"max_attempts": 5, "mode": "adaptive"})
agent = boto3.client("bedrock-agent", region_name="us-east-1", config=cfg)
agent_rt = boto3.client("bedrock-agent-runtime", region_name="us-east-1", config=cfg)// --- TypeScript (AWS SDK v3) ---
import { BedrockAgentClient } from "@aws-sdk/client-bedrock-agent";
import { BedrockAgentRuntimeClient } from "@aws-sdk/client-bedrock-agent-runtime";
const agent = new BedrockAgentClient({ region: "us-east-1", maxAttempts: 5 });
const agentRt = new BedrockAgentRuntimeClient({ region: "us-east-1", maxAttempts: 5 });numberOfResults from evals, not guesswork. Too few misses context; too many dilutes the generation prompt and raises token cost.citations. Even a "successful" RetrieveAndGenerate call can under-cover a multi-part question - check that citations back every part of the answer.bedrock-agent actions (CreateKnowledgeBase, CreateDataSource, StartIngestionJob) only to admin/setup roles; grant bedrock-agent-runtime actions (Retrieve, RetrieveAndGenerate) to request-handling roles.$metadata.requestId (v3) or the boto3 response metadata for both control-plane and data-plane calls so AWS support can trace issues.Deciding chunking strategy and size deliberately. It is expensive to change later because a change requires re-ingesting the entire Data Source, not just updating a setting.
Check statistics.numberOfDocumentsFailed on the completed job, not just its overall COMPLETE status - individual documents can fail silently within an otherwise successful run.
Default to RetrieveAndGenerate for its managed prompt construction and built-in citations. Move to retrieve-then-prompt only when you need custom structure or to mix in context it cannot retrieve itself.
Only for questions you can identify as genuinely multi-step - comparisons, multi-part questions, cross-document synthesis. It adds latency and cost that is wasted on simple single-fact lookups.
Grant bedrock-agent (control-plane) actions only to setup/admin roles, and bedrock-agent-runtime (data-plane) actions only to the roles that serve retrieval requests. Keep the Knowledge Base's own service role scoped narrowly too.
It depends on traffic shape - S3 Vectors' pay-per-use pricing tends to win for large corpora with intermittent queries, while OpenSearch Serverless's capacity model can suit sustained high-QPS traffic better. Model both against your access pattern.
Be careful - retrieved passages carry the same sensitivity as their source documents. Log token counts and request IDs by default; log content only under a clear data-handling policy.
Tag chunks with tenant metadata at ingestion and filter retrieval by it at query time, reserving separate Knowledge Bases for cases that truly require hard isolation.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+). Bedrock Knowledge Bases' Agentic Retriever is a fast-evolving 2026 capability - verify exact parameters against current docs.
Revisado por Chris St. John·Última actualización: 24 jul 2026