1616async def get_related_videos (
1717 video_id : VideoID , limit : int = 10
1818) -> List [RecommendationItem ]:
19- """Return a stubbed *related videos* list.
20-
21- In a future iteration this will call into a real recommendation engine that
22- analyses the content of the referenced video to find similar items. For the
23- moment we simply return the latest videos (excluding the reference video)
24- and assign each a random relevance score.
25- """
2619
2720 from opentelemetry import trace
2821 import time
@@ -42,18 +35,28 @@ async def get_related_videos(
4235 if target_video is None :
4336 return []
4437
45- latest_summaries , _total = await video_service .list_latest_videos (
46- page = 1 , page_size = limit + 5
38+ latest_summaries , _total = await video_service .get_recommended_videos (
39+ query_vector = target_video . content_features , page = 1 , page_size = limit + 5
4740 )
4841
4942 related_items : List [RecommendationItem ] = []
43+ unique_video_names : List [str ] = []
5044
5145 for summary in latest_summaries :
5246 if summary .videoId == video_id :
5347 # Skip the source video itself
5448 continue
49+
50+ if summary .title in unique_video_names :
51+ # Skip if we've already added this video to the list
52+ # ...sometimes we get duplicate rows
53+ continue
54+
5555 if len (related_items ) >= limit :
5656 break
57+
58+ unique_video_names .append (summary .title )
59+
5760 related_items .append (
5861 RecommendationItem (
5962 videoId = summary .videoId ,
0 commit comments