langchain-ai / langchain-aws

Build LangChain Applications on AWS
MIT License
71 stars 52 forks source link

Adding bedrock metadata filter and search type parameters #104

Closed ravediamond closed 6 days ago

ravediamond commented 2 weeks ago

Description

This pull request enhances the functionality of theAmazonKnowledgeBasesRetriever class by adding optional parameters for the following features (already implemented in boto3):

Here an example answer before the change:

retriever = AmazonKnowledgeBasesRetriever(
    knowledge_base_id="KNOWLEDGE_BASE_ID,
    retrieval_config={
        "vectorSearchConfiguration": {
            "numberOfResults": 4
        }
    },
)

And now after the change:

retriever = AmazonKnowledgeBasesRetriever(
    knowledge_base_id="KNOWLEDGE_BASE_ID,
    retrieval_config={
        "vectorSearchConfiguration": {
            "numberOfResults": 4,
            "filter": {
                "equals": {"key": "type", "TAG1"}
            },
            "overrideSearchType": "HYBRID"
        }
    },
)

Change

Motivation

This will allow users to better use the full capacity of Bedrock Knowledge Base.

Additional Notes

ravediamond commented 2 weeks ago

@3coins can you please have a look? I confirmed that this PR is working. Thanks in advance.

ravediamond commented 2 weeks ago

@3coins Thank you for the review. I correct my PR as per your recommendations. What do you think ?

ravediamond commented 1 week ago

Ok I corrected as per your reviews and I will create another PR for the nextToken when it is merged. Thanks in advance fir the review @3coins and also for having merged my other PR.