retrieveAndGenerate Syntax Error: Unknown parameter generationConfiguration or retrievalConfiguration (Claude-v3, Amazon Bedrock)

0

I am trying to retrieve and generate response from knowledge base use claude-v3 model. To do so I followed the boto3 documentation and blog post on Amazon and created the following method:

def retrieveAndGenerate(input, kbId, modelArn=None):
    response = boto_runtime.retrieve_and_generate(
        input={
            'text': input
        },
        retrieveAndGenerateConfiguration={
            'knowledgeBaseConfiguration': {
                'generationConfiguration': {
                    'promptTemplate': {
                        'textPromptTemplate': promptTemplate
                    }
                },
                'knowledgeBaseId': kbId,
                'modelArn': modelArn,
                "retrievalConfiguration": {
                    'vectorSearchConfiguration': {
                        'numberOfResults': 5
                    }
                }
            },
            'type': 'KNOWLEDGE_BASE'
        }
    )
    
    return response

But it is giving me the following error:

ParamValidationError: Parameter validation failed: Unknown parameter in retrieveAndGenerateConfiguration.knowledgeBaseConfiguration: "generationConfiguration", must be one of: knowledgeBaseId, modelArn
Unknown parameter in retrieveAndGenerateConfiguration.knowledgeBaseConfiguration: "retrievalConfiguration", must be of one: knowledgeBaseId, modelArn

The same error is raised with even one of aforementioned fields.

I tried to put generationConfiguration and retrievalConfiguration out of knowledgeBaseConfiguration but those cases are also raising the same error.

It only works with minimum required fields like this:

def retrieveAndGenerate(input, kbId, modelArn=None):
    response = boto_runtime.retrieve_and_generate(
        input={
            'text': input
        },
        retrieveAndGenerateConfiguration={
            'knowledgeBaseConfiguration': {
                'knowledgeBaseId': kbId,
                'modelArn': modelArn
            },
            'type': 'KNOWLEDGE_BASE'
        }
    )
    
    return response

In both cases I am calling the method with the same inputs:

anthropicModelArns = ['arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0']
response = retrieveAndGenerate(input='Felsefe nedir?', kbId='VPY6GXXXXX', modelArn=anthropicModelArns[0])

What is it I am doing wrong and how do I solve it? Appreciate your responses.

Full trace of the exception:

ParamValidationError                      Traceback (most recent call last)
Cell In[45], line 1
----> 1 response = retrieveAndGenerate(input='Felsefe nedir?', kbId='VPY6GXXXX', modelArn=anthropicModelArns[0])
Cell In[44], line 2
1 def retrieveAndGenerate(input, kbId, modelArn=None):
----> 2     response = boto_runtime.retrieve_and_generate(
3         input={
4             'text': input
5         },
6         retrieveAndGenerateConfiguration={
7             'knowledgeBaseConfiguration': {
8                 'generationConfiguration': {
9                     'promptTemplate': {
10                         'textPromptTemplate': promptTemplate
11                     }
12                 },
13                 'knowledgeBaseId': kbId,
14                 'modelArn': modelArn,
15                 "retrievalConfiguration": {
16                     'vectorSearchConfiguration': {
17                         'numberOfResults': 5
18                     }
19                 }
20             },
21             'type': 'KNOWLEDGE_BASE'
22         }
23     )
25     return response
File /usr/local/lib/python3.12/site-packages/botocore/client.py:553, in ClientCreator._create_api_method.<locals>._api_call(self, *args, **kwargs)
549     raise TypeError(
550         f"{py_operation_name}() only accepts keyword arguments."
551     )
552 # The "self" in this scope is referring to the BaseClient.
--> 553 return self._make_api_call(operation_name, kwargs)
File /usr/local/lib/python3.12/site-packages/botocore/client.py:962, in BaseClient._make_api_call(self, operation_name, api_params)
958 if properties:
959     # Pass arbitrary endpoint info with the Request
960     # for use during construction.
961     request_context['endpoint_properties'] = properties
--> 962 request_dict = self._convert_to_request_dict(
963     api_params=api_params,
964     operation_model=operation_model,
965     endpoint_url=endpoint_url,
966     context=request_context,
967     headers=additional_headers,
968 )
969 resolve_checksum_context(request_dict, operation_model, api_params)
971 service_id = self._service_model.service_id.hyphenize()
File /usr/local/lib/python3.12/site-packages/botocore/client.py:1036, in BaseClient._convert_to_request_dict(self, api_params, operation_model, endpoint_url, context, headers, set_user_agent_header)
1027 def _convert_to_request_dict(
1028     self,
1029     api_params,
(...)
1034     set_user_agent_header=True,
1035 ):
-> 1036     request_dict = self._serializer.serialize_to_request(
1037         api_params, operation_model
1038     )
1039     if not self._client_config.inject_host_prefix:
1040         request_dict.pop('host_prefix', None)
File /usr/local/lib/python3.12/site-packages/botocore/validate.py:381, in ParamValidationDecorator.serialize_to_request(self, parameters, operation_model)
377     report = self._param_validator.validate(
378         parameters, operation_model.input_shape
379     )
380     if report.has_errors():
--> 381         raise ParamValidationError(report=report.generate_report())
382 return self._serializer.serialize_to_request(
383     parameters, operation_model
384 )
ParamValidationError: Parameter validation failed:
Unknown parameter in retrieveAndGenerateConfiguration.knowledgeBaseConfiguration: "generationConfiguration", must be one of: knowledgeBaseId, modelArn
Unknown parameter in retrieveAndGenerateConfiguration.knowledgeBaseConfiguration: "retrievalConfiguration", must be one of: knowledgeBaseId, modelArn
1 Answer
1
Accepted Answer

Hi There

Your boto3 and botocore packages need to be updated to at least version1.34.71 , which is when the API was updated to include generationConfiguration and retrievalConfiguration parameters.

See line 548 at https://github.com/boto/botocore/commit/e34411f9b4aba6f5913337d3eecfc05c9b80bd2b#diff-05849e7e701ee702a7c1b1444627c9994b0ae801e29bce41a5915c8900164aee

profile pictureAWS
EXPERT
Matt-B
answered 16 days ago
  • Thank you for your response. I deleted the modules and reinstalled them. The latest versions are also producing the same error. I don't know if it is the source of the error, I am running the code in a jupyter notebook inside a docker container.

    These are my versions:

    pip freeze | grep boto
    boto3==1.34.84
    botocore==1.34.84
    
     python --version
    Python 3.12.1
    

    Also to initialize agent-runtime-client I use this code snippet (don't mind the env keywords please):

    boto_runtime = boto3.client('bedrock-agent-runtime', 
                                aws_access_key_id=os.getenv('AWS_S3_BEDROCK_KEY'),
                                aws_secret_access_key=os.getenv('AWS_S3_BEDROCK_SECRET'),
                                region_name=os.getenv('AWS_S3_BEDROCK_REGION'))
    
  • Please run the following code snippet to ensure your Python runtime is using the expected version. Your pip may be installing/reporting on a different python environment

    import boto3
    print(boto3.__version__)
    
  • Thank you very much for your response.

    Even though the library was giving the error with version 1.34.84, when I installed older 1.34.71 version, it worked. My current versions are followings:

    pip freeze | grep boto
    boto3==1.34.71
    botocore==1.34.84
    
  • I did check the versions from code itself and for both boto3 and botocore it was the latest version: 1.34.84 before installing the older one.

    I think the error could be related to my docker container. After installing the older version I also restarted the container. Even though I have volume in the workspace, I think this also had a play in the outcome.

    Thank you again, really appreciate it.

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.

Guidelines for Answering Questions