QueryKnowledgeBasesWithMetadata
Query an Amazon Bedrock knowledge base to retrieve relevant passages with metadata, supporting discovery of metadata keys and values before applying precise filters.
Instructions
Query a knowledge base and include metadata in results.
Use this for metadata-driven exploration (discover what keys/values exist) before applying precise filters. Returns newline-separated JSON objects.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>",
"knowledge_base_id": "<knowledge_base_id>"
},
"name": "QueryKnowledgeBasesWithMetadata"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | A natural language query to search the knowledge base with | |
| where | No | Optional schema-driven metadata constraints. Keys are resolved via the metadata schema: prefer schema aliases, or use direct metadata keys. Values can be scalars, lists (OR within that key), or dicts for operator overrides. | |
| filter | No | Optional raw Bedrock retrieval filter (RetrievalFilter). This is a power-user escape hatch and is only accepted when BEDROCK_KB_ALLOW_RAW_FILTER=true. | |
| reranking | No | Whether to rerank the results. Useful for improving relevance and sorting. Can be globally configured with BEDROCK_KB_RERANKING_ENABLED. | |
| where_join | No | How to combine schema-driven `where` constraints. Default is AND (narrow). OR is supported within friendly filters only. | AND |
| filter_mode | No | How to combine explicit filters (`where`/raw) and implicit filtering. 'explicit_then_implicit' applies explicit filters when provided, and also enables implicit filtering when requested; it composes constraints with AND semantics. | explicit_then_implicit |
| search_type | No | Search strategy for retrieval. 'HYBRID' combines keyword + semantic search and is recommended for OpenSearch Serverless; 'SEMANTIC' uses embeddings only; 'DEFAULT' lets Bedrock decide. | DEFAULT |
| data_source_ids | No | The data source IDs to filter the knowledge base by. It must be a list of valid data source IDs from the ListKnowledgeBases tool. | |
| implicit_filter | No | Enable Bedrock implicit filtering for this call (requires BEDROCK_KB_IMPLICIT_FILTER_MODEL_ARN). | |
| content_max_chars | No | If set, truncate returned TEXT content to this many characters to reduce tool output size. | |
| knowledge_base_id | Yes | The knowledge base ID to query. It must be a valid ID from the ListKnowledgeBases tool. | |
| number_of_results | No | The number of results to return. Prefer smaller values for metadata-driven discovery. If omitted and implicit_filter=true, defaults to 25; otherwise defaults to 6. | |
| metadata_schema_mode | No | Metadata schema resolution mode. 'static' uses only configured schema files; 'auto' falls back to sampling retrieval metadata to infer a schema. | auto |
| reranking_model_name | No | The name of the reranking model to use. Options: 'COHERE', 'AMAZON'. | AMAZON |
| metadata_schema_auto_sample_k | No | Number of retrieval results to sample for auto schema discovery. | |
| metadata_schema_auto_sample_query | No | Query used for auto schema discovery (only when metadata_schema_mode=auto). | the |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |