Spaces:
Running
Running
axeronis commited on
Commit ·
8f0d24c
1
Parent(s): bcf5f89
fix: improve nickname detection and lower knowledge retrieval threshold
Browse files
backend/app/services/ai_core/context_manager.py
CHANGED
|
@@ -153,7 +153,7 @@ async def get_relevant_context(
|
|
| 153 |
tenant_id=tenant_id,
|
| 154 |
query=user_message,
|
| 155 |
top_k=top_k,
|
| 156 |
-
min_similarity=0.
|
| 157 |
)
|
| 158 |
|
| 159 |
if not results:
|
|
|
|
| 153 |
tenant_id=tenant_id,
|
| 154 |
query=user_message,
|
| 155 |
top_k=top_k,
|
| 156 |
+
min_similarity=0.45 # Lowered from 0.6 for better name/entity matching
|
| 157 |
)
|
| 158 |
|
| 159 |
if not results:
|
backend/app/utils/name_extraction.py
CHANGED
|
@@ -207,6 +207,29 @@ def should_update_lead_name(current_name: str, extracted_name: str) -> bool:
|
|
| 207 |
if any(c.isdigit() for c in current_stripped) or any(c in "_-." for c in current_stripped):
|
| 208 |
return True
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
# Update if current is generic
|
| 211 |
generic_names = ["user", "client", "lead", "пользователь", "клиент", "лид", "unknown", "неизвестно"]
|
| 212 |
if any(generic in current_lower for generic in generic_names):
|
|
|
|
| 207 |
if any(c.isdigit() for c in current_stripped) or any(c in "_-." for c in current_stripped):
|
| 208 |
return True
|
| 209 |
|
| 210 |
+
# NEW: Detect Telegram-style nicknames
|
| 211 |
+
# Pattern 1: Single letter + word (e.g., "G Scream", "J Smith", "V Lord")
|
| 212 |
+
words = current_stripped.split()
|
| 213 |
+
if len(words) == 2 and len(words[0]) == 1 and words[0].isupper():
|
| 214 |
+
return True
|
| 215 |
+
|
| 216 |
+
# Pattern 2: CamelCase or single English words that look like nicknames
|
| 217 |
+
english_nickname_patterns = [
|
| 218 |
+
"scream", "lord", "king", "queen", "dark", "night", "wolf", "dragon",
|
| 219 |
+
"fire", "ice", "shadow", "phantom", "ghost", "storm", "blade", "star",
|
| 220 |
+
"moon", "sun", "sky", "master", "boss", "pro", "gamer", "hacker",
|
| 221 |
+
"ninja", "samurai", "snake", "eagle", "lion", "tiger", "bear", "fox"
|
| 222 |
+
]
|
| 223 |
+
if any(pattern in current_lower for pattern in english_nickname_patterns):
|
| 224 |
+
return True
|
| 225 |
+
|
| 226 |
+
# Pattern 3: Contains ASCII letters but not Cyrillic (likely English nickname for Russian context)
|
| 227 |
+
has_ascii = any('a' <= c.lower() <= 'z' for c in current_stripped)
|
| 228 |
+
has_cyrillic = any('\u0400' <= c <= '\u04FF' for c in current_stripped)
|
| 229 |
+
# If name is only in English but we're in Russian context (extracted name is Cyrillic), update
|
| 230 |
+
if has_ascii and not has_cyrillic and any('\u0400' <= c <= '\u04FF' for c in extracted_name):
|
| 231 |
+
return True
|
| 232 |
+
|
| 233 |
# Update if current is generic
|
| 234 |
generic_names = ["user", "client", "lead", "пользователь", "клиент", "лид", "unknown", "неизвестно"]
|
| 235 |
if any(generic in current_lower for generic in generic_names):
|