feat: Investor Agent — FAQ als LLM-Kontext statt Direkt-Streaming

Architektur-Umbau: FAQ-Antworten werden NICHT mehr direkt gestreamt.
Stattdessen werden die Top-3 relevanten FAQ-Einträge als Kontext
ans LLM übergeben. Das LLM interpretiert die Frage, kombiniert
mehrere FAQs bei komplexen Fragen und antwortet natürlich.

Vorher: Frage → Keyword-Match → FAQ direkt streamen (LLM umgangen)
Nachher: Frage → Top-3 FAQ-Matches → LLM-Prompt als Kontext → LLM antwortet

Neue Funktionen:
- matchFAQMultiple(): Top-N Matches statt nur bester
- buildFAQContext(): Baut Kontext-String für LLM-Injection
- faqContext statt faqAnswer im Request-Body
- System-Prompt Anweisung: "Kombiniere bei Bedarf, natürlicher Fließtext"

Behebt: Komplexe Fragen mit 2+ Themen werden jetzt korrekt beantwortet

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-28 10:57:47 +01:00
parent 928556aa89
commit 34d2529e04
3 changed files with 44 additions and 54 deletions

View File

@@ -7,7 +7,7 @@ import { ChatMessage, Language, SlideId } from '@/lib/types'
import { t } from '@/lib/i18n'
import { SLIDE_ORDER } from '@/lib/hooks/useSlideNavigation'
import { PresenterState } from '@/lib/presenter/types'
import { matchFAQ, getFAQAnswer } from '@/lib/presenter/faq-matcher'
import { matchFAQMultiple, buildFAQContext } from '@/lib/presenter/faq-matcher'
interface ChatFABProps {
lang: Language
@@ -227,8 +227,9 @@ export default function ChatFAB({
setIsStreaming(true)
setIsWaiting(true)
// Check FAQ first for instant response
const faqMatch = matchFAQ(message, lang)
// Find relevant FAQ entries as context for the LLM
const faqMatches = matchFAQMultiple(message, lang, 3)
const faqContext = buildFAQContext(faqMatches, lang)
abortRef.current = new AbortController()
@@ -245,9 +246,9 @@ export default function ChatFAB({
},
}
// If FAQ matched, send the cached answer for fast streaming (no LLM call)
if (faqMatch) {
requestBody.faqAnswer = getFAQAnswer(faqMatch, lang)
// Send FAQ context to LLM (not direct streaming LLM interprets and combines)
if (faqContext) {
requestBody.faqContext = faqContext
}
const res = await fetch('/api/chat', {