Amazon Knowledge Base retriever support with new metadata feature? #4928
Replies: 2 comments
-
Hey there, @langchainuser404! Great to see you diving into some exciting features again. How's everything going with your LangChain adventures? Based on the context provided, it seems like you're trying to retrieve custom metadata from an Amazon Bedrock knowledge base using the To retrieve custom metadata, you need to extend the import { AmazonKnowledgeBaseRetriever } from "@langchain/community/retrievers/amazon_knowledge_base";
class CustomMetadataAmazonKnowledgeBaseRetriever extends AmazonKnowledgeBaseRetriever {
constructor(options) {
super(options);
}
async getRelevantDocuments(query) {
const response = await super.getRelevantDocuments(query);
const documentsWithCustomMetadata = response.map(doc => ({
...doc,
customMetadata: "Your custom metadata here" // Replace this with actual logic to fetch custom metadata
}));
return documentsWithCustomMetadata;
}
}
// Usage
const retriever = new CustomMetadataAmazonKnowledgeBaseRetriever({
topK: 10,
knowledgeBaseId: "YOUR_KNOWLEDGE_BASE_ID",
region: "us-east-2",
clientOptions: {
credentials: {
accessKeyId: "YOUR_ACCESS_KEY_ID",
secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
},
},
});
const docs = await retriever.getRelevantDocuments("How are clouds formed?");
console.log(docs); This is a simplified example and you'll need to adjust it based on the actual API for fetching documents with custom metadata. The logic inside the You can refer to the examples/src/retrievers/amazon_knowledge_bases.ts for more details on how to use the As for the pull request you found, it seems to be related to the feature you're looking for. However, without more details about the changes made in the pull request, it's hard to say for sure if it's directly related to your issue. It would be helpful if you could provide more information about the changes made in the pull request. I hope this helps! If you have any more questions or need further clarification, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Fixed in #5535! |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Knowledge Bases for Amazon Bedrock now support metadata (press release).
Can Langchain Amazon Knowledge Bases retriever be integrated to this? I have tested so far, but I am not seeing any such metadata that I created custom.
My understanding is metadata is just added here: https://github.com/langchain-ai/langchainjs/pull/4035/files#diff-6c9ea40663ca59cf62a9488a979044d9140b820dfb09b42749db8880546f87c2R101-R104
Is my understanding correct? If not how I can I currently modify the retriever to pull my custom metadata that I am storing in bedrock knowledge base?
System Info
langchain==0.1.13
Beta Was this translation helpful? Give feedback.
All reactions