    def generate_vocabulary_quiz(self, topic_content, num_questions=5):
        """
        Generate vocabulary quiz questions from difficult words in the topic content
        
        Args:
            topic_content (str): The text content to extract vocabulary from
            num_questions (int): Number of questions to generate
            
        Returns:
            list: List of QuizQuestion objects
        """
        try:
            # First, check if the API is properly configured
            if not self._configure_genai():
                logger.error("Failed to configure Gemini API. Using fallback vocabulary quiz.")
                return self._generate_fallback_vocabulary_questions(topic_content, num_questions)
            
            # Get the model
            model = self.get_model()
            if not model:
                logger.error("Failed to get AI model. Using fallback vocabulary quiz.")
                return self._generate_fallback_vocabulary_questions(topic_content, num_questions)
            
            # Create the prompt
            prompt = f"""
            Create a vocabulary quiz with {num_questions} questions based on the following text.
            
            IMPORTANT REQUIREMENTS:
            1. Identify {num_questions} difficult or important words from the text
            2. For each word, create an MCQ question asking for its meaning
            3. Provide 4 options for each question, with one correct answer
            4. Include the sentence from the text where the word appears (as context)
            5. Format your response as JSON with the following structure:
            
            [
                {{
                    "word": "example",
                    "context": "This is an example sentence from the text.",
                    "question": "What does 'example' mean in this context?",
                    "correct_answer": "A representative case or instance",
                    "options": [
                        "A representative case or instance", 
                        "A difficult problem to solve", 
                        "A type of examination", 
                        "A mathematical equation"
                    ]
                }},
                // more questions...
            ]
            
            Text: {topic_content}
            """
            
            # Generate questions
            response = model.generate_content(prompt)
            response_text = response.text.strip()
            
            # Extract JSON from response (in case of markdown code blocks)
            json_match = re.search(r'```json\s*(.*?)\s*```', response_text, re.DOTALL)
            if json_match:
                json_str = json_match.group(1)
            else:
                json_str = response_text
            
            # Clean up any non-JSON text
            json_str = re.sub(r'^[\s\S]*?\[', '[', json_str)
            json_str = re.sub(r'\][\s\S]*?$', ']', json_str)
            
            # Parse JSON and create quiz questions
            questions_data = json.loads(json_str)
            questions = []
            
            for q_data in questions_data[:num_questions]:  # Limit to requested number
                question = QuizQuestion(
                    word=q_data.get('word', ''),
                    context=q_data.get('context', ''),
                    question_text=q_data.get('question', f"What does '{q_data.get('word', '')}' mean?"),
                    correct_answer=q_data.get('correct_answer', ''),
                    options=json.dumps(q_data.get('options', []))
                )
                questions.append(question)
            
            return questions
            
        except Exception as e:
            logger.error(f"Error generating vocabulary quiz: {str(e)}")
            return self._generate_fallback_vocabulary_questions(topic_content, num_questions)
    
    def _generate_fallback_vocabulary_questions(self, topic_content, num_questions=5):
        """Generate basic vocabulary questions when AI is unavailable"""
        try:
            # Tokenize text into words
            words = word_tokenize(topic_content.lower())
            
            # Remove common words and duplicates
            stopwords = {'a', 'an', 'the', 'and', 'or', 'but', 'if', 'because', 'as', 'what', 'when', 
                        'where', 'how', 'why', 'is', 'am', 'are', 'was', 'were', 'be', 'been', 'being', 
                        'have', 'has', 'had', 'do', 'does', 'did', 'to', 'at', 'by', 'for', 'with', 
                        'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 
                        'above', 'below', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under'}
            
            unique_words = [word for word in words if word.isalpha() and word not in stopwords and len(word) > 4]
            unique_words = list(set(unique_words))  # Remove duplicates
            
            # Extract sentences containing these words
            sentences = sent_tokenize(topic_content)
            word_contexts = {}
            
            for word in unique_words:
                for sentence in sentences:
                    if word in sentence.lower():
                        word_contexts[word] = sentence
                        break
            
            # Select words that have contexts
            selected_words = list(word_contexts.keys())
            if len(selected_words) > num_questions:
                selected_words = random.sample(selected_words, num_questions)
            
            # Create basic questions
            questions = []
            common_definitions = {
                'important': 'having great significance or value',
                'different': 'not the same as another or each other',
                'special': 'better, greater, or otherwise different from what is usual',
                'example': 'a thing characteristic of its kind',
                'learning': 'the acquisition of knowledge or skills',
                'specific': 'clearly defined or identified',
                'general': 'affecting or concerning all or most people, places, or things',
                'complete': 'having all the necessary or appropriate parts',
                'various': 'of different kinds or sorts',
                'similar': 'resembling without being identical',
            }
            
            for word in selected_words:
                # Generate fake options
                if word in common_definitions:
                    correct_answer = common_definitions[word]
                else:
                    correct_answer = f"The meaning of '{word}'"
                
                options = [
                    correct_answer,
                    f"The opposite of '{word}'",
                    f"A type of {word}",
                    f"Related to {word} but different"
                ]
                random.shuffle(options)
                
                question = QuizQuestion(
                    word=word,
                    context=word_contexts[word],
                    question_text=f"What does '{word}' mean?",
                    correct_answer=correct_answer,
                    options=json.dumps(options)
                )
                questions.append(question)
            
            return questions
            
        except Exception as e:
            logger.error(f"Error generating fallback vocabulary questions: {str(e)}")
            
            # Return extremely basic questions if all else fails
            questions = []
            for i in range(min(num_questions, 3)):
                word = f"word{i+1}"
                question = QuizQuestion(
                    word=word,
                    context=f"This is a sentence with {word}.",
                    question_text=f"What does '{word}' mean?",
                    correct_answer=f"Definition of {word}",
                    options=json.dumps([f"Definition of {word}", f"Not {word}", f"Similar to {word}", f"Opposite of {word}"])
                )
                questions.append(question)
            
            return questions