Closed leandro-loos closed 1 week ago
Can you share your debug logs (with any sensitive info redacted) by adding --debug
to your command? Also here is the CLI documentation for reference: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/bedrock-agent-runtime/retrieve-and-generate.html. Running that command involves a call to the RetrieveAndGenerate API, so we may need to reach out to the Bedrock team if the API is not behaving as expected.
I ran into the same issue and did some research.
Unlike invoke-model
in the bedrock-runtime
API, you cannot define the session id yourself. Instead, the session id will be created by Amazon Bedrock during the first API call as uuidv4-string and provided in the response object.
You use that session id as parameter for subsequent calls within the same sessions.
Referring to your example:
Initial invocation:
aws bedrock-agent-runtime retrieve-and-generate --retrieve-and-generate-configuration type=KNOWLEDGE_BASE,knowledgeBaseConfiguration="{knowledgeBaseId=<EXISTING_ID>,modelArn=arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0}" --input text="oso test"
Response:
{
"citations": ...
"output" : ...
"sessionId": "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6"
}
Second invocation:
aws bedrock-agent-runtime retrieve-and-generate --retrieve-and-generate-configuration type=KNOWLEDGE_BASE,knowledgeBaseConfiguration="{knowledgeBaseId=<EXISTING_ID>,modelArn=arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0}" --input text="oso test follow-up question" --session-id="1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6"
--debug
Heres the debug data, not much there:
2024-06-21 09:26:44,008 - MainThread - botocore.auth - DEBUG - CanonicalRequest: POST /retrieveAndGenerate
content-type:application/json
host:bedrock-agent-runtime.us-east-1.amazonaws.com
x-amz-date:20240621T072644Z
x-amz-security-token:
content-type;host;x-amz-date;x-amz-security-token
cb8e8bea2324e9d1d6d5ae87eb9d423786c0cfe856444603f40d4689a9f2fd86
2024-06-21 09:26:44,008 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20240621T072644Z
20240621/us-east-1/bedrock/aws4_request
9597558d3920f8224b29e59cd651b41d4e38c840d84ad0124fd84453a2a0c54e
2024-06-21 09:26:44,008 - MainThread - botocore.auth - DEBUG - Signature:
198d57aff31a00bf8db2f37e7ab2ca57dc4fc4c104c9b5ffacc0ea178c032f1c
2024-06-21 09:26:44,008 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://bedrock-agent-runtime.us-east-1.amazonaws.com/retrieveAndGenerate, headers={'Content-Type': b'application/json', 'User-Agent': b'aws-cli/2.15.44 Python/3.11.8 Darwin/23.5.0 exe/x86_64 prompt/off command/bedrock-agent-runtime.retrieve-and-generate', 'X-Amz-Date': b'20240621T072644Z', 'X-Amz-Security-Token':
An error occurred (ValidationException) when calling the RetrieveAndGenerate operation: Session with Id TEST1234 is not valid. Please check and try again.
I ran into the same issue and did some research. Unlike
invoke-model
in thebedrock-runtime
API, you cannot define the session id yourself. Instead, the session id will be created by Amazon Bedrock during the first API call as uuidv4-string and provided in the response object. You use that session id as parameter for subsequent calls within the same sessions.Referring to your example:
Initial invocation:
aws bedrock-agent-runtime retrieve-and-generate --retrieve-and-generate-configuration type=KNOWLEDGE_BASE,knowledgeBaseConfiguration="{knowledgeBaseId=<EXISTING_ID>,modelArn=arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0}" --input text="oso test"
Response:
{ "citations": ... "output" : ... "sessionId": "a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6" }
Second invocation:
aws bedrock-agent-runtime retrieve-and-generate --retrieve-and-generate-configuration type=KNOWLEDGE_BASE,knowledgeBaseConfiguration="{knowledgeBaseId=<EXISTING_ID>,modelArn=arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0}" --input text="oso test follow-up question" --session-id="1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6"
Yes @moellr ! Seems like this is how it works, thanks for the explanation... Quite likely is a matter of explaining it correctly on the docs @tim-finnigan : https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html
Thanks for following up and identifying the issue! I do see in the API documentation that it says the following for sessionId
:
The unique identifier of the session. Reuse the same value to continue the same session with the knowledge base.
So it does mention that the value needs to be reused. But the wording could probably be improved to clarify the behavior a bit better. I reached out to the Bedrock team for feedback on this (ref: P136727715) and will see what they. In the future you can also use the Provide feedback link at the bottom of API documentation pages to send feedback directly to the appropriate team.
We heard back from the team and they went ahead and made the update! Thanks again for bringing this to our attention:
The unique identifier of the session. When you first make a
RetrieveAndGenerate
request, Amazon Bedrock automatically generates this value. You must reuse this value for all subsequent requests in the same conversational session. This value allows Amazon Bedrock to maintain context and knowledge from previous interactions. You can't explicitly set thesessionId
yourself.
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html
This issue is now closed.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
No matter what input I give when calling with a
--session-id
parameter, the following error pops up:An error occurred (ValidationException) when calling the RetrieveAndGenerate operation: Session with Id <WHATEVER> is not valid. Please check and try again.
sample call:
aws bedrock-agent-runtime retrieve-and-generate --retrieve-and-generate-configuration type=KNOWLEDGE_BASE,knowledgeBaseConfiguration="{knowledgeBaseId=<EXISTING_ID>,modelArn=arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0}" --input text="oso test" --session-id="<WHATEVER>"
Tested the same session ids for the
bedrock-runtime
api withinvoke-model
and over there the session ids work just fine.Also, it would be nice if the sessionID would show up on the cloudwatch logs