feat(memory): support managed Bedrock knowledge bases in retrieve and ACL#2909
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Documentation Preview ReadyYour documentation preview has been successfully deployed! Changed pages: Updated at: 2026-06-24T22:18:15.800Z |
Add an optional access_control_list / accessControlList param to BedrockKnowledgeBaseStoreConfig, stamped on every write. Required by ACL-enabled data sources on managed knowledge bases. For CUSTOM data sources the entries are passed through verbatim (lowercase fields). For S3 data sources they are translated to the sidecar's capitalized field names (Name/Type/Access). When a write fails because the data source requires an ACL and none is configured, the store rewrites the ValidationException into a ValueError/Error pointing at the new param. An inline ACL on the CUSTOM path requires at least one metadata attribute (scope or caller metadata); the store raises early with guidance rather than letting the API reject it with a cryptic error. Validated end-to-end against a live managed knowledge base with ACL enabled: no-ACL error rewrite, ACL-only guard, and ACL+scope successful ingest all confirmed.
The managed knowledge base types (KnowledgeBaseRetrievalConfiguration with managedSearchConfiguration, DocumentAccessControlEntry) were added in SDK build 3.1075.0. Restore the typed imports that were removed when the older SDK couldn't resolve them.
Previously a failed GetKnowledgeBase call was not cached, causing a repeated failing control-plane call on every search(). Cache the VECTOR fallback so subsequent searches skip the redundant network round-trip. Also tighten the ACL test assertion to check the full metadata shape.
Replace the lazy fallback-to-VECTOR detection with an eager initialize() method on MemoryStore. MemoryManager.initAgent calls it at agent startup so a missing GetKnowledgeBase permission fails fast instead of silently mis-routing searches. - Add optional initialize() to the MemoryStore protocol/interface - MemoryManager.init_agent / initAgent is now async; calls initialize() - BedrockKnowledgeBaseStore.initialize() is idempotent and also called lazily on first search() for standalone usage - Add knowledge_base_type / knowledgeBaseType config — skips GetKnowledgeBase - Support all KB types (MANAGED, VECTOR, KENDRA, SQL) - Remove _logging.py (warn_once no longer needed) - Tighten test assertions to full metadata shape - Update docs with new config param and IAM note
bf4e0ac to
c94cd44
Compare
|
Assessment: Comment The eager- Review themes
Nicely scoped overall, and the ACL serialization across CUSTOM (inline) and S3 (capitalized sidecar) is clean and well-documented. |
- Update stale class docstrings (Python + TS) to reflect eager fail-fast behavior instead of old silent-fallback language - Add error logging in initialize() before re-raising, matching the pattern used by search() and add() - Use non-null assertions in TS initialize() so a missing type throws instead of silently being undefined (parity with Python's KeyError) - Type knowledge_base_type as Literal union in Python for parity with TS
|
Issue (PR description): The description still states detection "fails open... preserving behavior for existing stores" and "No breaking changes." After the eager- Suggestion: Update the description to describe the fail-fast behavior and call out the new |
|
Assessment: Comment This round closes most of the prior feedback — the class docstrings now describe the fail-fast detection accurately, the Python ACL tests assert full Review themes
The ACL serialization across CUSTOM (inline, lowercase) and S3 (capitalized sidecar) is clean and well-documented, and the live-validation notes against a real managed KB are a nice touch. |
Description
Amazon Bedrock recently launched managed knowledge bases, where Bedrock owns the ingestion, indexing, and storage infrastructure. They are queried differently from the self-managed (vector) knowledge bases this store was built for:
Retrievetakes amanagedSearchConfigurationrather than avectorSearchConfiguration. Until nowBedrockKnowledgeBaseStorealways sentvectorSearchConfiguration, sosearch()against a managed knowledge base was malformed.This change makes the store work with all knowledge base types. On agent startup (or first
search()for standalone usage), it resolves the knowledge base type viaGetKnowledgeBase, caches the result, and wraps the retrieval config under the matching key (managedSearchConfigurationforMANAGED,vectorSearchConfigurationfor everything else). Detection is eager:MemoryManager.initAgentnow callsinitialize()on each store, so a missingbedrock:GetKnowledgeBasepermission fails fast at construction rather than silently mis-routing searches at runtime. A newknowledge_base_type/knowledgeBaseTypeconfig option lets callers skip theGetKnowledgeBasecall entirely when the type is known ahead of time.Additionally, managed knowledge bases commonly have ACL awareness enabled on their data sources. An ACL-enabled data source rejects ingestion without a per-document access control list. This change adds an optional
access_control_list/accessControlListparam so users of ACL-enabled data sources can write memories. If the param is absent and Bedrock rejects with an ACL error, the store rewrites the exception to point at the new field.Both features are mirrored across the Python and TypeScript SDKs.
Public API additions:
access_control_list/accessControlListonBedrockKnowledgeBaseStoreConfig(optional, affects writes only)BedrockKnowledgeBaseAccessControlEntrytypeknowledge_base_type/knowledgeBaseTypeonBedrockKnowledgeBaseConfig(optional, skipsGetKnowledgeBase)initialize()method on theMemoryStoreprotocol/interface (optional, called byMemoryManager)MemoryManager.init_agent/initAgentis now async (callsinitialize()on stores)No breaking changes to the end-user API. The
init_agent/initAgentasync change is internal to the plugin lifecycle (Plugin.initAgent); agent construction already awaits plugin initialization. Stores withoutinitialize()are unaffected. TheGetKnowledgeBaseauto-detection is internal, and both new config params are optional (stores without them work exactly as before).Related Issues
Type of Change
New feature
Testing
Unit tests: Both SDKs — managed type detection (routing, memoization, all KB types), eager initialization via
MemoryManager, ACL on CUSTOM (inline metadata, ACL-only guard, error rewrite), ACL on S3 (sidecar capitalization, ACL-only sidecar, combined scope+ACL).Live validation: Ran against a real managed knowledge base (
WFQFKU3TIR,example-managed-kb, us-east-1) with ACL enabled:access_control_list✅_kb_typedetected asMANAGED,managedSearchConfigurationsent, no error ✅No CDK/CI integ coverage — CloudFormation does not yet expose
managedKnowledgeBaseConfiguration, so the test-infra stack can't provision a managed KB. Follow-up when CFN support lands.hatch run prepareChecklist