Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adaptive RAG-CAG Question Answering

This project is based on the paper "Don't Do RAG: When Cache-Augmented Generation is All You Need for Knowledge Tasks" and extends it into a practical comparison demo.

Project Idea

The system compares two ways of answering questions from uploaded documents:

  • RAG: retrieve the most relevant chunks, then answer from those chunks.
  • CAG: preload the full limited knowledge base, then answer without real-time retrieval.
  • Adaptive: automatically choose RAG or CAG based on knowledge-base size and query complexity.

Why This Project Is Useful

RAG is popular, but it adds retrieval latency and can fail when the wrong chunks are selected. CAG is simpler for small, stable document collections because the model can work from the full available context. This project demonstrates when each approach is better.

Features

  • Upload TXT, MD, or PDF files.
  • Run RAG, CAG, Adaptive, or side-by-side Compare mode.
  • View answer latency, confidence score, routing reason, and source snippets.
  • Includes a sample knowledge base for instant demo.

How To Run

No-Install Browser Demo

Open index.html in a browser. This version supports pasted text or uploaded TXT/MD/CSV files.

Streamlit App With PDF Support

pip install -r requirements.txt
streamlit run app.py

Then open the local URL shown by Streamlit.

How To Test

python -m unittest discover tests

Suggested Demo Questions

  • When should CAG be preferred over RAG?
  • What are the main failure cases of RAG?
  • Compare RAG and CAG for small knowledge bases.
  • Which metrics should be used to evaluate this system?

Proposed Evaluation

Use 20-30 questions over the same document collection and record:

  • answer relevance
  • faithfulness to source
  • latency
  • retrieval quality
  • whether the adaptive route selected the better method

Future Improvements

  • Replace lexical retrieval with embeddings and FAISS.
  • Add a real LLM generation layer.
  • Add automatic faithfulness scoring.
  • Add query decomposition for complex questions.
  • Cache long-context prompts for true CAG behavior with supported LLM APIs.

About

Adaptive RAG and CAG demo project with Streamlit app and tests.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages