📝 FALLBACK: Simple pattern-based routing (original logic).
(self, message: str, idx_ids: List[str])
| 504 | return self._simple_pattern_routing(query, []) |
| 505 | |
| 506 | def _simple_pattern_routing(self, message: str, idx_ids: List[str]) -> bool: |
| 507 | """ |
| 508 | 📝 FALLBACK: Simple pattern-based routing (original logic). |
| 509 | """ |
| 510 | message_lower = message.lower() |
| 511 | |
| 512 | # Always use Direct LLM for greetings and casual conversation |
| 513 | greeting_patterns = [ |
| 514 | 'hello', 'hi', 'hey', 'greetings', 'good morning', 'good afternoon', 'good evening', |
| 515 | 'how are you', 'how do you do', 'nice to meet', 'pleasure to meet', |
| 516 | 'thanks', 'thank you', 'bye', 'goodbye', 'see you', 'talk to you later', |
| 517 | 'test', 'testing', 'check', 'ping', 'just saying', 'nevermind', |
| 518 | 'ok', 'okay', 'alright', 'got it', 'understood', 'i see' |
| 519 | ] |
| 520 | |
| 521 | # Check for greeting patterns |
| 522 | for pattern in greeting_patterns: |
| 523 | if pattern in message_lower: |
| 524 | return False # Use Direct LLM for greetings |
| 525 | |
| 526 | # Keywords that strongly suggest document-related queries |
| 527 | rag_indicators = [ |
| 528 | 'document', 'doc', 'file', 'pdf', 'text', 'content', 'page', |
| 529 | 'according to', 'based on', 'mentioned', 'states', 'says', |
| 530 | 'what does', 'summarize', 'summary', 'analyze', 'analysis', |
| 531 | 'quote', 'citation', 'reference', 'source', 'evidence', |
| 532 | 'explain from', 'extract', 'find in', 'search for' |
| 533 | ] |
| 534 | |
| 535 | # Check for strong RAG indicators |
| 536 | for indicator in rag_indicators: |
| 537 | if indicator in message_lower: |
| 538 | return True |
| 539 | |
| 540 | # Question words + substantial length might benefit from RAG |
| 541 | question_words = ['what', 'how', 'when', 'where', 'why', 'who', 'which'] |
| 542 | starts_with_question = any(message_lower.startswith(word) for word in question_words) |
| 543 | |
| 544 | if starts_with_question and len(message) > 40: |
| 545 | return True |
| 546 | |
| 547 | # Very short messages - use direct LLM |
| 548 | if len(message.strip()) < 20: |
| 549 | return False |
| 550 | |
| 551 | # Default to Direct LLM unless there's clear indication of document query |
| 552 | return False |
| 553 | |
| 554 | def _handle_direct_llm_query(self, session_id: str, message: str, session: dict): |
| 555 | """ |
no outgoing calls
no test coverage detected