Skip to content

feat: add Managed Knowledge Base support to AWS Bedrock KB Retriever#6612

Draft
PVidyadhar wants to merge 1 commit into
FlowiseAI:mainfrom
PVidyadhar:bmkb-managed-kb-support
Draft

feat: add Managed Knowledge Base support to AWS Bedrock KB Retriever#6612
PVidyadhar wants to merge 1 commit into
FlowiseAI:mainfrom
PVidyadhar:bmkb-managed-kb-support

Conversation

@PVidyadhar

Copy link
Copy Markdown
  • Added Knowledge Base Type dropdown (MANAGED/VECTOR)
  • MANAGED path tries langchain first, falls back to direct Bedrock API
  • Direct API uses managedSearchConfiguration
  • Returns proper langchain Document objects via BaseRetriever subclass
  • Unit tests included
  • Added BEDROCK_MANAGED_KB.md design doc

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Amazon Bedrock Managed Knowledge Bases to the AWSBedrockKBRetriever node, allowing users to select between managed and traditional vector search. It implements a new ManagedKBRetriever class that supports agentic retrieval with query decomposition and automatic fallback mechanisms, adds corresponding unit tests, and provides documentation. The code review feedback suggests several key improvements: adding defensive nullish checks to prevent runtime errors in getSourceUri, optimizing performance by avoiding dynamic imports inside the query execution loop, and using the public getRelevantDocuments method instead of the protected _getRelevantDocuments to ensure LangChain lifecycle hooks and tracing are preserved.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +7 to +8
function getSourceUri(result: any): string {
const location = result.location ?? {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime errors, add a defensive nullish check for the result parameter using loose equality (== null). Since this handles potentially invalid data from an external source, prefer throwing an error rather than silently returning an empty value.

Suggested change
function getSourceUri(result: any): string {
const location = result.location ?? {}
function getSourceUri(result: any): string {
if (result == null) {
throw new Error('Invalid result received from AWS Bedrock')
}
const location = result.location ?? {}
References
  1. In JavaScript/TypeScript, use loose equality (== null) as a standard idiom for a 'nullish' check that covers both null and undefined.
  2. When handling potentially invalid data from external sources (like an API response), prefer throwing an error for invalid input types rather than silently returning a default or empty value. This promotes fail-fast behavior.

}
})

const { BedrockAgentRuntimeClient, RetrieveCommand } = await import('@aws-sdk/client-bedrock-agent-runtime')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Import AgenticRetrieveStreamCommand here along with the other Bedrock client classes. This allows us to avoid re-importing the module dynamically on every single query execution inside _getRelevantDocuments.

Suggested change
const { BedrockAgentRuntimeClient, RetrieveCommand } = await import('@aws-sdk/client-bedrock-agent-runtime')
const { BedrockAgentRuntimeClient, RetrieveCommand, AgenticRetrieveStreamCommand } = await import('@aws-sdk/client-bedrock-agent-runtime')

Comment on lines +175 to +180
// Try agentic retrieval first if enabled
const useAgenticRetrieval = process.env.USE_AGENTIC_RETRIEVAL !== 'false'
if (useAgenticRetrieval) {
try {
const { AgenticRetrieveStreamCommand } = await import('@aws-sdk/client-bedrock-agent-runtime')
const agenticCmd = new AgenticRetrieveStreamCommand({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the pre-imported AgenticRetrieveStreamCommand and perform a feature-detection check. This avoids the overhead of dynamic imports on every query execution.

                    // Try agentic retrieval first if enabled
                    const useAgenticRetrieval = process.env.USE_AGENTIC_RETRIEVAL !== 'false'
                    if (useAgenticRetrieval && AgenticRetrieveStreamCommand) {
                        try {
                            const agenticCmd = new AgenticRetrieveStreamCommand({


try {
// Try langchain path (will work once @langchain/aws adds managed support)
return await langchainRetriever._getRelevantDocuments(query)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid calling the protected method _getRelevantDocuments directly on langchainRetriever. Bypassing the public API skips standard LangChain lifecycle hooks, callbacks, and tracing (e.g., LangSmith). Use the public getRelevantDocuments method instead.

Suggested change
return await langchainRetriever._getRelevantDocuments(query)
return await langchainRetriever.getRelevantDocuments(query)

@PVidyadhar PVidyadhar force-pushed the bmkb-managed-kb-support branch from b8ae9f8 to ca93f4f Compare July 12, 2026 20:51
- Added Knowledge Base Type dropdown (MANAGED/VECTOR)
- MANAGED path tries langchain first, falls back to direct Bedrock API
- Direct API uses managedSearchConfiguration
- Returns proper langchain Document objects via BaseRetriever subclass
- Unit tests included
- Added BEDROCK_MANAGED_KB.md design doc
@PVidyadhar PVidyadhar force-pushed the bmkb-managed-kb-support branch from ca93f4f to e165f6a Compare July 12, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant