Agentic retrieval with LangChain and Amazon Bedrock Knowledge Bases
This article introduces agentic retrieval on Amazon Bedrock Managed Knowledge Bases, where the AgenticRetrieveStream API breaks a multi‑part query into sub‑queries, iteratively searches, and streams planning trace events. The langchain‑aws package exposes both the standard Retrieve API (single‑shot hybrid search) and the agentic AgenticRetrieveStream API for seamless integration into LangChain pipelines. Engineers can choose the cheaper standard retrieval when a single search suffices, or the more thorough agentic path for complex, multi‑intent questions.
⚡ Key Takeaways
- The Retrieve API runs one hybrid search and returns scored chunks.
- The AgenticRetrieveStream API runs a planning loop, streaming trace events for each sub‑query.
- The langchain‑aws package provides a standard LangChain retriever for the Retrieve API and a function retrieval interface for AgenticRetrieveStream.
- The walkthrough assumes Python 3.12+, an AWS account with Bedrock access in us-east-1, and an S3 bucket containing the source documents.
- Agentic retrieval incurs higher cost due to multiple search iterations, making the standard Retrieve API preferable for simple queries.
Selecting the appropriate retrieval mode lets engineers balance cost and answer completeness, enabling production RAG systems that can handle complex user intents without over‑provisioning resources.
✅ Practical Steps
- Install the langchain‑aws package and configure it with your AWS credentials and the Bedrock Knowledge Base ID.
- Use the Retrieve API for single‑shot searches by creating a standard LangChain retriever instance.
- For complex queries, invoke the AgenticRetrieveStream API via the langchain‑aws function retrieval to receive streamed planning events and assembled results.
Want the full story? Read the original article.
Read on AWS ML Blog ↗