AnyRAG-WebSearch / README.md
Rashid Ali
configure setup
0ac4aed
metadata
title: AnyRAG
emoji: πŸš€
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
  - streamlit
pinned: false
short_description: Streamlit template space

🧠 AnyRAG β€” Intelligent Document & Web-Aware Chatbot

AnyRAG (short for Any Document Retrieval-Augmented Generation) is an advanced RAG-powered conversational system built with LangGraph, Streamlit, and OpenAI / HuggingFace models. It allows users to interact with uploaded documents and optionally fetch live web data for up-to-date, context-rich responses.

πŸš€ Features

βœ… Dual Model Support β€” Choose between:

OpenAI GPT models (via API)

Open-Source HuggingFace models (like Llama, Mistral, etc.)

βœ… Document-Aware Chat β€” Upload PDFs or text documents, and chat directly with their contents.

βœ… Dynamic Web Search Integration β€” Toggle on/off real-time web search (DuckDuckGo) for the latest information.

βœ… System Prompt Control β€” Customize how the AI behaves (e.g., β€œAct as a Tax Advisor” or β€œExplain as a Data Scientist”).

βœ… Conversation Memory β€” Stores multiple chat threads with custom titles, allowing you to switch between them seamlessly.

βœ… Vector Store Management β€” Automatically indexes your documents for efficient semantic retrieval using FAISS/Chroma.

βœ… User-Friendly Streamlit Frontend β€” Clean, responsive UI with sidebars for all controls.

βœ… Graph-based Orchestration β€” Uses LangGraph to manage chat states, document search, and tool invocation.

🧩 Architecture Overview

         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚      Streamlit UI      β”‚
         β”‚ (chatbot_frontend.py)  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                    β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  LangGraph Backend     β”‚
         β”‚ (chatbot_backend.py)   β”‚
         β”‚  β€’ Chat State Engine   β”‚
         β”‚  β€’ Document Retriever  β”‚
         β”‚  β€’ Tool Invoker        β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό                   β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Vector Store β”‚    β”‚ Web Search   β”‚
   β”‚ (FAISS/Chromaβ”‚    β”‚ (DuckDuckGo) β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—οΈ Major Components

1. chatbot_frontend.py

The Streamlit-based interface that enables:

Chat interaction

Model selection (OpenAI or HuggingFace)

Document upload and retrieval

Web search toggle

System prompt customization

Viewing & switching saved chat threads

2. chatbot_backend.py

The main orchestration logic powered by LangGraph:

Maintains conversation state

Handles message routing between human, LLM, and tools

Integrates document retriever, DuckDuckGo search tool, and vector store

Uses Graph state transitions for structured, multi-step reasoning

3. search_tool.py

Implements live web search using DuckDuckGo, returning relevant snippets when web search is enabled.

4. document_tool.py

Handles:

PDF or text ingestion

Chunking and embedding creation

Building or loading a FAISS/Chroma vector index

Performing semantic similarity search

5. models.py

Provides model initialization functions for:

OpenAI GPT models via API key

HuggingFace Transformers (running locally or via pipeline)

6. vector_stores/

Stores prebuilt FAISS/Chroma indexes for quick retrieval of previously uploaded or sample documents.

βš™οΈ Setup Instructions 1️⃣ Clone the Repository

git clone https://github.com/yourusername/AnyRAG.git
cd AnyRAG

2️⃣ Create and Activate Environment

Using uv (recommended):

uv venv
source .venv/bin/activate

Or using venv/conda:

python -m venv .venv
source .venv/bin/activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Run the Streamlit App streamlit run chatbot_frontend.py

🧠 Example Use Cases

Domain Example System Prompt Benefit 🧾 Tax Advisor β€œYou are an expert GST consultant in India.” Answer document + live tax queries.

βš–οΈ Legal Assistant β€œYou are a contract lawyer explaining clauses.” Summarize long PDFs with context.

πŸ“š Research Helper β€œYou are a literature review assistant.” Summarize papers, add web references.

πŸ’¬ General Chat (Leave blank) Use model’s default persona.

🧰 Folder Structure

AnyRAG/
β”œβ”€β”€ chatbot_backend.py        # LangGraph backend orchestrator
β”œβ”€β”€ chatbot_frontend.py       # Streamlit-based UI
β”œβ”€β”€ search_tool.py            # DuckDuckGo search integration
β”œβ”€β”€ document_tool.py          # Document ingestion and vector store
β”œβ”€β”€ models.py                 # Model loaders (OpenAI / HF)
β”œβ”€β”€ vector_stores/            # Prebuilt FAISS indexes
β”œβ”€β”€ sample_docs/              # Example documents for testing
β”œβ”€β”€ requirements.txt
└── README.md

🧩 Benefits of AnyRAG

βœ… Hybrid Knowledge Access β€” Combines local document understanding with live internet results.

βœ… Flexible AI Backbone β€” Works with both OpenAI and HuggingFace models.

βœ… Explainable Retrieval Flow β€” LangGraph structure shows every reasoning step.

βœ… Customizable Persona β€” Behavior control via System Prompt.

βœ… Lightweight Deployment β€” Works locally or via Docker / Hugging Face Spaces.

βœ… Scalable for Enterprises β€” Extend easily for multi-agent or multi-doc setups.

🧠 Future Enhancements

🧩 Add Multi-Document RAG

🧠 Integrate Memory Store for Persistent Context

πŸ“ˆ Add Analytics for Query Insights

πŸͺ„ Add Voice/Whisper Support for Audio Inputs

🌍 Expose REST API endpoint for external use