Subchapter 23.19
references/knowledge-bases-retrieval.mdMarkdown8 KBView on GitHub
Assets
Kb Shim PyThree APIs — agents pick the wrong one. Use this table:
| Use Case | API | Endpoint | When |
|---|---|---|---|
| Synthesize answer from docs | RetrieveAndGenerate | bedrock-agent-runtime | Most common RAG pattern. Model reads chunks and generates answer with citations. |
| Get raw chunks for custom processing | Retrieve | bedrock-agent-runtime | You want to rank, filter, or feed chunks to a different model. |
| Full prompt control | Converse with manual context | bedrock-runtime | You retrieve chunks yourself, build a custom prompt, and call the model directly. |
Most common pattern: aws bedrock-agent-runtime retrieve-and-generate --input '{"text":"<query>"}' --retrieve-and-generate-configuration '{"type":"KNOWLEDGE_BASE","knowledgeBaseConfiguration":{"knowledgeBaseId":"<kb-id>","modelArn":"<model-arn>"}}'
Input limit: The --input text field has a maximum of 1000 characters. Exceeding this causes a ValidationException. For longer queries, truncate or summarize before sending.
Bedrock-specific filter syntax — not in model training data. Filters narrow retrieval to relevant documents before semantic search.
Operators:
| Operator | Type | Example |
|---|---|---|
equals | Exact match | {"equals": {"key": "department", "value": "engineering"}} |
notEquals | Exclude | {"notEquals": {"key": "status", "value": "archived"}} |
greaterThan | Number | {"greaterThan": {"key": "year", "value": 2024}} |
greaterThanOrEquals | Number (inclusive) | {"greaterThanOrEquals": {"key": "year", "value": 2024}} |
lessThan | Number | {"lessThan": {"key": "year", "value": 2026}} |
lessThanOrEquals | Number (inclusive) | {"lessThanOrEquals": {"key": "year", "value": 2026}} |
in | Match any in list | {"in": {"key": "category", "value": ["guide", "tutorial"]}} |
notIn | Exclude list | {"notIn": {"key": "type", "value": ["draft", "deprecated"]}} |
startsWith | Prefix match (string) | {"startsWith": {"key": "path", "value": "/docs/api"}} |
stringContains | Substring (string) | {"stringContains": {"key": "title", "value": "setup"}} |
listContains | List attribute contains value (string) | {"listContains": {"key": "tags", "value": "security"}} |
Vector store limitations for operators: startsWith and stringContains are currently best supported with Amazon OpenSearch Serverless vector stores. Neptune Analytics GraphRAG supports the stringContains string variant but not the list variant. listContains is currently best supported with Amazon OpenSearch Serverless. S3 vector buckets do NOT support startsWith or stringContains. If you use these operators with an unsupported vector store, the filter is silently ignored.
Refer to the latest AWS documentation on Bedrock Knowledge Base RetrievalFilter for the full current operator list.
Combining filters:
{
"andAll": [
{"equals": {"key": "department", "value": "engineering"}},
{"greaterThan": {"key": "epoch_modification_time", "value": 1704067200}}
]
}{
"orAll": [
{"equals": {"key": "type", "value": "guide"}},
{"equals": {"key": "type", "value": "tutorial"}}
]
}Constraints:
access_level: "admin") during ingestion, then filter at query time based on the calling user’s role to restrict which documents they can retrieveNon-obvious defaults agents get wrong:
| Parameter | Default | Guidance |
|---|---|---|
overrideSearchType | Not set (Bedrock decides) | When omitted, Bedrock automatically selects the search strategy best suited for your vector store configuration. For OpenSearch Serverless, RDS (including Aurora PostgreSQL), or MongoDB Atlas with a filterable text field, you can explicitly set to HYBRID (keyword + semantic) or SEMANTIC (vector only). For all other vector stores, only SEMANTIC is available. Consider HYBRID when supported for keyword-heavy queries. |
numberOfResults | 5 | Increase for broad questions (10-20), decrease for specific lookups (3-5). More results = higher latency. |
Score confidence threshold: Set to filter low-relevance results.
For multi-turn RAG conversations:
Constraints:
You MUST pass sessionId in RetrieveAndGenerate calls for multi-turn conversations — omitting it causes each query to be independent, silently losing all conversation context
You MUST NOT generate or set sessionId yourself — Amazon Bedrock auto-generates it on the first request; reuse the returned value for subsequent turns
For HIPAA/GDPR workloads, You MUST encrypt session data with a customer-managed KMS key via --session-configuration '{"kmsKeyArn":"<kms-key-arn>"}' — session data includes conversation history which may contain sensitive retrieved content
Context from previous turns carries forward automatically when sessionId is passed
Sessions expire after a timeout — start a new session if expired
For RetrieveAndGenerate only:
guardrailConfigurationThese are retrieval-specific security controls. For general Bedrock security, see the parent skill’s Security Considerations section.
Retrieved chunks are the primary vector for sensitive data exposure in RAG applications. If source documents contain PII/PHI and are not sanitized before ingestion, that sensitive data will be retrieved from the vector store and can leak to users.
Key risks:
citations[].retrievedReferences[].content.text field — this raw text may contain PII even if the generated response is sanitized by guardrailsretrievedReferences returned in the API response at runtimeMitigations:
retrievedReferences content in application logs for PII-sensitive workloadsRetrieve and RetrieveAndGenerate calls are logged as CloudTrail data events (not management events — they are not logged by default). To enable auditing of who queried what from the knowledge base, configure advanced event selectors with resource type AWS::Bedrock::KnowledgeBase. Refer to the latest AWS documentation on Bedrock CloudTrail logging (opens in a new tab).