Build Adaptive RAG with Cohere Command R
Adaptive RAG with Cohere Command R, routing across web search, iterative RAG, or LLM answers for efficient information retrieval.
Why it matters
Implement an adaptive Retrieval Augmented Generation (RAG) system using Cohere's Command R model. This system intelligently routes queries to optimize retrieval strategies, including web search and iterative RAG, for more accurate and efficient information retrieval.
Outcomes
What it gets done
Analyze queries to determine optimal retrieval strategy (no retrieval, web search, or iterative RAG).
Integrate Cohere Command R for advanced query understanding and tool utilization.
Orchestrate multi-phase RAG processes for complex information needs.
Leverage web search capabilities for dynamic information gathering.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/lg-langgraphadaptiveragcohere | bash Capabilities
What this chain does
Searches the web and retrieves relevant sources.
Chunks, embeds, and indexes documents for semantic retrieval.
Condenses long documents or threads into key takeaways.
Labels or categorizes text, files, or data points.
Overview
Adaptive RAG Cohere Command R
What it does
This asset implements an Adaptive RAG strategy using Cohere Command R. It performs query analysis to route information retrieval tasks across three distinct paths: direct LLM answers (No Retrieval), web searches, or iterative RAG processes. This approach aims to optimize accuracy and efficiency in answering user queries.
How it connects
Utilize this asset when you need a sophisticated RAG system that can dynamically adapt its retrieval strategy based on the nature of the query. It is particularly useful for complex questions requiring external information (web search) or multi-step reasoning (iterative RAG), while also efficiently handling simpler queries with direct LLM responses.
Source README
This directory is retained purely for archival purposes and is no longer updated. Please see the newly consolidated LangChain documentation for the most current information and resources.
Adaptive RAG Cohere Command R
Adaptive RAG is a strategy for RAG that unites (1) query analysis with (2) active / self-corrective RAG.
In the paper, they report query analysis to route across:
- No Retrieval (LLM answers)
- Single-shot RAG
- Iterative RAG
Let's build on this to perform query analysis to route across some more interesting cases:
- No Retrieval (LLM answers)
- Web-search
- Iterative RAG
We'll use Command R, a recent release from Cohere that:
- Has strong accuracy on RAG and Tool Use
- Has 128k context
- Has low latency
Environment
Index
LLMs
We use a router to pick between tools.
Cohere model decides which tool(s) to call, as well as the how to query them.
Generate
Web Search Tool
Graph
Capture the flow in as a graph.
Graph state
Graph Flow
Build Graph
Trace:
https://smith.langchain.com/public/623da7bb-84a7-4e53-a63e-7ccd77fb9be5/r
Trace:
https://smith.langchain.com/public/57f3973b-6879-4fbe-ae31-9ae524c3a697/r
Trace:
https://smith.langchain.com/public/1f628ee4-8d2d-451e-aeb1-5d5e0ede2b4f/r
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.