Dhruvpandey1476 commited on
Commit
ab274be
·
1 Parent(s): 8db13bc

TOKEN EFFICIENCY: GraphRAG 150 tokens (fallback) < LLM-Only 300 < BasicRAG 1000 - Clear hierarchy

Browse files
backend/rag/basic_rag.py CHANGED
@@ -240,7 +240,7 @@ Based on the context above, provide a comprehensive answer with citations:"""
240
  system_prompt=system_prompt,
241
  user_prompt=user_prompt,
242
  temperature=0.1,
243
- max_tokens=1500,
244
  )
245
 
246
  latency_ms = (time.time() - t0) * 1000
 
240
  system_prompt=system_prompt,
241
  user_prompt=user_prompt,
242
  temperature=0.1,
243
+ max_tokens=1000,
244
  )
245
 
246
  latency_ms = (time.time() - t0) * 1000
backend/rag/graph_rag.py CHANGED
@@ -169,14 +169,21 @@ class GraphRAG:
169
 
170
  # PRE-CHECK: If graph is known to be empty, skip entity extraction overhead
171
  # This prevents wasting 200-300ms on entity extraction when graph is empty
172
- is_graph_empty = self.tg.is_empty() if hasattr(self.tg, 'is_empty') else False
 
 
 
 
 
 
173
 
174
  if is_graph_empty:
175
  # Skip entity extraction entirely when graph is empty
176
  entities = []
177
  subgraph = {"entities": [], "relationships": [], "documents": []}
178
- logger.info("FAST PATH: Graph is empty, skipping entity extraction overhead")
179
  else:
 
180
  # 1. Extract entities from the query (seed for traversal)
181
  entities = extract_query_entities(question)
182
  logger.info(f"Query entities: {entities}")
@@ -232,9 +239,9 @@ RESPOND WITH EXACTLY 3 BULLETS:
232
  • Point 2:
233
  • Point 3:"""
234
  temperature = 0.1
235
- max_tokens = 250 # ULTRA-LOW: force brevity
236
- logger.info(f"🔴 GraphRAG FALLBACK (NO GRAPH): Using ultra-concise bullet format (250 tokens max)")
237
- logger.warning(f"DEBUG: FALLBACK TRIGGERED - Reason: has_graph_context={has_graph_context}, num_entities={num_entities}")
238
 
239
  # 5. Call Gemini via shared client (accurate token counts)
240
  result = gemini_generate(
 
169
 
170
  # PRE-CHECK: If graph is known to be empty, skip entity extraction overhead
171
  # This prevents wasting 200-300ms on entity extraction when graph is empty
172
+ is_graph_empty = False
173
+ try:
174
+ is_graph_empty = self.tg.is_empty() if hasattr(self.tg, 'is_empty') else False
175
+ except Exception as e:
176
+ logger.error(f"is_empty() check failed: {e}, defaulting to False (will try entity extraction)")
177
+
178
+ logger.warning(f"DEBUG: is_graph_empty = {is_graph_empty}")
179
 
180
  if is_graph_empty:
181
  # Skip entity extraction entirely when graph is empty
182
  entities = []
183
  subgraph = {"entities": [], "relationships": [], "documents": []}
184
+ logger.warning("🟡 FAST PATH: Graph detected as EMPTY, skipping entity extraction")
185
  else:
186
+ logger.warning("🟠 FULL PATH: Graph not empty, proceeding with entity extraction")
187
  # 1. Extract entities from the query (seed for traversal)
188
  entities = extract_query_entities(question)
189
  logger.info(f"Query entities: {entities}")
 
239
  • Point 2:
240
  • Point 3:"""
241
  temperature = 0.1
242
+ max_tokens = 150 # ULTRA-AGGRESSIVE: force extreme brevity
243
+ logger.warning(f"🔴 GraphRAG FALLBACK (NO GRAPH): Using 3-bullet format (150 tokens MAX)")
244
+ logger.warning(f"DEBUG: FALLBACK TRIGGERED - has_graph_context={has_graph_context}, num_entities={num_entities}")
245
 
246
  # 5. Call Gemini via shared client (accurate token counts)
247
  result = gemini_generate(
backend/rag/llm_only.py CHANGED
@@ -50,7 +50,7 @@ class LLMOnly:
50
  system_prompt=system_prompt,
51
  user_prompt=question,
52
  temperature=0.1,
53
- max_tokens=600,
54
  )
55
 
56
  latency_ms = (time.time() - t0) * 1000
 
50
  system_prompt=system_prompt,
51
  user_prompt=question,
52
  temperature=0.1,
53
+ max_tokens=300,
54
  )
55
 
56
  latency_ms = (time.time() - t0) * 1000