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

  1. Query in — You send a natural-language question. Wording carries emotional tone (frustrated, confused, curious).
  2. Emotion detection — DeepSeek classifies the message into labels such as anger, sadness, joy, or neutral, with a confidence score.
  3. Strategy selection — The agent maps emotion → one of three modes: concise, scaffolded, or standard.
  4. Retrieval — TF-IDF search over a small FAQ corpus runs with strategy-specific settings (top-k, score threshold, preferred doc types).
  5. Generation — DeepSeek answers using retrieved context and a strategy-specific system prompt. Answers use Markdown when helpful (lists, bold, steps).
  6. Explainability — Every response includes a rationale: detected emotion, confidence, chosen strategy, and why.

Strategies

StrategyTypical emotionsRetrievalAnswer shape
conciseanger, disgust, fearFewer chunks, higher score bar, prefer FAQShort, direct, reassuring
scaffoldedsadness, low-confidence neutralMore chunks, prefer how-to docsNumbered steps, defines jargon
standardjoy, surprise, confident neutralBalanced top-k across doc typesInformative 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.