Spaces:
Running
Running
Ali Hashhash
feat: implement Pydantic configuration management, add end-to-end pipeline testing, and include documentation for the recommendation module.
b27958e Recommendation Module 🎯
Responsibility
This module handles suggesting new educational videos based on user interests.
Functionality
- Analyze user's saved notes.
- Extract topics and categories.
- Search YouTube for related videos.
- Return a list of suggested educational videos.
Files
1. recommender.py
- Purpose: Suggest educational videos from YouTube.
- Main Class:
RecommendationService - Key Methods:
get_recommendations_for_user(user_id)- Get general recommendations for user.get_youtube_recommendations(query)- Search YouTube based on keywords.get_similar_notes(note_id)- Get similar notes from the same category.
How It Works
- Fetch Notes: Read the user's last 5 saved notes.
- Extract Topics: Use categories or titles.
- Enhance Search: Add keywords like "educational", "tutorial", "lecture".
- Filter Results: Select only embeddable videos.
Proposed Enhancements
- Add caching for recommendations to reduce YouTube API calls.
- Use Machine Learning to improve recommendation accuracy.
- Add filter for video duration (avoid very long videos).
- Prioritize well-known educational channels.
Testing
from src.ai_modules.recommendation.recommender import RecommendationService
from src.db.database import get_session
recommender = RecommendationService()
# Get recommendations for user
async def test_recommendations():
async with get_session() as session:
recs = await recommender.get_recommendations_for_user(session, user_id=1)
for video in recs:
print(f"{video['title']} - {video['url']}")
Libraries Used
google-api-python-client- Search YouTube.groq- Extract topics via LLM.
Important Notes
- YouTube API has a daily quota limit, use caching to reduce requests.
- Enhanced search adds "educational lecture tutorial" keywords for better educational results.
- System prioritizes videos from the same category.
API Quota Management
It's recommended to cache results temporarily to avoid exhausting YouTube API quota:
# Simple cache example
cache = {}
def get_cached_recommendations(query):
if query in cache:
return cache[query]
results = youtube_search(query)
cache[query] = results
return results