Skip to content

Is it possible to send multiple S3 urls to filter a knowledge base?

0

I have a knowledge base that contains multiple folders and I want to filter using multiple urls but when sending several urls from S3 it gives me the following error: "An error occurred (ValidationException) when calling the RetrieveAndGenerate operation: The filter value type provided isn't supported for the given operation: STARTS_WITH."

According to the documentation, if it is possible to send an array, is there a special way to do it?

me:

  • 'vectorSearchConfiguration': { 'filter': { 'startsWith': { 'key': 'x-amz-bedrock-kb-source-uri', 'value': ['s3://bedrock-sp/folder/subfolder1/','s3://bedrock-sp/folder/subfolder2/'] } } }*

boto3 documentation:

  • 'startsWith': { 'key': 'string', 'value': {...}|[...]|123|123.4|'string'|True|None },*
2 Answers
0

The error you're encountering suggests that the STARTS_WITH filter is not accepting an array as its value. According to the boto3 documentation https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent-runtime/client/retrieve.html, the value for startsWith should be a single string, not an array of strings.

Here's a more precise way to handle this scenario: Use Multiple Filters: Instead of sending an array of URLs, you can apply multiple startsWith filters for each URL. Logical Combinations: If the API allows combining multiple filters with logical OR conditions, use that. Given your current setup, you need to apply each startsWith filter separately. Here's an example of how you might structure it if logical combinations are allowed:

Example with Multiple startsWith Filters

vectorSearchConfiguration = {
    'filter': {
        'or': [
            {'startsWith': {'key': 'x-amz-bedrock-kb-source-uri', 'value': 's3://bedrock-sp/folder/subfolder1/'}},
            {'startsWith': {'key': 'x-amz-bedrock-kb-source-uri', 'value': 's3://bedrock-sp/folder/subfolder2/'}}
        ]
    }
}

If you need to apply filters separately, you would have to create separate requests or iterate through your filters.

EXPERT
answered a year ago
  • I leave a response with my tests, thank you

0

bro @A_J, I did tests and I was able to send 5 different urls, the problem is that there is only a limit (5), I tried to make a combination but when I ask a question about a subfolder it does not return information, I leave the example and continue doing tests to achieve a result that returns the information of each url that I send, thanks:

{
   "orAll":[
      {
         "orAll":[
            {
               "startsWith":{
                  "key":"x-amz-bedrock-kb-source-uri",
                  "value":"s3://bedrock-sp/folderB/sub1/"
               }
            },
            {
               "startsWith":{
                  "key":"x-amz-bedrock-kb-source-uri",
                  "value":"s3://bedrock-sp/folderB/sub2/"
               }
            },
            {
               "startsWith":{
                  "key":"x-amz-bedrock-kb-source-uri",
                  "value":"s3://bedrock-sp/folderB/sub3/"
               }
            },
            {
               "startsWith":{
                  "key":"x-amz-bedrock-kb-source-uri",
                  "value":"s3://bedrock-sp/folderB/sub4/"
               }
            }
         ]
      },
	  {
         "orAll":[
            {
               "startsWith":{
					"key":"x-amz-bedrock-kb-source-uri",
					"value":"s3://bedrock-sp/folderB/sub5/"
               }
            },
            {
               "startsWith":{
					"key":"x-amz-bedrock-kb-source-uri",
					"value":"s3://bedrock-sp/folderB/sub6/"
               }
            },
            {
               "startsWith":{
					"key":"x-amz-bedrock-kb-source-uri",
					"value":"s3://bedrock-sp/folderB/sub7/"
               }
            },
            {
               "startsWith":{
					"key":"x-amz-bedrock-kb-source-uri",
					"value":"s3://bedrock-sp/folderB/sub8/"
               }
            }
         ]
      }
   ]
}
answered a year ago

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.