Skip to content

Repository files navigation

🎓 Self-RAG University Advisory Agent

An advanced, self-correcting RAG (Retrieval-Augmented Generation) agent built with LangGraph to assist students and faculty at XYZ National University. The agent provides accurate information on course catalogs, academic policies, and faculty details while actively preventing hallucinations.


🚀 Features

  • Adaptive Retrieval: Classifies queries to decide whether to search the internal knowledge base (University data) or provide a general response.
  • Structure-Aware Chunking: Custom regex-based parsing of PDF catalogs to ensure course descriptions and faculty entries stay intact.
  • Relevance Grading: Automatically filters out irrelevant documents before generation to minimize noise and token costs.
  • Self-Correction (Hallucination Check): Verifies every generated claim against the retrieved context. If an answer isn't grounded, the agent automatically retries generation or falls back to web search.
  • Web Search Fallback: Integrates with Tavily to provide supplementary information when internal documents are insufficient.
  • Streamlit UI: A clean, modern interface for real-time interaction and execution tracing.

🛠️ Tech Stack

  • Orchestration: LangGraph
  • LLM: Meta Llama 3 (via OpenRouter)
  • Vector Store: FAISS
  • Embeddings: OpenAI text-embedding-3-small
  • UI: Streamlit

📦 Installation & Setup

1. Clone the Repository

git clone git@github.com:abeeranajam31/Self-Rag-.git
cd Self-Rag-

2. Create Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

3. Environment Variables

Create a .env file in the root directory:

OPENROUTER_API_KEY=your_key_here
TAVILY_API_KEY=your_key_here
DATA_DIR=./Data_share
VECTORSTORE_PATH=./vectorstore_index

🎯 Usage

CLI Mode (Interative)

Run the agent directly in your terminal:

python self_rag_agent.py

Rebuild Vector Index

If you update the PDFs in Data_share, rebuild the knowledge base:

python self_rag_agent.py --rebuild-index

Streamlit Dashboard

Launch the web interface:

streamlit run app.py

📊 Evaluation Scenarios

The agent has been verified across 5 critical scenarios:

  1. General Queries: Instant grounded responses without retrieval.
  2. Specific Retrieval: Precise course/policy lookups (e.g., "Prerequisites for EE-201").
  3. Web Fallback: Handling queries outside the local KB (e.g., "International rankings").
  4. Hallucination Protection: Self-correction loop for unsupported claims.
  5. Cross-Document Synthesis: Combining faculty contact info with course catalog details.

Detailed execution traces can be found in evaluation_results.md.


🛡️ Security

This project uses environment variables for all API keys. Hardcoded secrets have been removed to comply with security best practices.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages