Skip to content

API reference

Core

recommend(interaction_history: list[tuple[UUID, int]], count: int = 10) -> list[UUID]

Synchronously predict the best recommendations for given interaction_history

Parameters:

  • interaction_history (list[tuple[UUID, int]]) –

    list of (UUID, int) pairs, where UUID is the video id, and int is the reaction (1 - like, -1 - dislike, 0 - neutral)

  • count (int, default: 10 ) –

    number of recommended videos

Returns:

  • list[UUID]

    UUIDs of recommended videos

Source code in src/rutube_cold_start/main.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def recommend(
    interaction_history: list[tuple[UUID, int]],
    count: int = 10,
) -> list[UUID]:
    """
        Synchronously predict the best recommendations for given ``interaction_history``

        Args:
            interaction_history: list of ``(UUID, int)`` pairs, where ``UUID`` is the video id,
                and ``int`` is the reaction (``1`` - like, ``-1`` - dislike, ``0`` - neutral)
            count: number of recommended videos

        Returns:
            UUIDs of recommended videos
    """
    interaction_history = [(str(pair[0]), pair[1]) for pair in interaction_history]

    recommendations = get_all_interests(full_video_df, interaction_history, count)

    return [UUID(recommendation) for recommendation in recommendations]

recommend_async(interaction_history: list[tuple[UUID, int]], count: int = 10) -> list[UUID] async

Asynchronous wrapper around the recommend function

Parameters:

  • interaction_history (list[tuple[UUID, int]]) –

    list of (UUID, int) pairs, where UUID is the video id, and int is the reaction (1 - like, -1 - dislike, 0 - neutral)

  • count (int, default: 10 ) –

    number of recommended videos

Returns:

  • list[UUID]

    UUIDs of recommended videos

Source code in src/rutube_cold_start/main.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
async def recommend_async(
    interaction_history: list[tuple[UUID, int]],
    count: int = 10,
) -> list[UUID]:
    """
        Asynchronous wrapper around the ``recommend`` function

        Args:
            interaction_history: list of ``(UUID, int)`` pairs, where ``UUID`` is the video id,
                and ``int`` is the reaction (``1`` - like, ``-1`` - dislike, ``0`` - neutral)
            count: number of recommended videos

        Returns:
            UUIDs of recommended videos
    """
    return await asyncio.to_thread(recommend, interaction_history, count)