- Newest
- Most votes
- Most comments
To emulate the OpenAI responses API style of RAG in Amazon Bedrock where the model determines when to use the knowledge base, you can use the Converse API with tool definitions. This approach allows the model to decide when to access external knowledge.
Here's how to implement this in Bedrock:
-
Define a tool for knowledge base access: Create a JSON schema that defines a tool for querying your knowledge base. This tool definition would include the name, description, and input parameters needed to search your knowledge base.
-
Use the Converse API: When sending a message to the model via the Converse API, include your tool definition. The model will evaluate the user's query and determine if the knowledge base tool should be used.
-
Handle tool use responses: When the model decides it needs to use the knowledge base, it will return a response with
stopReasonset totool_useand include details about the tool request in thetoolUsefield. -
Make the knowledge base query: Your application should then query the knowledge base using the Retrieve API from Amazon Bedrock Knowledge Bases.
-
Return results to the model: After getting results from the knowledge base, construct a new message that includes these results and send it back to the model in another Converse request.
-
Get the final response: The model will generate a response based on the knowledge base results.
This approach gives the model agency to decide when to use the knowledge base, similar to how OpenAI's file_search tool works. The RetrieveAndGenerate API is more automated but doesn't provide the same level of model agency in determining when to use RAG.
For more advanced RAG patterns, you could also consider using LlamaIndex with Amazon Bedrock, which supports agentic RAG workflows where the LLM can reason about when and how to use external knowledge sources.
Sources
Call a tool with the Converse API - Amazon Bedrock
Knowledge bases for Amazon Bedrock - AWS Prescriptive Guidance
Build powerful RAG pipelines with LlamaIndex and Amazon Bedrock | AWS Machine Learning Blog
Use Amazon Bedrock tooling with Amazon SageMaker JumpStart models | AWS Machine Learning Blog
answered a year ago
Relevant content
asked 3 years ago

This seems like it should technically work. I also noticed that Agents can be created and associated with knowledge base. This is probably more equivalent to the Responses API pattern I mention, coz in this case the tool search doesn't have to be explicitly implemented for one. I am curious now how the Converse API and Agents approach compare in terms of LLM behavior and effectiveness