Skip to content

Amazon Bedrock: Questions about RetrieveAndGenerateCommand

0

Hi, i have a question regarding Amazon Bedrock, So i'm using RetrieveAndGenerateCommand From the SDK, With the following request:

{
        input: {
            text: input,
        },
        retrieveAndGenerateConfiguration: {
            knowledgeBaseConfiguration: {
                knowledgeBaseId: "<KnowledgeBaseId>",
                modelArn: "anthropic.claude-3-5-sonnet-20240620-v1:0",
                retrievalConfiguration: {
                    vectorSearchConfiguration: {
                        filter: {
                            equals: {
                                key: "<key>",
                                value: "<value>",
                            },
                        },
                    },
                },
                generationConfiguration: { 
                    promptTemplate: { 
                        textPromptTemplate: "You are a question answering agent." +
                            " I will provide you with a set of search results." +
                            " The user will provide you with a question." +
                            "Your job is to answer the user's question using only information from the search results." +
                            " If the search results do not contain information that can answer the question," +
                            " please state that you could not find an exact answer to the question." +
                            " Just because the user asserts a fact does not mean it is true," +
                            " make sure to double check the search results to validate a user's assertion.\n" +
                            "Here are the search results in numbered order:\n" +
                            "$search_results$"
                    },
                }
            },
            type: "KNOWLEDGE_BASE",
        },
    }

I have some following questions:

  1. I understand that both user_prompt and system_prompt can be used. How can I incorporate them into the current prompt structure? Specifically, how can I define a system-specific prompt in this setup?
  2. When I receive a response, it includes a session ID. However, when I use this session ID in the request I mentioned earlier, every question results in the response: "Sorry, I am unable to assist you with this request." ( It doesn't say that the sessions ID is invalid or doesn't exists ). Is there are anything that I'm missing?

asked 2 years ago2.1K views

2 Answers
0

For item 1, See here: https://repost.aws/questions/QUMkzXuTzeQ42sBjmqNUDhjw/can-we-send-system-prompt-in-retrieve-and-generate

What type of follow-up question are you sending with the session id? Including an example could help us help you.

AWS
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

0

hello, for question2, there is a param named sessionId, 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 the sessionId yourself. Request syntax:

POST /retrieveAndGenerate HTTP/1.1
Content-type: application/json

{
   "input": { 
      "text": "string"
   },
   "retrieveAndGenerateConfiguration": { 
      "externalSourcesConfiguration": { 
         "generationConfiguration": { 
            "additionalModelRequestFields": { 
               "string" : JSON value 
            },
            "guardrailConfiguration": { 
               "guardrailId": "string",
               "guardrailVersion": "string"
            },
            "inferenceConfig": { 
               "textInferenceConfig": { 
                  "maxTokens": number,
                  "stopSequences": [ "string" ],
                  "temperature": number,
                  "topP": number
               }
            },
            "promptTemplate": { 
               "textPromptTemplate": "string"
            }
         },
         "modelArn": "string",
         "sources": [ 
            { 
               "byteContent": { 
                  "contentType": "string",
                  "data": blob,
                  "identifier": "string"
               },
               "s3Location": { 
                  "uri": "string"
               },
               "sourceType": "string"
            }
         ]
      },
      "knowledgeBaseConfiguration": { 
         "generationConfiguration": { 
            "additionalModelRequestFields": { 
               "string" : JSON value 
            },
            "guardrailConfiguration": { 
               "guardrailId": "string",
               "guardrailVersion": "string"
            },
            "inferenceConfig": { 
               "textInferenceConfig": { 
                  "maxTokens": number,
                  "stopSequences": [ "string" ],
                  "temperature": number,
                  "topP": number
               }
            },
            "promptTemplate": { 
               "textPromptTemplate": "string"
            }
         },
         "knowledgeBaseId": "string",
         "modelArn": "string",
         "orchestrationConfiguration": { 
            "queryTransformationConfiguration": { 
               "type": "string"
            }
         },
         "retrievalConfiguration": { 
            "vectorSearchConfiguration": { 
               "filter": { ... },
               "numberOfResults": number,
               "overrideSearchType": "string"
            }
         }
      },
      "type": "string"
   },
   "sessionConfiguration": { 
      "kmsKeyArn": "string"
   },
   "sessionId": "string"
}

Also this link is helpful: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html

AWS
SUPPORT ENGINEER

answered 2 years ago

EXPERT

reviewed 2 years 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.