AnishMachamasi / Building-a-Generative-AI-chatbot-using-Amazon-Bedrock

3 stars 5 forks source link

Embedding are empty #2

Open adnanrizve opened 5 months ago

adnanrizve commented 5 months ago

This lambda function LambdaEmbeddingtoOpenSearch/lambda_function.py so unable to generate embeddings by using Amazon Bedrock Embedding model.

In this part of code, embedding variable is empty because of the the vector_field inside OpenSearch is not storing any value.

response = bedrock.invoke_model( body=body, modelId=modelId, accept=accept, contentType=contentType ) response_body = json.loads(response.get("body").read())

embedding = response_body.get("embedding")

Due to this when retrieval is happing, error is generating

AnishMachamasi commented 5 months ago

The reason that you might be getting error when invoking model is that you may not have proper access to bedrock titan embedding model. I need you to confirm if you have proper access. Otherwise, the code should just work fine.

adnanrizve commented 5 months ago

thanks for your response. I did verify the access, do have access.

bedrockaccessconfirm

I can also see the list of foundation models in the cloudwatch logs for the lambda.

When lambda is making a call to bedrock for embedding, its getting following response, going to debug further

{'Output': {'__type': 'com.amazon.coral.service#UnknownOperationException'}, 'Version': '1.0'}

it might be related to the Boto3 version which is present in the layer

adnanrizve commented 4 months ago

Nothing really worked for me. At then end, I upgraded the lambda runtime to 3.11 and gathered the required layer with newer versions of dependencies. I am now using boto3 (1.34.76). Even after this got {'Output': {'__type': 'com.amazon.coral.service#UnknownOperationException'}, 'Version': '1.0'} error.

Then removed "endpoint_url" from client creation and used bedrock-runtime as service_name. Finally able to make a call to bedrock and able to generate embedding.

bedrock = boto3.client( service_name='bedrock-runtime', region_name='us-east-1' )

Just sharing this here, might be helpful for others.