Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bedrock_agent_runtime APIs are not returning source metadata #4352

Open
1 task
vbloise3 opened this issue Nov 18, 2024 · 1 comment
Open
1 task

bedrock_agent_runtime APIs are not returning source metadata #4352

vbloise3 opened this issue Nov 18, 2024 · 1 comment
Assignees
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.

Comments

@vbloise3
Copy link

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

  • Select this option if this issue appears to be a regression.

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:
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: $search_results$\n\nQuestion: $input$'
}
},
'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

except ClientError as e:
    logger.error(f"Error in answer_query_tool: {e}")
    return f"An error occurred: {str(e)}"

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

@vbloise3 vbloise3 added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 18, 2024
@adev-code adev-code self-assigned this Nov 20, 2024
@adev-code adev-code added investigating This issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue bedrock-agent-runtime and removed needs-triage This issue or PR still needs to be triaged. labels Nov 20, 2024
@adev-code
Copy link

Hello @vbloise3, thank you for reaching out. For further look, could you please provide the full debug logs by adding the line boto3.set_stream_logger('') and redacting any sensitive information. Also, if you can also include more information for the code you have and bedrock replication. Thank you.

@adev-code adev-code added response-requested Waiting on additional information or feedback. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

2 participants