import json import numpy as np from duplicate_checker import QuestionDuplicateChecker checker = QuestionDuplicateChecker() user_input = { 'stem': '如图,两个同心圆中,大圆的半径为$5$,小圆的半径为$3$,若大圆的弦$AB$与小圆有公共点,则$AB$的取值范围是( )', 'options': '{"A": "$8\\le AB\\le10$", "B": "$8' } # Fetch ID 3094 q3094 = checker.fetch_question_from_db(3094) if not q3094: print("Question 3094 not found") exit() print(f"Comparing user input with ID 3094\n") # Calculate embeddings for each part to see where it drops parts = ['stem', 'options', 'answer', 'solution'] for p in parts: u_text = user_input.get(p, '') db_text = str(q3094.get(p, '') or '') u_emb = checker.get_embedding(u_text) db_emb = checker.get_embedding(db_text) if u_emb is not None and db_emb is not None: # Normalize u_emb = u_emb / np.linalg.norm(u_emb) db_emb = db_emb / np.linalg.norm(db_emb) sim = np.dot(u_emb, db_emb) print(f"Part {p} similarity: {sim:.4f}") else: print(f"Part {p} failed to get embedding") mega_u = checker.get_weighted_embedding(user_input) mega_db = checker.get_weighted_embedding(q3094) if mega_u is not None and mega_db is not None: overall_sim = np.dot(mega_u, mega_db) print(f"\nOverall weighted similarity: {overall_sim:.4f}") else: print("\nMega vector calculation failed")