|
121 | 121 | ] |
122 | 122 | }, |
123 | 123 | { |
124 | | - "cell_type": "markdown", |
125 | 124 | "metadata": {}, |
| 125 | + "cell_type": "markdown", |
126 | 126 | "source": [ |
127 | | - "### Install Redis Stack\n", |
| 127 | + "### Install Redis\n", |
128 | 128 | "\n", |
129 | 129 | "Later in this tutorial, Redis will be used to store, index, and query vector\n", |
130 | 130 | "embeddings and full text fields. **We need to have a Redis\n", |
131 | 131 | "instance available.**\n", |
132 | 132 | "\n", |
133 | 133 | "#### Local Redis\n", |
134 | | - "Use the shell script below to download, extract, and install [Redis Stack](https://redis.io/docs/getting-started/install-stack/) directly from the Redis package archive." |
| 134 | + "Use the shell script below to download, extract, and install [Redis](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/apt/) directly from the Redis package archive for a Linux environment." |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | { |
138 | | - "cell_type": "code", |
139 | | - "execution_count": null, |
140 | 138 | "metadata": {}, |
| 139 | + "cell_type": "code", |
141 | 140 | "outputs": [], |
| 141 | + "execution_count": 20, |
142 | 142 | "source": [ |
143 | 143 | "# NBVAL_SKIP\n", |
144 | 144 | "%%sh\n", |
| 145 | + "sudo apt-get install lsb-release curl gpg\n", |
145 | 146 | "curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg\n", |
| 147 | + "sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg\n", |
146 | 148 | "echo \"deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main\" | sudo tee /etc/apt/sources.list.d/redis.list\n", |
147 | | - "sudo apt-get update > /dev/null 2>&1\n", |
148 | | - "sudo apt-get install redis-stack-server > /dev/null 2>&1\n", |
149 | | - "redis-stack-server --daemonize yes" |
| 149 | + "sudo apt-get update\n", |
| 150 | + "sudo apt-get install redis\n", |
| 151 | + "\n", |
| 152 | + "redis-server --version\n", |
| 153 | + "redis-server --daemonize yes --loadmodule /usr/lib/redis/modules/redisearch.so" |
150 | 154 | ] |
151 | 155 | }, |
152 | 156 | { |
153 | | - "cell_type": "markdown", |
154 | 157 | "metadata": {}, |
| 158 | + "cell_type": "markdown", |
155 | 159 | "source": [ |
156 | 160 | "#### Alternative Redis Access (Cloud, Docker, other)\n", |
157 | 161 | "There are many ways to get the necessary redis-stack instance running\n", |
158 | 162 | "1. On cloud, deploy a [FREE instance of Redis in the cloud](https://redis.com/try-free/). Or, if you have your\n", |
159 | 163 | "own version of Redis Enterprise running, that works too!\n", |
160 | 164 | "2. Per OS, [see the docs](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/)\n", |
161 | | - "3. With docker: `docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest`" |
| 165 | + "3. With docker: `docker run -d --name redis -p 6379:6379 redis:latest`" |
162 | 166 | ] |
163 | 167 | }, |
164 | 168 | { |
|
172 | 176 | }, |
173 | 177 | { |
174 | 178 | "cell_type": "code", |
175 | | - "execution_count": null, |
176 | | - "metadata": {}, |
177 | | - "outputs": [], |
| 179 | + "metadata": { |
| 180 | + "ExecuteTime": { |
| 181 | + "end_time": "2025-12-09T15:24:43.601826Z", |
| 182 | + "start_time": "2025-12-09T15:24:43.599178Z" |
| 183 | + } |
| 184 | + }, |
178 | 185 | "source": [ |
179 | 186 | "import os\n", |
180 | 187 | "\n", |
|
185 | 192 | "\n", |
186 | 193 | "# If SSL is enabled on the endpoint, use rediss:// as the URL prefix\n", |
187 | 194 | "REDIS_URL = f\"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}\"" |
188 | | - ] |
| 195 | + ], |
| 196 | + "outputs": [], |
| 197 | + "execution_count": 1 |
189 | 198 | }, |
190 | 199 | { |
191 | 200 | "cell_type": "markdown", |
|
196 | 205 | }, |
197 | 206 | { |
198 | 207 | "cell_type": "code", |
199 | | - "execution_count": 3, |
200 | | - "metadata": {}, |
| 208 | + "metadata": { |
| 209 | + "ExecuteTime": { |
| 210 | + "end_time": "2025-12-09T15:24:45.636539Z", |
| 211 | + "start_time": "2025-12-09T15:24:45.602099Z" |
| 212 | + } |
| 213 | + }, |
| 214 | + "source": [ |
| 215 | + "from redis import Redis\n", |
| 216 | + "\n", |
| 217 | + "client = Redis.from_url(REDIS_URL)\n", |
| 218 | + "client.ping()" |
| 219 | + ], |
201 | 220 | "outputs": [ |
202 | 221 | { |
203 | 222 | "data": { |
204 | 223 | "text/plain": [ |
205 | 224 | "True" |
206 | 225 | ] |
207 | 226 | }, |
208 | | - "execution_count": 3, |
| 227 | + "execution_count": 2, |
209 | 228 | "metadata": {}, |
210 | 229 | "output_type": "execute_result" |
211 | 230 | } |
212 | 231 | ], |
213 | | - "source": [ |
214 | | - "from redis import Redis\n", |
215 | | - "\n", |
216 | | - "client = Redis.from_url(REDIS_URL)\n", |
217 | | - "client.ping()" |
218 | | - ] |
| 232 | + "execution_count": 2 |
219 | 233 | }, |
220 | 234 | { |
221 | 235 | "cell_type": "code", |
222 | | - "execution_count": 4, |
223 | | - "metadata": {}, |
224 | | - "outputs": [], |
| 236 | + "metadata": { |
| 237 | + "ExecuteTime": { |
| 238 | + "end_time": "2025-12-09T15:24:48.003249Z", |
| 239 | + "start_time": "2025-12-09T15:24:47.998789Z" |
| 240 | + } |
| 241 | + }, |
225 | 242 | "source": [ |
226 | 243 | "import json\n", |
227 | 244 | "\n", |
228 | 245 | "with open(\"resources/movies.json\", 'r') as file:\n", |
229 | 246 | " movies = json.load(file)" |
230 | | - ] |
| 247 | + ], |
| 248 | + "outputs": [], |
| 249 | + "execution_count": 3 |
231 | 250 | }, |
232 | 251 | { |
233 | 252 | "cell_type": "markdown", |
|
246 | 265 | }, |
247 | 266 | { |
248 | 267 | "cell_type": "code", |
249 | | - "execution_count": 5, |
250 | | - "metadata": {}, |
251 | | - "outputs": [ |
252 | | - { |
253 | | - "name": "stdout", |
254 | | - "output_type": "stream", |
255 | | - "text": [ |
256 | | - "14:45:04 datasets INFO PyTorch version 2.3.0 available.\n", |
257 | | - "14:45:05 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
258 | | - "14:45:05 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-MiniLM-L6-v2\n", |
259 | | - "14:45:07 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
260 | | - "14:45:07 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n", |
261 | | - "14:45:08 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
262 | | - "14:45:08 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2\n" |
263 | | - ] |
| 268 | + "metadata": { |
| 269 | + "ExecuteTime": { |
| 270 | + "end_time": "2025-12-09T15:25:17.968696Z", |
| 271 | + "start_time": "2025-12-09T15:24:51.320769Z" |
264 | 272 | } |
265 | | - ], |
| 273 | + }, |
266 | 274 | "source": [ |
267 | 275 | "from redisvl.utils.vectorize import HFTextVectorizer\n", |
268 | 276 | "from redisvl.extensions.cache.embeddings import EmbeddingsCache\n", |
|
299 | 307 | " ),\n", |
300 | 308 | " dtype=\"float32\"\n", |
301 | 309 | ")" |
302 | | - ] |
| 310 | + ], |
| 311 | + "outputs": [ |
| 312 | + { |
| 313 | + "name": "stderr", |
| 314 | + "output_type": "stream", |
| 315 | + "text": [ |
| 316 | + "/Users/vishal.bala/PycharmProjects/redis-ai-resources/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
| 317 | + " from .autonotebook import tqdm as notebook_tqdm\n" |
| 318 | + ] |
| 319 | + }, |
| 320 | + { |
| 321 | + "name": "stdout", |
| 322 | + "output_type": "stream", |
| 323 | + "text": [ |
| 324 | + "16:24:55 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 325 | + "16:24:55 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-MiniLM-L6-v2\n", |
| 326 | + "16:24:58 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 327 | + "16:24:58 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n", |
| 328 | + "16:25:01 sentence_transformers.SentenceTransformer INFO Use pytorch device_name: mps\n", |
| 329 | + "16:25:01 sentence_transformers.SentenceTransformer INFO Load pretrained SentenceTransformer: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2\n" |
| 330 | + ] |
| 331 | + } |
| 332 | + ], |
| 333 | + "execution_count": 4 |
303 | 334 | }, |
304 | 335 | { |
305 | 336 | "cell_type": "markdown", |
|
313 | 344 | }, |
314 | 345 | { |
315 | 346 | "cell_type": "code", |
316 | | - "execution_count": 6, |
317 | | - "metadata": {}, |
318 | | - "outputs": [ |
319 | | - { |
320 | | - "name": "stdout", |
321 | | - "output_type": "stream", |
322 | | - "text": [ |
323 | | - "Generating multiple embeddings for movies...\n", |
324 | | - "Generated embeddings for 20 movies\n" |
325 | | - ] |
| 347 | + "metadata": { |
| 348 | + "ExecuteTime": { |
| 349 | + "end_time": "2025-12-09T15:25:27.857788Z", |
| 350 | + "start_time": "2025-12-09T15:25:24.034106Z" |
326 | 351 | } |
327 | | - ], |
| 352 | + }, |
328 | 353 | "source": [ |
329 | 354 | "# Generate multiple embeddings for each movie\n", |
330 | 355 | "print(\"Generating multiple embeddings for movies...\")\n", |
|
340 | 365 | " multi_vector_movie_data.append(movie_with_vectors)\n", |
341 | 366 | "\n", |
342 | 367 | "print(f\"Generated embeddings for {len(multi_vector_movie_data)} movies\")" |
343 | | - ] |
344 | | - }, |
345 | | - { |
346 | | - "cell_type": "code", |
347 | | - "execution_count": 7, |
348 | | - "metadata": {}, |
| 368 | + ], |
349 | 369 | "outputs": [ |
350 | 370 | { |
351 | 371 | "name": "stdout", |
352 | 372 | "output_type": "stream", |
353 | 373 | "text": [ |
354 | | - "Multi-vector index created and populated successfully!\n" |
| 374 | + "Generating multiple embeddings for movies...\n", |
| 375 | + "Generated embeddings for 20 movies\n" |
355 | 376 | ] |
356 | 377 | } |
357 | 378 | ], |
| 379 | + "execution_count": 5 |
| 380 | + }, |
| 381 | + { |
| 382 | + "cell_type": "code", |
| 383 | + "metadata": { |
| 384 | + "ExecuteTime": { |
| 385 | + "end_time": "2025-12-09T15:25:27.891696Z", |
| 386 | + "start_time": "2025-12-09T15:25:27.864579Z" |
| 387 | + } |
| 388 | + }, |
358 | 389 | "source": [ |
359 | 390 | "from redisvl.schema import IndexSchema\n", |
360 | 391 | "from redisvl.index import SearchIndex\n", |
|
411 | 442 | "# Load the multi-vector data\n", |
412 | 443 | "multi_vector_index.load(multi_vector_movie_data)\n", |
413 | 444 | "print(\"Multi-vector index created and populated successfully!\")" |
414 | | - ] |
| 445 | + ], |
| 446 | + "outputs": [ |
| 447 | + { |
| 448 | + "name": "stdout", |
| 449 | + "output_type": "stream", |
| 450 | + "text": [ |
| 451 | + "Multi-vector index created and populated successfully!\n" |
| 452 | + ] |
| 453 | + } |
| 454 | + ], |
| 455 | + "execution_count": 6 |
415 | 456 | }, |
416 | 457 | { |
417 | 458 | "cell_type": "markdown", |
|
432 | 473 | }, |
433 | 474 | { |
434 | 475 | "cell_type": "code", |
435 | | - "execution_count": 8, |
436 | | - "metadata": {}, |
437 | | - "outputs": [ |
438 | | - { |
439 | | - "name": "stdout", |
440 | | - "output_type": "stream", |
441 | | - "text": [ |
442 | | - "1. The Incredibles \n", |
443 | | - " Genre: comedy, Rating: 8\n", |
444 | | - " Description: A family of undercover superheroes, while trying to live the quiet suburban life, are forced into ac...\n", |
445 | | - "\n", |
446 | | - "2. The Avengers \n", |
447 | | - " Genre: action, Rating: 8\n", |
448 | | - " Description: Earth's mightiest heroes come together to stop an alien invasion that threatens the entire planet....\n", |
449 | | - "\n", |
450 | | - "3. Mad Max: Fury Road \n", |
451 | | - " Genre: action, Rating: 8\n", |
452 | | - " Description: In a post-apocalyptic wasteland, Max teams up with Furiosa to escape a tyrant's clutches and find fr...\n", |
453 | | - "\n", |
454 | | - "4. John Wick \n", |
455 | | - " Genre: action, Rating: 8\n", |
456 | | - " Description: A retired hitman seeks vengeance against those who wronged him, leaving a trail of destruction in hi...\n", |
457 | | - "\n", |
458 | | - "5. The Dark Knight \n", |
459 | | - " Genre: action, Rating: 9\n", |
460 | | - " Description: Batman faces off against the Joker, a criminal mastermind who threatens to plunge Gotham into chaos....\n", |
461 | | - "\n" |
462 | | - ] |
| 476 | + "metadata": { |
| 477 | + "ExecuteTime": { |
| 478 | + "end_time": "2025-12-09T15:25:31.125875Z", |
| 479 | + "start_time": "2025-12-09T15:25:30.346516Z" |
463 | 480 | } |
464 | | - ], |
| 481 | + }, |
465 | 482 | "source": [ |
466 | 483 | "from redisvl.query import Vector, MultiVectorQuery\n", |
467 | 484 | "query_text = \"action movie with superheroes and explosions\"\n", |
|
503 | 520 | " print(f\" Genre: {result['genre']}, Rating: {result['rating']}\")\n", |
504 | 521 | " print(f\" Description: {result['description'][:100]}...\")\n", |
505 | 522 | " print()" |
506 | | - ] |
| 523 | + ], |
| 524 | + "outputs": [ |
| 525 | + { |
| 526 | + "name": "stdout", |
| 527 | + "output_type": "stream", |
| 528 | + "text": [ |
| 529 | + "1. The Incredibles \n", |
| 530 | + " Genre: comedy, Rating: 8\n", |
| 531 | + " Description: A family of undercover superheroes, while trying to live the quiet suburban life, are forced into ac...\n", |
| 532 | + "\n", |
| 533 | + "2. The Avengers \n", |
| 534 | + " Genre: action, Rating: 8\n", |
| 535 | + " Description: Earth's mightiest heroes come together to stop an alien invasion that threatens the entire planet....\n", |
| 536 | + "\n", |
| 537 | + "3. Mad Max: Fury Road \n", |
| 538 | + " Genre: action, Rating: 8\n", |
| 539 | + " Description: In a post-apocalyptic wasteland, Max teams up with Furiosa to escape a tyrant's clutches and find fr...\n", |
| 540 | + "\n", |
| 541 | + "4. John Wick \n", |
| 542 | + " Genre: action, Rating: 8\n", |
| 543 | + " Description: A retired hitman seeks vengeance against those who wronged him, leaving a trail of destruction in hi...\n", |
| 544 | + "\n", |
| 545 | + "5. The Dark Knight \n", |
| 546 | + " Genre: action, Rating: 9\n", |
| 547 | + " Description: Batman faces off against the Joker, a criminal mastermind who threatens to plunge Gotham into chaos....\n", |
| 548 | + "\n" |
| 549 | + ] |
| 550 | + } |
| 551 | + ], |
| 552 | + "execution_count": 7 |
507 | 553 | }, |
508 | 554 | { |
509 | 555 | "cell_type": "markdown", |
|
515 | 561 | }, |
516 | 562 | { |
517 | 563 | "cell_type": "code", |
518 | | - "execution_count": 9, |
519 | | - "metadata": {}, |
520 | | - "outputs": [], |
| 564 | + "metadata": { |
| 565 | + "ExecuteTime": { |
| 566 | + "end_time": "2025-12-09T15:25:33.245401Z", |
| 567 | + "start_time": "2025-12-09T15:25:33.242415Z" |
| 568 | + } |
| 569 | + }, |
521 | 570 | "source": [ |
522 | 571 | "# clean up!\n", |
523 | 572 | "multi_vector_index.delete()" |
524 | | - ] |
| 573 | + ], |
| 574 | + "outputs": [], |
| 575 | + "execution_count": 8 |
525 | 576 | } |
526 | 577 | ], |
527 | 578 | "metadata": { |
|
0 commit comments