From ebbc19c01d861cd91e3c74d37919486d359399fb Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 15 Jun 2026 22:53:42 +0200 Subject: [PATCH] Enhance chat memory NLP by updating stopwords, improving last conversation detection regex, and adding query expansions. --- backend/chat_memory.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/chat_memory.py b/backend/chat_memory.py index 583b9fa..8654c23 100644 --- a/backend/chat_memory.py +++ b/backend/chat_memory.py @@ -20,10 +20,27 @@ _STOPWORDS = { "from", "had", "has", "have", "how", "into", "just", "like", "more", "not", "now", "our", "out", "over", "please", "should", "that", "the", "then", "there", "this", "was", "were", "what", "when", "where", "which", "with", "would", "you", "your", + "all", "anything", "chat", "chats", "conversation", "conversations", "discuss", + "discussed", "everything", "list", "me", "talk", "talked", "tell", "topic", "topics", "aber", "als", "auch", "auf", "aus", "bei", "bin", "bis", "das", "dem", "den", - "der", "des", "die", "ein", "eine", "einem", "einen", "einer", "für", "hat", - "ich", "ist", "mit", "nicht", "oder", "sich", "sind", "und", "uns", "von", - "war", "was", "wie", "wir", "zu", "zum", "zur", + "der", "des", "die", "ein", "eine", "einem", "einen", "einer", "erzaehl", "erzähl", + "erzähle", "für", "ging", "hat", "ich", "ist", "letzte", "letzten", "letztes", "mir", + "mit", "nicht", "oder", "sich", "sind", "und", "uns", "über", "ueber", "von", + "war", "was", "wie", "wir", "worum", "zu", "zum", "zur", +} +_LAST_CONVERSATION_RE = re.compile( + r"\b(last|latest|previous|prior)\s+(chat|conversation|session)\b" + r"|\b(letzte[sn]?|vorherige[sn]?)\s+(gespr[aä]ch|chat|unterhaltung)\b" + r"|\bworum\s+ging\s+es\s+im\s+letzte[sn]?\s+gespr[aä]ch\b", + re.IGNORECASE, +) +_QUERY_EXPANSIONS = { + "music": ["song", "songs", "album", "albums", "artist", "artists", "band", "bands", "lied", "lieder", "musik"], + "musik": ["music", "song", "songs", "album", "albums", "artist", "artists", "band", "bands", "lied", "lieder"], + "song": ["music", "songs", "lied", "lieder", "musik"], + "songs": ["music", "song", "lied", "lieder", "musik"], + "lied": ["music", "musik", "song", "songs", "lieder"], + "lieder": ["music", "musik", "song", "songs", "lied"], }