File size: 2,234 Bytes
58b1106
 
 
 
 
 
 
 
 
 
 
 
 
630f6f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Phuree Healthcare Assistant
emoji: 🏥
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
---

# Qwen Healthcare Assistant

This is a healthcare assistant powered by a custom Qwen model.

## Current Runtime Flow

The Docker app runs `main_v2:app` with FastAPI and exposes:

- `GET /` for a health check.
- `GET /generate?query=...&useRAG=false&thread_id=...` for SSE chat streaming.
- `GET /clear?thread_id=...` to clear one conversation thread.

### Request Path

```text
Client
  -> GET /generate?query=...&useRAG=...&thread_id=...
  -> FastAPI generate_endpoint()
  -> Load LangGraph memory by thread_id
  -> If new thread: add initial health-assistant system message
  -> If useRAG=true: add internal force-retrieval marker
  -> Add user query
  -> Run LangGraph
  -> Stream SSE response back to client
```

### Routing Path

```text
User query
  -> Pure small talk?
       -> Yes: direct short reply
       -> No:
  -> Health capability/meta question?
       -> Yes: direct scope reply
       -> No:
  -> Clear animal or pet-health question?
       -> Yes: direct outside-scope reply
       -> No:
  -> Clear human-health question?
       -> Yes: retrieve_health_info tool call
       -> No:
  -> LLM router classifies query
       -> RETRIEVE: retrieve_health_info tool call
       -> ANIMAL: direct outside-scope reply
       -> DIRECT: direct response with conversation history
```

### RAG Path

```text
retrieve_health_info
  -> Chroma vector search
  -> BAAI/bge-m3 embeddings
  -> Candidate documents
  -> BAAI/bge-reranker-v2-m3 cross-encoder rerank
  -> Top reranked documents
  -> RAG prompt with relevant context
  -> Qwen/Ollama answer
  -> Clean <think>...</think>
  -> Stream:
       **Source:**{...}

       final answer
```

### Direct Path

```text
DIRECT route
  -> Build prompt from:
       DIRECT_RESPONSE_SYSTEM_MESSAGE
       + prior human messages
       + prior AI messages without tool calls
  -> Qwen/Ollama answer
  -> Clean <think>...</think>
  -> Stream final answer
```

### Error Path

```text
Ollama / router / RAG / streaming failure
  -> Catch exception
  -> Log error on server
  -> Stream fallback message to client
  -> Avoid raw 500 traceback in chat UI
```