Adds Bedrock KB metadata to AmazonKnowledgeBasesRetriever Document metadata #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AWS Bedrock Knowledge Bases support custom user metadata per source document. This change adds that metadata to AmazonKnowledgeBasesRetriever Documents metadata as
source_metadata
.This addresses the feature request in langchain-ai/langchain#20649
I'm open to suggestions on the
source_metadata
key name, but I was avoidingmetadata["metadata"]
There are a few different ways to handle this. In this PR,
source_metadata
is set toNone
if the Bedrock KB result does not contain ametadata
key. I prefer this approach as the presence of thesource_metadata
key is guaranteed for the caller - i.e., the caller does not have to check for it's presence.If it's preferred to not set
source_metadata
if it's empty, then here are a couple of options.Requires Python 3.9+
I updated the integration tests to reflect these changes and added a response that includes KB metadata.
I changed the integration test
get_relevant_documents
toinvoke
based onTwo simple typos in README.md were fixed.