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

![Python](https://img.shields.io/badge/Python-3.12-blue)
![License](https://img.shields.io/badge/License-MIT-green)
![Model](https://img.shields.io/badge/Model-Flan--T5-blueviolet)