Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Agentic RAG Framework - Enterprise Edition

A production-ready, full-stack framework for building intelligent RAG applications with an interactive web interface.

This framework provides everything you need to build sophisticated AI agents that can:

  • Retrieve Information: Use semantic vector search (RAG) to find relevant documents
  • Make Intelligent Decisions: Automatically determine when to search vs. answer directly
  • Maintain Context: Persist conversation history across sessions
  • Interactive UI: Modern, responsive web interface with smooth typing animations
  • Flexible Deployment: Supports OpenAI, Azure OpenAI, or local models (LM Studio)

✨ Features

Backend (Python + FastAPI)

  • πŸ€– Intelligent Tool Use: LLM calls search_docs only when necessary
  • 🎯 Semantic Filtering: Relevance threshold (β‰₯0.5) removes irrelevant results
  • πŸ“Š Optimized Retrieval: Configurable TOP_K and chunk sizing for accuracy
  • πŸ”„ Session Memory: Persists chat history to disk
  • 🌐 Multi-Provider: OpenAI, Azure OpenAI, or LM Studio (local)
  • ⚑ FastAPI Server: Production-ready REST API

Frontend (React + Vite)

  • 🎨 Modern UI: Dark theme with glassmorphism effects
  • ✨ Smooth Typing Animation: ChatGPT-like letter-by-letter responses
  • πŸ“‹ Copy-to-Clipboard: Easy code snippet copying
  • πŸ’« Interactive Animations: Hover effects, loading states, transitions
  • πŸ“š Source Citations: Clear attribution for all retrieved information
  • 🎯 Real-time Feedback: Shake validation, pulse effects, status indicators

πŸ“‚ Project Structure

Agentic-RAG-Framework/
β”œβ”€β”€ backend/agentic_rag/    # Backend Python package
β”‚   β”œβ”€β”€ api.py              # FastAPI server
β”‚   β”œβ”€β”€ agent.py            # Core agent logic
β”‚   β”œβ”€β”€ tools.py            # Search tools with semantic filtering
β”‚   β”œβ”€β”€ index.py            # Document indexing
β”‚   β”œβ”€β”€ chat.py             # CLI interface
β”‚   └── ...
β”œβ”€β”€ frontend/               # React + Vite web app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # UI components
β”‚   β”‚   β”œβ”€β”€ index.css       # Styles & animations
β”‚   β”‚   └── App.jsx
β”‚   β”œβ”€β”€ tailwind.config.js  # Tailwind CSS config
β”‚   └── package.json
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ docs/               # Your documents (.txt, .md, .pdf)
β”‚   β”œβ”€β”€ index/              # Generated embeddings
β”‚   └── sessions/           # Chat history
β”œβ”€β”€ .env                    # Configuration
└── requirements.txt        # Python dependencies

πŸš€ Getting Started

Prerequisites

  • Python 3.9+
  • Node.js 18+ and npm
  • LM Studio (for local models) OR OpenAI/Azure API keys

1. Backend Setup

Windows (PowerShell)

cd Agentic-RAG-Framework
py -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

Mac/Linux

cd Agentic-RAG-Framework
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

2. Configuration

Create .env file (or copy from .env.example):

# Provider: openai, azure, or use LM Studio
PROVIDER=openai
OPENAI_BASE_URL=http://127.0.0.1:1234/v1  # LM Studio endpoint
OPENAI_API_KEY=lm-studio-local            # Dummy key for LM Studio

# Model names (use deployment names for Azure)
CHAT_MODEL=qwen2.5-7b-instruct-1m
EMBEDDING_MODEL=text-embedding-nomic-embed-text-v1.5

# Retrieval settings (optimized defaults)
TOP_K=8                # Number of chunks to retrieve
CHUNK_TOKENS=600       # Chunk size for faster processing
CHUNK_OVERLAP=120      # Overlap between chunks

For OpenAI:

PROVIDER=openai
OPENAI_API_KEY=sk-your-key-here
CHAT_MODEL=gpt-4o-mini
EMBEDDING_MODEL=text-embedding-3-small

For Azure OpenAI:

PROVIDER=azure
AZURE_OPENAI_API_KEY=your-key
AZURE_OPENAI_BASE_URL=https://your-resource.openai.azure.com/openai/v1/
CHAT_MODEL=gpt-4o-mini  # deployment name
EMBEDDING_MODEL=text-embedding-ada-002  # deployment name

3. Frontend Setup

cd frontend
npm install

πŸ’‘ Usage

Step 1: Add Documents

Place your documents (.txt, .md, .pdf) in data/docs/:

# Sample document included for testing
data/docs/sample_policy.md

Step 2: Build Index

Generate embeddings for your documents:

python -m agentic_rag.index

Step 3: Start the Application

Terminal 1 - Backend:

python -m uvicorn agentic_rag.api:app --reload --port 8000

Terminal 2 - Frontend:

cd frontend
npm run dev

Open your browser:

http://localhost:5173

Alternative: CLI Chat

Start the interactive CLI (without frontend):

python -m agentic_rag.chat

Resume a session:

python -m agentic_rag.chat --session <SESSION_ID>

🎨 UI Features

Typing Animation

  • Smooth letter-by-letter reveal (10ms per character)
  • Blinking cursor during typing
  • ChatGPT/Gemini-like experience

Interactive Elements

  • Hover effects on all components
  • Shake animation on validation errors
  • Pulse glow on active send button
  • Copy-to-clipboard for code blocks
  • Smooth transitions throughout

Source Citations

Every response shows its sources:

SOURCES
πŸ“„ sample_policy.md
πŸ“„ document.pdf

βš™οΈ Configuration Deep Dive

Retrieval Parameters

TOP_K (default: 8)

  • Number of chunks to retrieve from vector store
  • Higher = better coverage, but more noise
  • Recommended: 5-10

CHUNK_TOKENS (default: 600)

  • Size of each document chunk
  • Smaller = faster processing
  • Recommended: 400-800

CHUNK_OVERLAP (default: 120)

  • Overlap between consecutive chunks
  • Prevents information loss at boundaries
  • Recommended: 15-20% of CHUNK_TOKENS

Semantic Filtering

The framework automatically filters results with relevance score < 0.5:

# In tools.py
RELEVANCE_THRESHOLD = 0.5  # Only keep relevant results

This prevents irrelevant answers and improves accuracy.


πŸ› οΈ Customization

Add New Tools

Edit backend/agentic_rag/tools.py:

TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "your_custom_tool",
            "description": "What this tool does",
            "parameters": {...}
        }
    }
]

Modify UI Styling

  • Colors: Edit CSS variables in frontend/src/index.css
  • Animations: Adjust keyframes in frontend/src/index.css
  • Components: Modify files in frontend/src/components/

Change Typing Speed

In frontend/src/components/ChatInterface.jsx:

const typingSpeed = 3; // milliseconds per character

πŸš€ Deployment

Backend (Azure/Railway/Render)

# Build and deploy the FastAPI app
pip install -r requirements.txt
uvicorn agentic_rag.api:app --host 0.0.0.0 --port 8000

Frontend (Vercel/Netlify/Azure Static Web Apps)

cd frontend
npm run build  # Creates dist/ folder
# Deploy dist/ folder to your hosting service

Update frontend proxy for production: Edit frontend/vite.config.js:

server: {
  proxy: {
    '/ask': {
      target: process.env.VITE_API_URL || 'https://your-backend.com',
      changeOrigin: true,
    }
  }
}

πŸ§ͺ Testing

Test Queries

1. "What is the POSH policy?"
   β†’ Should return Prevention of Sexual Harassment policy

2. "Tell me about leave policy"
   β†’ Should return vacation/leave information

3. "Remote work guidelines"
   β†’ Should return remote work policies

4. "What is Python?" (general knowledge)
   β†’ Should answer directly without searching docs

Verify Features

  • βœ… Typing animation is smooth
  • βœ… Sources are displayed
  • βœ… Hover effects work
  • βœ… Copy-to-clipboard on code blocks
  • βœ… Empty submit triggers shake animation

πŸ“ API Reference

POST /ask

Query the agent:

Request:

{
  "query": "What is the vacation policy?",
  "session_id": "sess_abc123"  // Optional
}

Response:

{
  "answer": "Unused leave can be carried forward...",
  "source": ["sample_policy.md", "hr_handbook.pdf"]
}

🎯 Key Technologies

  • Backend: Python, FastAPI, OpenAI API, FAISS
  • Frontend: React, Vite, Tailwind CSS
  • Vector Store: FAISS (cosine similarity)
  • Embeddings: OpenAI text-embedding-3-small or custom models

πŸ“š Learn More


🀝 Contributing

Contributions welcome! Please feel free to submit a Pull Request.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages