You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an Agent and a Knowledge Base set up in AWS Bedrock.
I'm trying to provide a citation link to the document in S3 that was used as part of RAG for a particular user query. The first response in the session has retrievedReferences that I can use to create this link. Any subsequent responses generated using RAG either have an empty array for retrievedReferences or don't even have an attribution field.
Expected Behavior
When RAG is used by the agent and it's pulling information from the Knowledge Base. The attribution field should be in the response and the retrievedReferences field should include the appropriate references rather than being an empty array.
Call the invoke_agent API with multiple questions that will hit the Knowledge Base in the same session.
importuuidimportboto3fromtypingimportDict, Listdefcall_invoke_agent_api(prompt: str, chat_session_id: str):
bedrock_agent_runtime_client=boto3.client("bedrock-agent-runtime", region_name="us-east-1")
agent_response=bedrock_agent_runtime_client.invoke_agent(
agentId=***,
agentAliasId=***,
inputText=prompt,
sessionId=chat_session_id,
enableTrace=True,
)
text_completions: List[Dict] = []
foreventinagent_response["completion"]:
chunk=event.get("chunk")
ifchunkisNone:
continueattribution=chunk.get("attribution")
ifattributionisnotNone:
# the agent used RAG to generate a responsecitations=attribution.get("citations")
forcitationincitations:
text=citation["generatedResponsePart"]["textResponsePart"]["text"]
uri=filename=""retrieved_references=citation["retrievedReferences"]
forreferenceinretrieved_references:
uri=reference["location"]["s3Location"]["uri"]
filename=uri.split("/")[-1]
text_completion=dict(text=text)
ifuri:
text_completion["uri"] =uritext_completion["filename"] =filenametext_completions.append(text_completion)
else:
# the agent didn't use the knowledge base to generate a response, just get it from bytestext_completions.append(dict(text=chunk["bytes"].decode()))
returndict(text_completions=text_completions)
chat_session_id=uuid.uuid4().hexcall_invoke_agent_api(prompt_1, chat_session_id)
call_invoke_agent_api(prompt_2, chat_session_id)
Possible Solution
No response
Additional Information/Context
It seems to always provide the retrievedReferences correctly for the first prompt that causes the Agent to use the Knowledge Base. After that it will sometimes return valid references in retrievedReferences, sometimes empty arrays, and sometimes not even an attribution field in the response, even though the trace for invoke_agent call shows that the Agent is performing RAG and using the Knowledge Base.
In my Agent's Advanced prompts configuration, I have the Pre-processing template and Post-processing template turned off
SDK version used
boto3==1.34.61
Environment details (OS name and version, etc.)
AmazonLinux2
The text was updated successfully, but these errors were encountered:
Hi @tim-finnigan is there any update regarding this issue?
I noticed that, in the agent playground from the AWS console, the metadata information from the knowledge base documents are now being displayed when accessing the trace event details, however, even using the latest boto3 version 1.35.2 the metadata object it is not present in the invoke_agent response.
@tim-finnigan Also looking for an update on this issue. It's a big problem for our customers as we can only provide a citation for them the first time and no subsequent times.
Original issue: boto/boto3#4197. (ref: P140606677)
The text was updated successfully, but these errors were encountered: