File size: 9,348 Bytes
e92c350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269becd
 
e92c350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# BioPacific MIP Research Assistant

BioPacific MIP Research Assistant is an agentic AI system designed to help researchers explore and understand scientific literature more efficiently. It combines a local LLM service, an embedding model, a Qdrant vector database, and an automated paper-processing pipeline to support paper-grounded question answering over the BioPacific literature collection.

The system can ingest papers, update the searchable database, retrieve relevant documents, and serve a session-based REST API for interactive research workflows.

## New Features

The current version introduces several improvements for a more practical research assistant experience.

- **Multi-turn conversation support.** The agent now supports session-based conversations, so users can ask follow-up questions while preserving the context of previous turns.
- **Automatic intention recognition.** The agent can decide whether a user message actually needs retrieval. For example, it can skip retrieval for simple follow-up requests such as rephrasing, but perform retrieval when the question requires scientific evidence.
- **Automatic natural-language filters.** The agent can infer structured retrieval constraints directly from user language, including journal, time range, and author hints. For example, if a user asks for *synthetic biology papers published in PNAS in the last 4 years*, the system can translate that request into targeted retrieval filters automatically.
- **More concise and precise answers.** Before generating the final response, the agent first cleans and compresses retrieved paper content into focused summaries, then answers based on those refined inputs. This makes the final output shorter, clearer, and more relevant to the user's request.

## Environment Setup

This project requires an **Anaconda/Conda** environment.

Please firstly unzip the src.zip.
Then, from the repository root, run:

```bash
bash install_env.sh
```

This script will automatically create a Conda environment named `biopacific` and install the required packages for the project.

After the environment is created, go to the `models/` directory. Each model folder contains its own `download_model.sh` script. Run those scripts to download the required local models:

```bash
cd models/Qwen3-Embedding-8B
bash download_model.sh

cd ../Qwen3.5-9B
bash download_model.sh
```

After that, activate the environment when you want to use the system:

```bash
conda activate biopacific
```

## Configuration

After installing the environment, configure the project by editing `config.yaml`.

Most settings in `config.yaml` do not need to be changed for normal use. In practice, the most important items are:

- **GPU allocation**
- **Port allocation**

### GPU Allocation

The two vLLM services are configured independently:

- `embedding.gpu`: GPU used by the embedding model
- `llm.gpu`: GPU used by the chat/completions model

By default, the config assigns:

- `embedding.gpu: "0"`
- `llm.gpu: "1"`

If your machine has at least two GPUs, this is a good default because the embedding model and the chat model can run separately. If you only have one GPU, you will need to adjust the configuration carefully based on available memory and your deployment strategy.

You may also need to tune:

- `embedding.gpu_memory_utilization`
- `llm.gpu_memory_utilization`
- `embedding.max_model_len`
- `llm.max_model_len`

If you encounter out-of-memory issues, reducing the memory utilization value is usually the first thing to try.

### Port Allocation

The default service layout is:

- `embedding.port: 7770`
- `llm.port: 7771`
- `qdrant.port: 7772`
- `pipeline.s5_agent.service_port: 7773`

Make sure these ports are free on your machine before starting the system. If any of them conflict with another service, update the values in `config.yaml`.

## Running the System

Once the `biopacific` environment is ready and `config.yaml` has been configured, start the system from the repository root:

```bash
conda activate biopacific
cd /path/to/BioPacific-MIP-Rearch-Assistant
./start_service.sh
```

This command automatically starts the following long-running services:

- `embedding`: vLLM embedding server
- `llm`: vLLM chat/completions server
- `qdrant`: vector database
- `agent`: paper agent REST service

The startup workflow also runs the data pipeline automatically:

1. It checks and starts the prerequisite services.
2. It runs the paper pipeline stages.
3. It updates the paper database if new content is available.
4. It finally starts the agent REST service.

After the agent service is running, the system is ready to be accessed through the REST API.

### Common Commands

Start everything:

```bash
./start_service.sh
```

Stop everything:

```bash
./start_service.sh stop
```

Restart everything:

```bash
./start_service.sh restart
```

Check service status:

```bash
./start_service.sh status
```

If you want the paper database to refresh regularly, you can schedule a monthly restart:

```bash
./start_service.sh restart
```

Running this periodically is useful because each restart will trigger the automated pipeline and allow the database to update when new papers are available.

## REST API Usage

An example client is provided in `rest-api/example_chat_session.py`.

You can run it directly after the services are up:

```bash
python rest-api/example_chat_session.py
```

### Session ID and Multi-turn Conversation

The REST API is session-based. A `sessionId` identifies one conversation on the server side.

If you keep using the same `sessionId`, the agent will preserve recent conversation history and support multi-turn follow-up questions. This is what enables interactions such as:

- asking an initial literature question
- following up with "tell me more about paper [2]"
- requesting a simpler explanation of the previous answer

If you start a new `sessionId`, the server treats it as a new conversation.

### The Three Core Methods

The API provides three main endpoints:

#### 1. Start a Session

`POST /v1/session/start`

Example request body:

```json
{
  "sessionId": "optional-session-id"
}
```

Example response:

```json
{
  "sessionId": "your-session-id"
}
```

If you do not want to manage session IDs yourself, the example client can generate one automatically.

#### 2. Chat

`POST /v1/chat`

Example request body:

```json
{
  "sessionId": "your-session-id",
  "message": "Find synthetic biology papers published in PNAS in the last 4 years."
}
```

Example response shape:

```json
{
  "sessionId": "your-session-id",
  "response": "Final grounded answer...",
  "docs": [
    {
      "chat_doc_id": 1,
      "rank": 1,
      "score": 0.91,
      "paper": {
        "title": "...",
        "authors": ["..."],
        "journal": "...",
        "pub_date": "...",
        "doi": "...",
        "keywords": ["..."],
        "abstract": "...",
        "sections": [
          {
            "section_title": "...",
            "subsections": [
              {
                "title": "...",
                "paragraphs": ["..."]
              }
            ]
          }
        ],
        "link": "https://pubmed.ncbi.nlm.nih.gov/..."
      }
    }
  ]
}
```

The `response` field contains the assistant answer, and `docs` contains the retrieved paper results for that turn. Each document entry currently includes:

- `chat_doc_id`: the stable paper identifier used by the assistant for inline citations during the chat session
- `rank`: the retrieval ranking for the current turn
- `score`: the retrieval similarity score returned by the agent
- `paper`: the paper payload, including `title`, `abstract`, `sections`, `authors`, `journal`, `pub_date`, `doi`, `keywords`, and a PubMed `link`

Important: citations in the agent's `response` refer to `chat_doc_id`, not to `rank`. For example, if the response cites paper `[3]`, that means the cited paper is the one whose `chat_doc_id` is `3`, not necessarily the paper whose retrieval `rank` is `3` in the current turn.

#### 3. End a Session

`POST /v1/session/end`

Example request body:

```json
{
  "sessionId": "your-session-id"
}
```

Example response:

```json
{
  "ok": true
}
```

Ending a session clears the conversation state associated with that session on the server.

### Example Python Workflow

The example client exposes three corresponding methods:

- `start_session()`
- `chat()`
- `end_session()`

A typical workflow looks like this:

```python
from example_chat_session import ExampleChatSession

session = ExampleChatSession()
session.start_session()

session.chat("Find synthetic biology papers published in PNAS in the last 4 years.")
session.chat("Now summarize the key trends from those papers.")
session.chat("Please explain the previous answer in simpler language.")

session.end_session()
```

As long as the same session remains active, the assistant can use the conversation history to interpret follow-up questions more effectively.

## Summary

BioPacific MIP Research Assistant provides an agentic, paper-grounded research workflow with automated paper ingestion, retrieval, summarization, and session-based conversation. With the latest updates, it now supports better multi-turn interaction, smarter retrieval decisions, more precise natural-language filtering, and cleaner final answers for literature exploration.