Documentation
How emotion-aware agentic RAG works in this demo — from query to strategy to answer.
What is this?
Emotion-Aware Agentic RAG is a research demo that treats the user's emotional tone as a control signal for retrieval and generation. Instead of running the same RAG pipeline for every message, an agent detects affect, picks a strategy, retrieves documents accordingly, and generates an answer shaped to that state.
The goal is to show how affective computing, agentic control, and explainable AI can fit together in a small, inspectable system — not just as separate ideas, but as one loop you can try in the browser.
Pipeline
- Query in — You send a natural-language question. Wording carries emotional tone (frustrated, confused, curious).
- Emotion detection — DeepSeek classifies the message into labels such as anger, sadness, joy, or neutral, with a confidence score.
- Strategy selection — The agent maps emotion → one of three modes:
concise,scaffolded, orstandard. - Retrieval — TF-IDF search over a small FAQ corpus runs with strategy-specific settings (top-k, score threshold, preferred doc types).
- Generation — DeepSeek answers using retrieved context and a strategy-specific system prompt. Answers use Markdown when helpful (lists, bold, steps).
- Explainability — Every response includes a rationale: detected emotion, confidence, chosen strategy, and why.
Strategies
| Strategy | Typical emotions | Retrieval | Answer shape |
|---|---|---|---|
concise | anger, disgust, fear | Fewer chunks, higher score bar, prefer FAQ | Short, direct, reassuring |
scaffolded | sadness, low-confidence neutral | More chunks, prefer how-to docs | Numbered steps, defines jargon |
standard | joy, surprise, confident neutral | Balanced top-k across doc types | Informative mid-length answer |
Why emotion changes the answer
The same factual question can be asked in different emotional frames. A frustrated user often needs a fast, calming path forward; a confused user needs structure; a curious user may want a balanced overview.
Static RAG ignores that difference. This demo makes the choice explicit: open the Compare page, pick an intent (e.g. upload docs), and run frustrated vs confused vs curious variants side by side.
Explainability trace
Each response includes metadata like:
Detected emotion: anger (0.95 confidence) -> switched to concise mode: fewer high-confidence chunks, shorter reassuring answer.
That trace is the explainability layer: you can see what the agent inferred and which retrieval/generation policy it applied, without digging into logs.
Stack
- Frontend — Next.js on Vercel; Markdown-rendered answers
- API — FastAPI on Render
- LLM — DeepSeek (
deepseek-chat) for emotion classification and answer generation - Retrieval — TF-IDF over a bundled NovaAssist FAQ corpus
Try it
Go to Ask and try the example buttons (Frustrated / Confused / Curious) on the same underlying topic. Watch the strategy chip and rationale change, then read the Markdown-formatted answer.