Velayutham S commited on
Commit
a2d2a98
·
1 Parent(s): 6b00d65

fix: lower RAG threshold, more context for better accuracy

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -62,7 +62,7 @@ def embed_query(text: str):
62
  return None
63
 
64
  # ─── RAG Search ───────────────────────────
65
- def rag_search(query: str, grade: str = "", subject: str = "", top_k: int = 5) -> str:
66
  if faiss_index is None or not GEMINI_KEY:
67
  return ""
68
  vec = embed_query(query)
@@ -70,10 +70,10 @@ def rag_search(query: str, grade: str = "", subject: str = "", top_k: int = 5) -
70
  return ""
71
  q = np.array([vec], dtype=np.float32)
72
  faiss.normalize_L2(q)
73
- scores, indices = faiss_index.search(q, top_k * 3)
74
  chunks = []
75
  for score, idx in zip(scores[0], indices[0]):
76
- if idx < 0 or score < 0.35:
77
  continue
78
  meta = metadata_store[idx]
79
  if grade and meta.get("grade") != grade:
@@ -104,7 +104,7 @@ Give a STRUCTURED answer in Tamil+English mix with these sections:
104
  💡 **எளிய உதாரணம் (Simple Example):** [1 real-life example]
105
  📝 **நினைவில் வைக்க (Remember):** [1 key takeaway]"""
106
  elif mode == "📖 Story Mode":
107
- user = f"""Context: {context[:500] if context else ''}
108
 
109
  Write a SHORT story (exactly 6-8 sentences) about: {user_message}
110
  FORMAT:
@@ -114,7 +114,7 @@ FORMAT:
114
  📚 **கதையிலிருந்து பாடம் (Lesson from Story):**
115
  [1-2 sentences explaining what concept the story taught]"""
116
  else:
117
- user = f"""Context: {context[:500] if context else ''}
118
 
119
  Generate TN Board style exam questions for: {user_message}
120
 
@@ -146,7 +146,7 @@ FORMAT:
146
  {"role": "system", "content": SYSTEM_PROMPT},
147
  {"role": "user", "content": user}
148
  ],
149
- max_tokens=1024,
150
  temperature=0.7,
151
  )
152
  return response.choices[0].message.content.strip(), model_id.split("/")[-1]
 
62
  return None
63
 
64
  # ─── RAG Search ───────────────────────────
65
+ def rag_search(query: str, grade: str = "", subject: str = "", top_k: int = 8) -> str:
66
  if faiss_index is None or not GEMINI_KEY:
67
  return ""
68
  vec = embed_query(query)
 
70
  return ""
71
  q = np.array([vec], dtype=np.float32)
72
  faiss.normalize_L2(q)
73
+ scores, indices = faiss_index.search(q, top_k * 4)
74
  chunks = []
75
  for score, idx in zip(scores[0], indices[0]):
76
+ if idx < 0 or score < 0.25:
77
  continue
78
  meta = metadata_store[idx]
79
  if grade and meta.get("grade") != grade:
 
104
  💡 **எளிய உதாரணம் (Simple Example):** [1 real-life example]
105
  📝 **நினைவில் வைக்க (Remember):** [1 key takeaway]"""
106
  elif mode == "📖 Story Mode":
107
+ user = f"""Context: {context[:800] if context else ''}
108
 
109
  Write a SHORT story (exactly 6-8 sentences) about: {user_message}
110
  FORMAT:
 
114
  📚 **கதையிலிருந்து பாடம் (Lesson from Story):**
115
  [1-2 sentences explaining what concept the story taught]"""
116
  else:
117
+ user = f"""Context: {context[:800] if context else ''}
118
 
119
  Generate TN Board style exam questions for: {user_message}
120
 
 
146
  {"role": "system", "content": SYSTEM_PROMPT},
147
  {"role": "user", "content": user}
148
  ],
149
+ max_tokens=600,
150
  temperature=0.7,
151
  )
152
  return response.choices[0].message.content.strip(), model_id.split("/")[-1]