Skip to content

Integrating metadata filtering within Bedrock flows

0

I have a Bedrock knowledge base with some metadata. My application utilises Bedrock flows. Briefly, the workflow looks like this:

  1. User inputs a query
  2. A query is performed against 3 knowledge bases, each holding different datasets. The retrieval results are returned as an array.
  3. A prompt takes the 3 arrays from the knowledge bases to generate a response.

Now, I would like to use a metadata filter to further refine the results of the retrieval, applying this filter to a specific knowledge-base. Are there any documents providing some guidance on how I can achieve this?

1 Answer
-1

Yes, you can integrate metadata filtering within your Bedrock workflow to refine the results of retrieval for a specific knowledge base. Here's how you can achieve this:

  1. When setting up your knowledge base, ensure that you provide metadata files alongside your source data files. These metadata files should have the same name as the source files with a '.metadata.json' suffix.

  2. In your workflow, when querying the specific knowledge base where you want to apply the metadata filter, you'll need to modify the retrieval configuration. You can do this by passing a filter to the 'retrievalConfiguration' parameter of the Retrieval API or RetrieveAndGenerate API.

  3. The filter should be constructed using the metadata attributes you want to filter on. You can use various operators like equals, notEquals, greaterThan, lessThan, etc., depending on your filtering needs.

  4. Here's an example of how you might structure the retrieval configuration with a metadata filter:

    retrievalConfiguration={ "vectorSearchConfiguration": { "filter": your_metadata_filter } }

  5. You can construct complex filters using multiple conditions if needed.

  6. Apply this filtered retrieval to the specific knowledge base you want to refine, while keeping the other knowledge base queries as they are.

  7. The results from this filtered retrieval will be more targeted and relevant based on your metadata criteria.

  8. You can then proceed with your existing workflow, using these refined results along with the results from the other knowledge bases to generate your final response.

By implementing this approach, you'll be able to leverage metadata filtering to improve the accuracy and relevance of the information retrieved from your targeted knowledge base, while maintaining your overall workflow structure.
Sources
Knowledge Bases for Amazon Bedrock now supports metadata filtering to improve retrieval accuracy | AWS Machine Learning Blog
Amazon Bedrock Knowledge Bases now supports metadata filtering to improve retrieval accuracy | AWS Machine Learning Blog
Streamline RAG applications with intelligent metadata filtering using Amazon Bedrock | AWS Machine Learning Blog

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Does not answer the question. The question is specifically asking how to use Metadata Filtering with "FLOWS" and in retrieve or retrieveAndGenerate API.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.