

# AWS Context integration with managed knowledge bases

You can connect a managed Amazon Bedrock knowledge base to AWS Context to bring your unstructured documents and application content into an Agent Context. AWS Context connects to databases, documents, and applications and builds an Agent Context: a governed graph of your data, business definitions, and rules. Agents reach an Agent Context through MCP tools and APIs. You set up the knowledge base and its data sources in Amazon Bedrock, create a `BEDROCK_KNOWLEDGE_BASE` connection to the knowledge base in AWS Context, and bind the connection into an Agent Context.

After you bind the connection, the knowledge base sends content to AWS Context each time one of its data sources syncs. AWS Context runs ontology-guided extraction over that content and copies each document's access control list (ACL) onto the nodes it builds. At query time, AWS Context reads the knowledge base to return content and to confirm that the end user can still read each document.

**Important**  
If a data source doesn't crawl ACLs, its documents are sent as public, and every caller that can query the Agent Context can receive content extracted from them. Turn on ACLs on each data source where you want per-user results.

## Prerequisites
<a name="integrate-managed-kb-context-prereqs"></a>
+ An active managed Amazon Bedrock knowledge base in the same AWS Region as the Agent Context.
+ The knowledge base and the Agent Context in the same AWS account, by default. For a knowledge base in another account, see the cross-account step that follows.
+ At least one data source connected to the knowledge base.
+ ACLs turned on for each data source where you want per-user results. For more information, see [Access Control Lists awareness enablement](kb-managed-acl.md).

## Connect a managed knowledge base to AWS Context
<a name="integrate-managed-kb-context-setup"></a>

To connect your managed knowledge base to AWS Context, complete the following steps.

**To connect a managed knowledge base to AWS Context**

1. **Create the knowledge base and connect data sources.** Create a managed knowledge base and connect its data sources, turning on ACLs where you want per-user results. For more information, see [Create a managed knowledge base](kb-managed-create.md) and [Connect a data source](kb-managed-connect-ds.md).

   Note the knowledge base ARN. The ARN format is:

   ```
   arn:aws:bedrock:{{REGION}}:{{ACCOUNT_ID}}:knowledge-base/{{KB_ID}}
   ```

   You can find the ARN in the Amazon Bedrock console on the knowledge base details page, or by calling the `GetKnowledgeBase` API.

1. **Create the ingestion role.** In the Agent Context account, create an ingestion role that Amazon Bedrock assumes to send the knowledge base's content to AWS Context. Grant the role `context:IngestAgentContext`, limited to this knowledge base with the `context:SourceArn` condition, and `bedrock:SendKnowledgeBaseEntities` on the knowledge base.

1. **Set up query access.** Choose how AWS Context reads the knowledge base at query time:
   + The caller's credentials (default). AWS Context reads the knowledge base with the credentials of the principal that calls the Agent Context, through forward access sessions. Attach read permissions to the callers' roles.
   + A data access role that AWS Context assumes, with a trust principal of `context.amazonaws.com`. The role's permissions decide what every caller can read.

   Read permissions are `bedrock:Retrieve`, `bedrock:GetDocumentContent`, and `bedrock:GetKnowledgeBase`. The principal that creates the connection needs `iam:PassRole` for the ingestion role and for the data access role, if you use one.

1. **(Optional) Grant cross-account access.** Skip this step if the knowledge base and the Agent Context are in the same AWS account. For a knowledge base in another account, the knowledge base owner adds statements to the knowledge base's resource policy. These statements grant access to the ingestion role and to the identity that reads the knowledge base, both in the Agent Context account. Only managed knowledge bases support resource policies, and the knowledge base and Agent Context must be in the same AWS Region. For more information, see [Resource policies for managed knowledge bases](kb-managed-cross-account.md).

1. **Create the connection and bind it.** In AWS Context, call the `CreateConnection` operation with `dataSource.type` set to `BEDROCK_KNOWLEDGE_BASE`, `dataSource.location.arn` set to the knowledge base ARN, the ingestion role in `ingestionConfig`, and the data access role, if used, in `accessConfig`. If the knowledge base is encrypted with a customer managed AWS KMS key, add `CUSTOMER_MANAGED_KEY` to `acknowledgements`; otherwise `CreateConnection` returns a `ValidationException`. Then bind the `ACTIVE` connection into the Agent Context through a data mapping (`connectionMappings`).

1. **Sync the data sources.** AWS Context doesn't schedule syncs. Control the timing with the data source sync schedule or a manual sync. Content flows to AWS Context on each sync. For more information, see [Sync a data source](kb-managed-sync.md).

## Per-user results at query time
<a name="integrate-managed-kb-context-identity"></a>

When the request carries the end user's identity, AWS Context propagates it to the knowledge base, which returns only documents that user can read. The knowledge base matches users by email address, with no alias resolution. For more information, see [Use IAM Identity Center identities for ACL-aware retrieval](kb-managed-identity-idc.md).

## Related documentation
<a name="integrate-managed-kb-context-more-info"></a>

For detailed setup instructions, permissions policies, query access options, and troubleshooting, see [Connect a managed knowledge base to AWS Context](https://docs.aws.amazon.com/context/latest/userguide/unstructured-connect-kb.html) in the *AWS Context User Guide*.