- Newest
- Most votes
- Most comments
You can do this as part of SessionState Object, which agents use. Documentation here: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html
The example shown uses both 1/ Session Attributes and 2/ KB filters that can be used throughout the agent session. The retrievalConfiguration can be found at the bottom:
{
"sessionAttributes": {
"<attributeName1>": "<attributeValue1>",
"<attributeName2>": "<attributeValue2>",
...
},
"promptSessionAttributes": {
"<attributeName3>": "<attributeValue3>",
"<attributeName4>": "<attributeValue4>",
...
},
"invocationId": "string",
"returnControlInvocationResults": [
ApiResult or FunctionResult,
...
],
"knowledgeBases": [
{
"knowledgeBaseId": "string",
"retrievalConfiguration": {
"vectorSearchConfiguration": {
"overrideSearchType": "HYBRID | SEMANTIC",
"numberOfResults": int,
"filter": RetrievalFilter object
}
}
},
...
]
}
Hi, Currently Agents do not have the capability to invoke KnowledgeBases and pass metadata fileters. Here is the API reference: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html However, the idea is to use a Action group lamda function to use context from a knowledgebase. So, to filter search results returned from the knowledgebase you can have filtration logic in the lambda function.
Rajarshighosal, thank you for your answer. do you mean that invoke agent does not deal with KB at all or it does not allowed metadata filtering? it looks like it works with KB, but with limitations, am i right? As for the proposed idea, does it mean that i need execute custom lambda that talks to KB with filters and than execute another function call? Tkank you YK
Hi, A Bedrock Agent interprets the user input, invokes action groups and queries knowledge bases, and returns output to the user or as input to continued orchestration. Now, in your scenario, you can add prompts to the knowledgebase to return only the context. Next, you add prompts to the action group to use the context from the knowledgebase. Add custom filter code to the action group lambda to get the desired filtered content.
The other way is, not add the knowledgebase to the agent directly, but invoke the knowledgebase from your action group lambda and add filters.
See what works best.
Hi!
You can find how to add filters in the Agents for Amazon Bedrock Runtime API reference here: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html
This example uses filters:
POST /retrieveAndGenerate HTTP/1.1
Content-type: application/json
{
"input": {
"text": "What is AWS?",
},
"retrieveAndGenerateConfiguration": {
"knowledgeBaseConfiguration": {
"knowledgeBaseId": "KB12345678",
"modelArn": "anthropic.claude-v2:1",
"retrievalConfiguration": {
"vectorSearchConfiguration": {
"numberOfResults": 5,
"filter": {
"orAll": [
{
"andAll": [
{
"equals": {
"key": "genre",
"value": "entertainment"
}
},
{
"greaterThan": {
"key": "year",
"value": 2018
}
}
]
},
{
"andAll": [
{
"in": {
"key": "genre",
"value": ["cooking", "sports"]
}
},
{
"startsWith": {
"key": "author",
"value": "C"
}
}
]
}
]
}
}
}
},
"type": "KNOWLEDGE_BASE"
}
}
@Anna_G, looks like you mentioned RetrieveAndGenerate API? My understanding that Api does not work with agent, but rather Queries a knowledge base and generates responses based on the retrieved results. Agree?
Relevant content
- Accepted Answerasked 3 months ago
- Accepted Answerasked 6 months ago
- asked 4 months ago
- How do I raise the priority of agent to agent or agent to queue transferred calls in Amazon Connect?AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 2 months ago
Great answer! Actually it looks like bedrock agent provides better results with session state than without it