aws.bedrock.query_knowledge_base ​
Query a Bedrock Knowledge Base and return a grounded answer
Query an Amazon Bedrock Knowledge Base using RetrieveAndGenerate.
Retrieves relevant documents from the KB and generates a grounded answer using the specified foundation model.
Inputs:
- knowledge_base_id: Bedrock Knowledge Base ID (required).
- query: Natural-language question to ask (required).
- model_arn: Foundation model ARN to use for generation (optional, default: anthropic.claude-3-haiku-20240307-v1:0 in us-east-1).
- max_results: Maximum number of source chunks to retrieve (optional, default: 5).
Outputs (terminal state_data):
- answer: str — generated answer grounded in the KB
- citations: list — list of {text, location} source chunks used
- query: str — original question echoed back
- knowledge_base_id: str — KB ID echoed back
- model_arn: str — model ARN used
- max_results: int — number of chunks retrieved
Compensation: N/A (read-only query). Plugin required: context.get_plugin("aws") must expose .bedrock_agent_runtime_client().
Overview ​
| Property | Value |
|---|---|
| Workflow type | Atomic |
| Library | Base-aws |
| Version | 1.0 |
Input Schema ​
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
knowledge_base_id | string | Yes | — | Bedrock Knowledge Base ID |
query | string | Yes | — | Natural-language question |
model_arn | string | No | — | Foundation model ARN for generation |
max_results | integer | No | — | Max source chunks to retrieve (default: 5) |
Output Schema ​
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
knowledge_base_id | string | No | — | Bedrock Knowledge Base ID echoed from input |
query | string | No | — | Original question echoed from input |
model_arn | string | No | — | Foundation model ARN used for generation |
max_results | integer | No | — | Number of source chunks retrieved |
answer | string | No | — | Generated answer grounded in the Knowledge Base |
citations | list | No | — | List of {text, location} source chunks used |
failure_reason | string | No | — | — |
failure_type | string | No | — | — |
failed_action | string | No | — | — |
failed_at_state | string | No | — | — |
failed_step | string | No | — | — |
failed_layer | string | No | — | — |
error | string | No | — | — |
error_type | string | No | — | — |
States ​
| State | Initial | Terminal | Success | Auto-advance | Description |
|---|---|---|---|---|---|
pending | Yes | No | — | execute | — |
completed | No | Yes | Yes | — | — |
failed | No | Yes | No | — | — |
State Diagram ​
Transitions ​
| From | Action | To | Description |
|---|---|---|---|
pending | execute | completed | — |
* (any state) | fail | failed | — |
API Usage ​
bash
POST /api/workflows/start
Content-Type: application/json
{
"workflow_type": "aws.bedrock.query_knowledge_base",
"initial_data": {
"knowledge_base_id": "value",
"query": "value"
}
}