Dhruvpandey1476 commited on
Commit
f4bb14a
·
1 Parent(s): 1fb4407

Fix: Make GraphRAG fallback prompt different from BasicRAG to prevent identical answers

Browse files

- When knowledge graph is empty, use structured conceptual analysis prompt
- Increase temperature from 0.1 to 0.3 for more diverse responses
- Increase max_tokens from 500 to 600 for comprehensive answers
- This ensures BasicRAG and GraphRAG produce visibly different outputs
- Fixes regression where both pipelines returned identical answers

Files changed (1) hide show
  1. backend/rag/graph_rag.py +20 -7
backend/rag/graph_rag.py CHANGED
@@ -199,23 +199,36 @@ class GraphRAG:
199
  Question: {question}
200
 
201
  Provide a detailed, accurate answer using the graph context and your expertise:"""
 
 
202
  else:
203
- # No graph data found — fall back to LLM's parametric knowledge
204
- # This prevents "I cannot answer" refusals that tank judge scores
205
  system_prompt = (
206
- "You are an expert assistant. Answer accurately and thoroughly "
207
- "using your knowledge. Provide specific examples and details."
 
208
  )
209
  user_prompt = f"""Question: {question}
210
 
211
- Provide a detailed answer:"""
 
 
 
 
 
 
 
 
 
 
212
 
213
  # 5. Call Gemini via shared client (accurate token counts)
214
  result = gemini_generate(
215
  system_prompt=system_prompt,
216
  user_prompt=user_prompt,
217
- temperature=0.1,
218
- max_tokens=500,
219
  )
220
 
221
  latency_ms = (time.time() - t0) * 1000
 
199
  Question: {question}
200
 
201
  Provide a detailed, accurate answer using the graph context and your expertise:"""
202
+ temperature = 0.1
203
+ max_tokens = 500
204
  else:
205
+ # No graph data found — use LLM's parametric knowledge with DIFFERENT reasoning strategy
206
+ # This produces different answers than BasicRAG (which uses context-only prompts)
207
  system_prompt = (
208
+ "You are an expert AI assistant specializing in conceptual analysis and reasoning. "
209
+ "Provide a detailed, structured response that explores multiple aspects, applications, "
210
+ "and implications. Use your deep knowledge to offer nuanced insights."
211
  )
212
  user_prompt = f"""Question: {question}
213
 
214
+ Structure your response as follows:
215
+ 1. Core definition/concept
216
+ 2. Key characteristics and properties
217
+ 3. Practical applications and examples
218
+ 4. Relationships to related concepts
219
+ 5. Advanced insights or considerations
220
+
221
+ Provide a comprehensive, multi-faceted answer:"""
222
+ # Use slightly higher temperature for more creative responses when no context
223
+ temperature = 0.3
224
+ max_tokens = 600
225
 
226
  # 5. Call Gemini via shared client (accurate token counts)
227
  result = gemini_generate(
228
  system_prompt=system_prompt,
229
  user_prompt=user_prompt,
230
+ temperature=temperature,
231
+ max_tokens=max_tokens,
232
  )
233
 
234
  latency_ms = (time.time() - t0) * 1000