Spaces:
Sleeping
Sleeping
File size: 4,388 Bytes
b497248 1a3974f 8f6f40b 1a3974f 8f6f40b 1a3974f 8f6f40b 1a3974f 8f6f40b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | ---
title: AI Research Assistant
emoji: π€
colorFrom: blue
colorTo: red
sdk: streamlit
sdk_version: "1.28.1"
app_file: rag_streamlit_app.py
pinned: false
---
# AI Research Assistant
## π Overview
The **AI Research Assistant** is an agentic RAG (Retrieval-Augmented Generation) pipeline designed to support advanced research tasks.
It combines **retrieval, reasoning, and generation** with modular components for ingestion, query refinement, and output generation.
The system uses **LangChain**, **LangGraph**, and **FAISS**, enhanced with **BM25 hybrid retrieval** and **cross-encoder reranking** for high-precision results.
On top of the pipeline, a **Streamlit web app** (`rag_streamlit_app.py`) provides an intuitive interface for researchers to interact with the assistant, ask questions, and visualize responses.
---
## π Key Features
- **Hybrid Retrieval**: Combines dense embeddings with BM25 for balanced semantic + keyword search.
- **Reranking**: Cross-encoder model refines retrieved passages for better relevance.
- **Agentic Reasoning**: Powered by LangGraph with conditional edges and iterative loops.
- **Query Refinement**: Uses Gemini (via `langchain_google_genai`) to re-formulate queries for better coverage.
- **Self-Critique & Improvement**: The pipeline can score and revise its own outputs.
- **Modular Design**: Clean separation of ingestion, retrieval, refinement, generation, and agent flow.
- **Streamlit App**: Modern UI for asking questions, viewing retrieved sources, and getting citation-backed answers.
---
## π Project Structure
```ai_research_assistant/
βββ agentic_rag/
β βββ agent_flow.py # Defines LangGraph state machine and agent workflow
β βββ ddg_check.py # DuckDuckGo search helper for external knowledge retrieval
β βββ generation.py # Handles LLM response generation using Gemini
β βββ ingestion.py # Ingests documents and builds FAISS vector store
β βββ init.py # Marks directory as a Python package
β βββ llm_config.py # Centralized config for Gemini and other LLMs
β βββ refinement.py # Query reformulation and refinement logic
β βββ retrieval.py # Hybrid (BM25 + dense) retrieval with reranking
β βββ scoring.py # Implements self-critique and scoring of answers
β βββ state.py # LangGraph state definitions and transitions
β βββ tools_agent.py # Utility tools exposed to the agent (search, calculators, etc.)
β
βββ main.py # CLI entry point for running pipeline
βββ rag_streamlit_app.py # Streamlit web app for interactive research assistant
βββ .gitignore # Git ignore rules
βββ README.md # Project documentation
```
---
## βοΈ Tech Stack
- **Python 3.10+**
- **LangChain** + **LangGraph**
- **Vector Stores**: FAISS (with BM25 hybrid)
- **LLMs**: Google Gemini via `langchain_google_genai`
- **Rerankers**: Cross-encoders for document relevance
- **Frontend**: Streamlit
---
## π οΈ Setup
1. Clone the repo:
```
git clone https://github.com/sourabhd321/AI-Research-Assistant.git
cd ai-research-assistant
```
Create and activate virtual environment:
```
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
```
Install dependencies:
```
pip install -r requirements.txt
```
Set up environment variables in .env:
```
GOOGLE_API_KEY=your_gemini_key
```
βΆοΈ Usage
Run the pipeline (CLI mode)
```
python main.py
```
Run the Streamlit app (UI mode)
```
streamlit run rag_streamlit_app.py
```
ποΈ Architecture
```mermaid
flowchart TD
A[Ingestion] -->|Load docs, build FAISS| B[Retrieval]
B -->|Hybrid: BM25 + Dense| C[Reranking]
C --> D[Refinement]
D --> E["Agent Flow (LangGraph)"]
E --> F["Generation (LLM - Gemini)"]
F --> G["Scoring & Self-Critique"]
G --> H["Final Answer"]
%% UI paths
H -->|Display| I["Streamlit App"]
E -->|CLI mode| J["main.py"]
```
## Authors
- [@sourabhd321](https://github.com/sourabhd321)
## Badges



|