bedrock_agent_runtime APIs are not returning source metadata #4352
Labels
bedrock-agent-runtime
bug
This issue is a confirmed bug.
p3
This is a minor priority issue
response-requested
Waiting on additional information or feedback.
Describe the bug
When I call the invoke_agent, retrieve, or retrieve_and_generate APIs for the bedrock_agent_runtime, the response never contains the metadata keys associated with the source files. I know that the metadata is set up correctly for the source, because I see it show up in the vector DB indexes, and if I test the knowledge base directly in the console and view the trace, it shows the correct source metadata.
However, when I call any of the APIs mentioned above referencing the same knowledge base, the response never contains the source metadata information.
Regression Issue
Expected Behavior
The retrievedReferences key in the response from an invoke_agent call to the bedrock_agent_runtime should contain a metadata key whose values match the JSON key values set in the corresponding source .metadata.json file.
Current Behavior
There is no metadata key returned by any of the invoke_agent, retrieve, or retrieve_and_generate APIs.
Reproduction Steps
try:$search_results$ \n\nQuestion: $input$ '
response = bedrock_agent_runtime.retrieve_and_generate(
input={'text': query},
retrieveAndGenerateConfiguration={
'type': 'KNOWLEDGE_BASE',
'knowledgeBaseConfiguration': {
'generationConfiguration': {
'promptTemplate': {
'textPromptTemplate': 'Use this context to answer the question at the end. Give a very detailed, long answer. Use a friendly, conversational tone.\n\nContext:
}
},
'knowledgeBaseId': KB_ID,
'modelArn': f"arn:aws:bedrock:us-east-1:904262394592:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0",
'retrievalConfiguration': {
'vectorSearchConfiguration': {
'numberOfResults': 5
}
}
}
}
)
print(f"\n\n the returned answer: {response} \n\n")
generated_text = response['output']['text']
# Extract the retrieved sources
retrieved_sources = []
if 'retrievalResults' in response:
for result in response['retrievalResults']:
if 'location' in result:
location = result['location']
if 'uri' in location:
retrieved_sources.append({
'uri': location['uri'],
'score': result.get('score', None),
'content': result.get('content', {}).get('text', '')
})
print("f\n\n the metadata: {retrieved_sources} \n\n")
return generated_text, retrieved_sources
Possible Solution
Return the metadata in the response to the bedrock_agent_runtime.retrieve_and_generate API call.
Additional Information/Context
No response
SDK version used
boto3 1.35.63
Environment details (OS name and version, etc.)
Mac OS 14.7.1, Python 3.11.4
The text was updated successfully, but these errors were encountered: