MCPcopy
hub / github.com/PromtEngineer/localGPT / _should_use_rag

Method _should_use_rag

backend/server.py:342–366  ·  view source on GitHub ↗

🧠 ENHANCED: Determine if a query should use RAG pipeline using document overviews. Args: message: The user's query idx_ids: List of index IDs associated with the session Returns: bool: True if should use RAG, False fo

(self, message: str, idx_ids: List[str])

Source from the content-addressed store, hash-verified

340 print(f"⚠️ Client disconnected during error response")
341
342 def _should_use_rag(self, message: str, idx_ids: List[str]) -> bool:
343 """
344 🧠 ENHANCED: Determine if a query should use RAG pipeline using document overviews.
345
346 Args:
347 message: The user's query
348 idx_ids: List of index IDs associated with the session
349
350 Returns:
351 bool: True if should use RAG, False for direct LLM
352 """
353 # No indexes = definitely no RAG needed
354 if not idx_ids:
355 return False
356
357 # Load document overviews for intelligent routing
358 try:
359 doc_overviews = self._load_document_overviews(idx_ids)
360 if doc_overviews:
361 return self._route_using_overviews(message, doc_overviews)
362 except Exception as e:
363 print(f"⚠️ Overview-based routing failed, falling back to simple routing: {e}")
364
365 # Fallback to simple pattern matching if overviews unavailable
366 return self._simple_pattern_routing(message, idx_ids)
367
368 def _load_document_overviews(self, idx_ids: List[str]) -> List[str]:
369 """Load and aggregate overviews for the given index IDs.

Callers 1

handle_session_chatMethod · 0.95

Calls 3

Tested by

no test coverage detected