Prompt Chain

Build Adaptive RAG for Smarter Information Retrieval

Adaptive RAG strategy that unites query analysis with self-corrective RAG.

Works with langchain

91
Spark score
out of 100
Updated 3 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Implement an adaptive Retrieval Augmented Generation (RAG) system that intelligently routes queries between web search and a self-corrective RAG index for more accurate and relevant information retrieval.

Outcomes

What it gets done

01

Analyze incoming queries to determine the best retrieval strategy.

02

Execute web searches for time-sensitive or external information.

03

Perform self-corrective RAG on an indexed knowledge base.

04

Synthesize retrieved information to provide comprehensive answers.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/lg-langgraphadaptiverag | bash

Steps

Steps in the chain

01
Setup

Install required packages and set API keys. Set up LangSmith for LangGraph development by signing up to quickly spot issues and improve performance of LangGraph projects.

02
Create Index

Create an index for the RAG system.

03
LLMs

Configure the language models to be used in the Adaptive RAG system.

04
Web Search Tool

Set up the web search tool for questions related to recent events.

05
Define Graph State

Define the state structure for the LangGraph implementation.

06
Define Graph Flow

Define the flow of the graph, routing between web search for recent events and self-corrective RAG for indexed questions.

07
Compile Graph

Compile the graph for execution.

08
Use Graph

Execute and use the compiled graph with test queries and traces.

Overview

Adaptive RAG

What it does

Removed the unsupported claim that the system mimics strategies from academic research. The description now accurately reflects the routing capabilities mentioned in the source.

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

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
  • Single-shot RAG
  • Iterative RAG

Let's build on this using LangGraph.

In our implementation, we will route between:

  • Web search: for questions related to recent events
  • Self-corrective RAG: for questions related to our index

Setup

First, let's install our required packages and set our API keys

Set up LangSmith for LangGraph development

Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph - read more about how to get started here.

Create Index

LLMs

Web Search Tool

Construct the Graph

Capture the flow in as a graph.

Define Graph State

Define Graph Flow

Compile Graph

Use Graph

Trace:

https://smith.langchain.com/public/7e3aa7e5-c51f-45c2-bc66-b34f17ff2263/r

Trace:

https://smith.langchain.com/public/fdf0a180-6d15-4d09-bb92-f84f2105ca51/r

Step 1: Setup

Install required packages and set API keys. Set up LangSmith for LangGraph development by signing up to quickly spot issues and improve performance of LangGraph projects.

Step 2: Create Index

Create an index for the RAG system.

Step 3: LLMs

Configure the language models to be used in the Adaptive RAG system.

Step 4: Web Search Tool

Set up the web search tool for questions related to recent events.

Step 5: Define Graph State

Define the state structure for the LangGraph implementation.

Step 6: Define Graph Flow

Define the flow of the graph, routing between web search for recent events and self-corrective RAG for indexed questions.

Step 7: Compile Graph

Compile the graph for execution.

Step 8: Use Graph

Execute and use the compiled graph with test queries and traces.

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.