Commit 60ce4a8c authored by salma's avatar salma

faster and cheeper mcq generation

parent 67972c15
......@@ -98,6 +98,8 @@ class MCQService:
# Slice to exact number requested (in case we generated extras)
final_set = accepted_mcqs[:num_questions]
self.pgvector.insert_mcqs(final_set)
for q in final_set:
q.pop('embedding', None)
return final_set
# If we failed to generate enough
......@@ -105,6 +107,8 @@ class MCQService:
logger.warning(f"Could not generate unique questions for {concept} after {attempts} attempts.")
return []
return accepted_mcqs
......
......@@ -547,13 +547,12 @@ class PGVectorService:
def get_mcqs(self, curriculum: str, grade: str, subject: str, unit: str, concept: str, is_arabic: bool, limit: Optional[int] = 10) -> List[Dict]:
"""
Retrieves MCQs for a specific topic and language, now filtering by curriculum.
If limit is None, it retrieves all matching questions.
Retrieves MCQs for a specific topic and language.
Removes the 'embedding' field to prevent JSON serialization errors with ndarrays.
"""
with self.pool_handler.get_connection() as conn:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
# --- UPDATED SELECT AND WHERE CLAUSE ---
query = """
SELECT *
FROM mcq_questions
......@@ -570,7 +569,12 @@ class PGVectorService:
query += ";"
cur.execute(query, params)
return cur.fetchall()
results = cur.fetchall()
for row in results:
row.pop('embedding', None)
return results
def get_distinct_curricula_from_structure(self) -> List[str]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment