"
- ],
"text/plain": [
"title 0\n",
"rating 0\n",
@@ -679,22 +411,23 @@
"dtype: int64"
]
},
- "execution_count": 5,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "roman_numerals = ['(I)','(II)','(III)','(IV)', '(V)', '(VI)', '(VII)', '(VIII)', '(IX)', '(XI)', '(XII)', '(XVI)', '(XIV)', '(XXXIII)', '(XVIII)', '(XIX)', '(XXVII)']\n",
+ "import datetime\n",
+ "roman_numerals = ['0','(I)','(II)','(III)','(IV)', '(V)', '(VI)', '(VII)', '(VIII)', '(IX)', '(XI)', '(XII)', '(XVI)', '(XIV)', '(XXXIII)', '(XVIII)', '(XIX)', '(XXVII)']\n",
"\n",
"def replace_year(x):\n",
" if x in roman_numerals:\n",
- " return 1998 # the average year of the dataset\n",
+ " return datetime.datetime(1998, 1, 1).timestamp()\n",
" else:\n",
- " return x\n",
+ " return datetime.datetime(int(x), 1, 1).timestamp()\n",
"\n",
"df.drop(columns=['runtime', 'writer', 'path'], inplace=True)\n",
- "df['year'] = df['year'].apply(replace_year) # replace roman numerals with average year\n",
+ "df['year'] = df['year'].apply(replace_year) # replace roman numerals with average year as a timestamp\n",
"df['genres'] = df['genres'].apply(ast.literal_eval) # convert string representation of list to list\n",
"df['keywords'] = df['keywords'].apply(ast.literal_eval) # convert string representation of list to list\n",
"df['cast'] = df['cast'].apply(ast.literal_eval) # convert string representation of list to list\n",
@@ -730,7 +463,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@@ -742,14 +475,11 @@
"outputs": [
{
"data": {
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "string"
- },
"text/plain": [
"'The Story of the Kelly Gang. Story of Ned Kelly, an infamous 19th-century Australian outlaw. ned kelly, australia, historic figure, australian western, first of its kind, directorial debut, australian history, 19th century, victoria australia, australian'"
]
},
- "execution_count": 6,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -782,7 +512,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 6,
"metadata": {
"id": "Dyxs5dyWy4oQ"
},
@@ -825,11 +555,19 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 7,
"metadata": {
"id": "fzfELmSjy4oR"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\u001b[32m14:50:33\u001b[0m \u001b[34mredisvl.index.index\u001b[0m \u001b[1;30mINFO\u001b[0m Index already exists, overwriting.\n"
+ ]
+ }
+ ],
"source": [
"from redis import Redis\n",
"from redisvl.schema import IndexSchema\n",
@@ -888,7 +626,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 8,
"metadata": {
"id": "Z45nA5Zoy4oR"
},
@@ -913,7 +651,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -926,11 +664,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "{'id': 'movie:345589922cb348a098930568d5e7d02a', 'vector_distance': '0.584869861603', 'title': 'The Odyssey', 'overview': 'The aquatic adventure of the highly influential and fearlessly ambitious pioneer, innovator, filmmaker, researcher, and conservationist, Jacques-Yves Cousteau, covers roughly thirty years of an inarguably rich in achievements life.'}\n",
- "{'id': 'movie:5147986e894d43879f4d90d6ed85dfd0', 'vector_distance': '0.633292078972', 'title': 'The Inventor', 'overview': 'Inventing flying contraptions, war machines and studying cadavers, Leonardo da Vinci tackles the meaning of life itself with the help of French princess Marguerite de Nevarre.'}\n",
- "{'id': 'movie:da53156795ab4026b51e9dde88b02fa6', 'vector_distance': '0.658123493195', 'title': 'Ruin', 'overview': 'The film follows a nameless ex-Nazi captain who navigates the ruins of post-WWII Germany determined to atone for his crimes during the war by hunting down the surviving members of his former SS Death Squad.'}\n",
- "{'id': 'movie:3e14e33c09944a70810aa7e24a2f78ef', 'vector_distance': '0.688094377518', 'title': 'The Raven', 'overview': 'A man with incredible powers is sought by the government and military.'}\n",
- "{'id': 'movie:2a4c39f73e6b49e8b32ea1ce456e5833', 'vector_distance': '0.694671332836', 'title': 'Get the Girl', 'overview': 'Sebastain \"Bash\" Danye, a legendary gun for hire hangs up his weapon to retire peacefully with his \\'it\\'s complicated\\' partner Renee. Their quiet lives are soon interrupted when they find an unconscious woman on their property, Maddie. While nursing her back to health, some bad me... Read all'}\n"
+ "{'id': 'movie:01JR93QQKR98GVEAZ9WEACJCQ2', 'vector_distance': '5.96046447754e-08', 'title': '20,000 Leagues Under the Sea', 'overview': 'A French professor and his daughter accompany Captain Nemo on an adventure aboard a submarine.'}\n",
+ "{'id': 'movie:01JR93QQM22ACE1NAYHMFQZ5JM', 'vector_distance': '0.364912927151', 'title': 'Captain Nemo and the Underwater City', 'overview': 'When Captain Nemo saves the passengers of a sinking ship and takes them to his Utopian underwater city he discovers that not all of his guests agree to remain there forever.'}\n",
+ "{'id': 'movie:01JR93QQKV8CWP07V3MXXX04DD', 'vector_distance': '0.451630234718', 'title': 'Adventures of Captain Fabian', 'overview': 'A sea captain becomes involved with a servant girl in early New Orleans. She sees him as a way to gain access into wealthy households.'}\n",
+ "{'id': 'movie:01JR93QQSA6TMDG5C3555JYJZJ', 'vector_distance': '0.469480991364', 'title': 'Intrigo: Death of an Author', 'overview': 'One solitary man at the rudder in a small open boat ploughs through a troubled sea off the Dutch coast.'}\n",
+ "{'id': 'movie:01JR93QQSD4JRAJNK8MY55KPFD', 'vector_distance': '0.473049581051', 'title': 'Le chant du loup', 'overview': 'In the near future, a French submarine finds itself in a crisis situation.'}\n"
]
}
],
@@ -963,22 +701,22 @@
"\n",
"Production recommender systems often have fields that can be configured. Users can specify if they want to see a romantic comedy or a horror film, or only see new releases.\n",
"\n",
- "Let's go ahead and add this functionality by using the tags we've defined in our schema."
+ "Let's go ahead and add this functionality by using the tags we've defined in our schema. For illustration, we'll use the `Timestamp` filter to show recent films, the `Tag` filter to narrow down the genres, and the `Text` filter to make sure at least one of our keyword search terms is in the description."
]
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 10,
"metadata": {
"id": "wcRNJ4evy4oR"
},
"outputs": [],
"source": [
- "from redisvl.query.filter import Tag, Num, Text\n",
+ "from redisvl.query.filter import Tag, Text, Timestamp\n",
"\n",
"def make_filter(genres=None, release_year=None, keywords=None):\n",
" flexible_filter = (\n",
- " (Num(\"year\") > release_year) & # only show movies released after this year\n",
+ " (Timestamp(\"year\") > datetime.datetime(release_year, 1, 1)) & # only show movies released after this year\n",
" (Tag(\"genres\") == genres) & # only show movies that match at least one in list of genres\n",
" (Text(\"full_text\") % keywords) # only show movies that contain at least one of the keywords\n",
" )\n",
@@ -1013,7 +751,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 11,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -1026,21 +764,21 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "- Wolfman:\n",
- "\t A man becomes afflicted by an ancient curse after he is bitten by a werewolf.\n",
- "\t Genres: [\"Horror\"]\n",
- "- Off Season:\n",
- "\t Tenn's relentless search for his father takes him back to his childhood town only to find a community gripped by fear. As he travels deeper into the bitter winter wilderness of the town he uncovers a dreadful secret buried long ago.\n",
- "\t Genres: [\"Horror\",\"Mystery\",\"Thriller\"]\n",
- "- Pieces:\n",
- "\t The co-eds of a Boston college campus are targeted by a mysterious killer who is creating a human jigsaw puzzle from their body parts.\n",
- "\t Genres: [\"Horror\",\"Mystery\",\"Thriller\"]\n",
- "- Cursed:\n",
- "\t A prominent psychiatrist at a state run hospital wrestles with madness and a dark supernatural force as he and a female police detective race to stop an escaped patient from butchering five people held hostage in a remote mansion.\n",
- "\t Genres: [\"Horror\",\"Thriller\"]\n",
- "- The Home:\n",
- "\t The Home unfolds after a young man is nearly killed during an accident that leaves him physically and emotionally scarred. To recuperate, he is taken to a secluded nursing home where the elderly residents appear to be suffering from delusions. But after witnessing a violent attac... Read all\n",
- "\t Genres: [\"Action\",\"Fantasy\",\"Horror\"]\n"
+ "- The Forsaken:\n",
+ "\t A young man gets embroiled in a war against vampires.\n",
+ "\t Genres: [\"Action\",\"Horror\",\"Thriller\"]\n",
+ "- Shadow of the Vampire:\n",
+ "\t The filming of Nosferatu (1922) is hampered by the fact that its star Max Schreck is taking the role of a vampire far more seriously than seems humanly possible.\n",
+ "\t Genres: [\"Drama\",\"Horror\"]\n",
+ "- Blood and Chocolate:\n",
+ "\t A teenage werewolf is torn between honoring her family's secret and her love for a man.\n",
+ "\t Genres: [\"Drama\",\"Fantasy\",\"Horror\"]\n",
+ "- Queen of the Damned:\n",
+ "\t In this loose sequel to Interview with the Vampire: The Vampire Chronicles (1994), the vampire Lestat becomes a rock star whose music wakes up the equally beautiful and monstrous queen of all vampires.\n",
+ "\t Genres: [\"Drama\",\"Fantasy\",\"Horror\"]\n",
+ "- Stake Land:\n",
+ "\t In a world of vampires, an expert vampire hunter and his young protégé travel toward sanctuary.\n",
+ "\t Genres: [\"Drama\",\"Horror\",\"Sci-Fi\"]\n"
]
}
],
@@ -1067,7 +805,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 12,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -1080,7 +818,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Deleted 143 keys\n"
+ "Deleted 10000 keys\n",
+ "Deleted 7000 keys\n",
+ "Deleted 3500 keys\n",
+ "Deleted 1541 keys\n",
+ "Deleted 1000 keys\n",
+ "Deleted 500 keys\n"
]
}
],
@@ -1110,7 +853,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.11.10"
+ "version": "3.11.9"
}
},
"nbformat": 4,