File size: 7,855 Bytes
ac64eeb
 
 
 
 
 
 
 
 
ae2bb22
 
 
 
d510a4f
ae2bb22
 
 
d510a4f
ae2bb22
d510a4f
1003d5c
ae2bb22
d510a4f
c6b35de
 
 
1003d5c
c6b35de
 
 
 
 
 
ae2bb22
 
 
 
 
 
efb086b
ae2bb22
efb086b
ae2bb22
d510a4f
ae2bb22
d510a4f
efb086b
d510a4f
ae2bb22
efb086b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae2bb22
efb086b
 
 
 
 
 
 
 
 
 
ae2bb22
d510a4f
efb086b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d510a4f
efb086b
 
 
 
ae2bb22
efb086b
 
 
 
 
 
 
ae2bb22
d510a4f
efb086b
 
 
 
d510a4f
efb086b
 
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
 
cb96d83
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
 
1a2c92d
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
 
 
 
 
d510a4f
ae2bb22
 
a3bacd6
ae2bb22
d510a4f
ae2bb22
 
 
d510a4f
efb086b
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
 
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
ae2bb22
 
 
1a2c92d
8eb0662
ae2bb22
d510a4f
ae2bb22
d510a4f
efb086b
d510a4f
efb086b
 
 
 
 
d510a4f
ae2bb22
d510a4f
ae2bb22
d510a4f
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
---
title: Necthrall
emoji: πŸ”¬
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
---

<div align="center">
  <img src="logo/necthrall.png" alt="Necthrall Logo" width="120">
  <h1>Necthrall</h1>
  <h3><i>Science, Distilled.</i> An open-source, AI research assistant.</h3>

  ![License](https://img.shields.io/badge/license-GPL-green)
  ![Python](https://img.shields.io/badge/python-3.11+-blue)
  ![Stack](https://img.shields.io/badge/Stack-NiceGUI%20%7C%20FastAPI%20%7C%20LlamaIndex-purple)

  <br/>

  <strong><a href="https://necthrall.tech/">πŸ”΄ Live Demo</a></strong>
</div>

## πŸŽ₯ Video Demo

<div align="center">
  <a href="https://youtube.com/shorts/uSinui_HFrQ">
    <img src="https://img.youtube.com/vi/z6Bg-02ml8w/0.jpg" alt="Necthrall Demo Video" width="300"/>
  </a>
  <br>
  <i>Watch Necthrall retrieve, analyze, and cite full-text scientific papers in real time.</i>
</div>

---

## ⚑ Key Features

- **πŸ“„ Full-Text Analysis:** We don't just read abstracts. Necthrall downloads and chunks the actual PDFs to find evidence buried deep in Methods and Results.
- **πŸ›‘οΈ Privacy First:** Completely stateless. No database, no user accounts, no history.
- **πŸ” Deep Search:** Queries **Semantic Scholar** to find hundreds of candidates per query, filtered down to the top N most relevant open-access papers.
- **βœ… Verifiable:** Every sentence is backed by an inline citation `[1]` that links directly to the source passage.
- **🧠 Resilient:** Built on **LiteLLM**, Necthrall automatically switches to the secondary provider if the primary one is unavailable or fails.
---

## πŸ—οΈ Architecture

Necthrall runs a **10-stage pipeline** for every query. It is optimized for speed (async/parallel) and transparency.

```mermaid
flowchart TD
    %% Global Styles
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px,color:#000;
    classDef decision fill:#fff9c4,stroke:#fbc02d,stroke-width:2px,color:#000;
    classDef terminal fill:#263238,stroke:#333,color:#fff;
    classDef success fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;
    classDef fail fill:#ffebee,stroke:#c62828,stroke-width:2px;
    classDef note fill:#e1f5fe,stroke:#0277bd,stroke-dasharray: 5 5;

    Start([<b>User Query</b>]) --> OptStart

    %% ==========================================================
    %% PHASE 0: PRE-PROCESSING
    %% ==========================================================
    subgraph Phase0 [Phase 0: Planning & Optimization]
        direction TB
        OptStart[<b>Generate Dual Queries</b>]
        
        OptFail{LLM Failure?}
        
        FallbackOpt[Fallback:Use Original Query]
        SuccessOpt[Success:Use 'Final Rephrase' + Variants]
        
        OptStart --> OptFail
        OptFail -- Yes --> FallbackOpt
        OptFail -- No --> SuccessOpt
    end

    %% ==========================================================
    %% PHASE 1: DISCOVERY
    %% ==========================================================
    subgraph Phase1 [Phase 1: Discovery Service]
        direction TB
        DiscCall[<b>Search Semantic Scholar API<br/>]
        
        QualityGate{Quality Gate<br/>Passed?}
        
        RefineLoop[<b>Refinement Loop</b><br/>Retry with 'Broad' Query]:::note
        
        Ranking[<b>Composite Scoring</b><br/>Relevance + Authority + Recency]
        
        FallbackOpt --> DiscCall
        SuccessOpt --> DiscCall
        
        DiscCall --> QualityGate
        QualityGate -- No (Attempt 1) --> RefineLoop --> DiscCall
        QualityGate -- Yes --> Ranking
        QualityGate -- No (Attempt 2) --> Ranking
    end

    CheckFinalists{Any Papers<br/>Found?}
    ExitNoPaper([STOP: Return 'No Papers Found']):::terminal
    
    Ranking --> CheckFinalists
    CheckFinalists -- No --> ExitNoPaper

    %% ==========================================================
    %% PHASE 2: INGESTION
    %% ==========================================================
    subgraph Phase2 [Phase 2: Ingestion Service]
        direction TB
        DeepMode{Deep Mode<br/>Enabled?}
        
        subgraph DeepIngest [Deep Analysis]
            PDFDownload[<b>PDF Acquisition</b><br/>Download Full Text]
            Processing[<b>Processing</b><br/>Chunking & Embedding]
        end
        
        subgraph FastIngest [Fast Scan]
            Abstracts[<b>Abstract Ingestion</b><br/>Use Abstracts Only]
        end
        
        DeepMode -- Yes --> PDFDownload --> Processing
        DeepMode -- No --> Abstracts
    end

    CheckChunks{Content<br/>Available?}
    ExitNoChunks([STOP: Return 'No Content']):::terminal

    CheckFinalists -- Yes --> DeepMode
    Processing --> CheckChunks
    Abstracts --> CheckChunks
    CheckChunks -- No --> ExitNoChunks

    %% ==========================================================
    %% PHASE 3: RAG
    %% ==========================================================
    subgraph Phase3 [Phase 3: RAG Service]
        direction TB
        SelectQuery[Select Query:<br/>Use 'Final Rephrase' if available]
        
        Hybrid[<b>Hybrid Retrieval</b><br/>Vector + BM25 Search]
        Rerank[<b>Reranking</b><br/>Cross-Encoder Re-scoring]
        
        Synth[<b>Synthesis</b><br/>Generate Answer with Citations]
        Verify[<b>Verification</b><br/>Check Citation Accuracy]:::success
    end

    CheckChunks -- Yes --> SelectQuery
    SelectQuery --> Hybrid --> Rerank --> Synth --> Verify
    
    Verify --> End([Final Response]):::terminal

    %% Class Assignments
    class OptFail,QualityGate,CheckFinalists,DeepMode,CheckChunks decision
````

### The Stack

  * **UI/Server:** NiceGUI + FastAPI (Single Python app)
  * **RAG:** LlamaIndex + FAISS (Ephemeral in-memory indices)
  * **Data:** Semantic Scholar API
  * **LLM Routing:** LiteLLM

-----

## πŸš€ Quickstart

### Prerequisites

  * Python 3.11+
  * [Semantic Scholar API Key](https://www.semanticscholar.org/product/api) (Free)
  * LLM Provider Key (Cerebras or Groq)

### Local Development

1.  **Clone & Install**

    ```bash
    git clone [https://github.com/adamcseresznye/necthrall.git](https://github.com/adamcseresznye/necthrall.git)
    cd necthrall
    pip install -r requirements.txt
    ```

2.  **Configure Environment**
    Create a `.env` file in the root directory

3.  **Run the App**

    ```bash
    python main.py
    ```

    The UI will be available at `http://localhost:7860`.

-----

## πŸ”’ Privacy & Data Retention

Necthrall is designed to be **ephemeral** and privacy-first:

  * **No Database:** We do not store user search queries or results.
  * **Memory Only:** Vector indices (FAISS) are built in RAM and destroyed immediately after the response is generated.

-----

## πŸ› οΈ Configuration

Necthrall uses **LiteLLM** for model routing. You can configure the following in your `.env` file:

| Variable | Description | Required |
| :--- | :--- | :--- |
| `SEMANTIC_SCHOLAR_API_KEY` | For searching papers | **Yes** |
| `PRIMARY_LLM_API_KEY` | Primary LLM (e.g., Llama 3.3) | **Yes** |
| `SECONDARY_LLM_API_KEY` | Fallback LLM (e.g., Llama 3.3) | Optional |
-----

## πŸ™ Acknowledgements

This project is made possible by the open-science ecosystem. Special thanks to:

- **[Semantic Scholar](https://www.semanticscholar.org/)**: For their open API that powers our paper discovery.
- **[LlamaIndex](https://www.llamaindex.ai/)**: The orchestration framework for our RAG pipeline and data ingestion.
- **[LiteLLM](https://github.com/BerriAI/litellm)**: For providing the unified interface that makes our multi-model routing possible.
- **[NiceGUI](https://nicegui.io/) & [FastAPI](https://fastapi.tiangolo.com/)**: For the seamless full-stack Python experience.
- **[Hugging Face](https://huggingface.co/)**: For hosting the demo infrastructure and serving the embedding models.

## πŸ“„ License

GPL-3.0 license