|
81 | 81 | }, |
82 | 82 | { |
83 | 83 | "cell_type": "code", |
84 | | - "execution_count": 1, |
| 84 | + "execution_count": 3, |
85 | 85 | "metadata": {}, |
86 | 86 | "outputs": [], |
87 | 87 | "source": [ |
|
126 | 126 | }, |
127 | 127 | { |
128 | 128 | "cell_type": "code", |
129 | | - "execution_count": 2, |
| 129 | + "execution_count": 4, |
130 | 130 | "metadata": {}, |
131 | 131 | "outputs": [], |
132 | 132 | "source": [ |
|
178 | 178 | }, |
179 | 179 | { |
180 | 180 | "cell_type": "code", |
181 | | - "execution_count": 3, |
| 181 | + "execution_count": 5, |
182 | 182 | "metadata": {}, |
183 | 183 | "outputs": [], |
184 | 184 | "source": [ |
|
195 | 195 | "Now we also need to facilitate a Redis connection. There are a few ways to do this:\n", |
196 | 196 | "\n", |
197 | 197 | "- Create & manage your own client connection (recommended)\n", |
198 | | - "- Provide a simple Redis URL and let RedisVL connect on your behalf" |
| 198 | + "- Provide a Redis URL and let RedisVL connect on your behalf (by default, it will connect to \"redis://localhost:6379\")" |
199 | 199 | ] |
200 | 200 | }, |
201 | 201 | { |
|
209 | 209 | }, |
210 | 210 | { |
211 | 211 | "cell_type": "code", |
212 | | - "execution_count": 4, |
| 212 | + "execution_count": 6, |
213 | 213 | "metadata": {}, |
214 | 214 | "outputs": [ |
215 | 215 | { |
|
227 | 227 | "from redis import Redis\n", |
228 | 228 | "\n", |
229 | 229 | "client = Redis.from_url(\"redis://localhost:6379\")\n", |
| 230 | + "index = SearchIndex.from_dict(schema, redis_client=client)\n", |
230 | 231 | "\n", |
231 | | - "index.set_client(client)\n", |
232 | | - "# optionally provide an async Redis client object to enable async index operations" |
| 232 | + "# alternatively, provide an async Redis client object to enable async index operations\n", |
| 233 | + "# from redis.asyncio import Redis\n", |
| 234 | + "# from redisvl.index import AsyncSearchIndex\n", |
| 235 | + "# client = Redis.from_url(\"redis://localhost:6379\")\n", |
| 236 | + "# index = AsyncSearchIndex.from_dict(schema, redis_client=client)\n" |
233 | 237 | ] |
234 | 238 | }, |
235 | 239 | { |
|
243 | 247 | }, |
244 | 248 | { |
245 | 249 | "cell_type": "code", |
246 | | - "execution_count": 5, |
| 250 | + "execution_count": 7, |
247 | 251 | "metadata": {}, |
248 | 252 | "outputs": [ |
249 | 253 | { |
|
258 | 262 | } |
259 | 263 | ], |
260 | 264 | "source": [ |
261 | | - "index.connect(\"redis://localhost:6379\")\n", |
262 | | - "# optionally use an async client by passing use_async=True" |
| 265 | + "index = SearchIndex.from_dict(schema, redis_url=\"redis://localhost:6379\")\n", |
| 266 | + "\n", |
| 267 | + "# If you don't specify a client or Redis URL, the index will attempt to\n", |
| 268 | + "# connect to Redis at the default address (\"redis://localhost:6379\")." |
263 | 269 | ] |
264 | 270 | }, |
265 | 271 | { |
|
273 | 279 | }, |
274 | 280 | { |
275 | 281 | "cell_type": "code", |
276 | | - "execution_count": 6, |
| 282 | + "execution_count": 8, |
277 | 283 | "metadata": {}, |
278 | 284 | "outputs": [], |
279 | 285 | "source": [ |
|
297 | 303 | }, |
298 | 304 | { |
299 | 305 | "cell_type": "code", |
300 | | - "execution_count": 7, |
| 306 | + "execution_count": 9, |
301 | 307 | "metadata": {}, |
302 | 308 | "outputs": [ |
303 | 309 | { |
|
315 | 321 | }, |
316 | 322 | { |
317 | 323 | "cell_type": "code", |
318 | | - "execution_count": 8, |
| 324 | + "execution_count": 10, |
319 | 325 | "metadata": {}, |
320 | 326 | "outputs": [ |
321 | 327 | { |
|
358 | 364 | }, |
359 | 365 | { |
360 | 366 | "cell_type": "code", |
361 | | - "execution_count": 9, |
| 367 | + "execution_count": 11, |
362 | 368 | "metadata": {}, |
363 | 369 | "outputs": [ |
364 | 370 | { |
|
392 | 398 | }, |
393 | 399 | { |
394 | 400 | "cell_type": "code", |
395 | | - "execution_count": 10, |
| 401 | + "execution_count": 12, |
396 | 402 | "metadata": {}, |
397 | 403 | "outputs": [ |
398 | 404 | { |
|
429 | 435 | }, |
430 | 436 | { |
431 | 437 | "cell_type": "code", |
432 | | - "execution_count": 11, |
| 438 | + "execution_count": 13, |
433 | 439 | "metadata": {}, |
434 | 440 | "outputs": [], |
435 | 441 | "source": [ |
|
454 | 460 | }, |
455 | 461 | { |
456 | 462 | "cell_type": "code", |
457 | | - "execution_count": 12, |
| 463 | + "execution_count": 14, |
458 | 464 | "metadata": {}, |
459 | 465 | "outputs": [ |
| 466 | + { |
| 467 | + "name": "stdout", |
| 468 | + "output_type": "stream", |
| 469 | + "text": [ |
| 470 | + "*=>[KNN 3 @user_embedding $vector AS vector_distance] RETURN 6 user age job credit_score vector_distance vector_distance SORTBY vector_distance ASC DIALECT 2 LIMIT 0 3\n" |
| 471 | + ] |
| 472 | + }, |
460 | 473 | { |
461 | 474 | "data": { |
462 | 475 | "text/html": [ |
463 | | - "<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>" |
| 476 | + "table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>" |
464 | 477 | ], |
465 | 478 | "text/plain": [ |
466 | 479 | "<IPython.core.display.HTML object>" |
|
487 | 500 | }, |
488 | 501 | { |
489 | 502 | "cell_type": "code", |
490 | | - "execution_count": 13, |
| 503 | + "execution_count": 15, |
491 | 504 | "metadata": {}, |
492 | 505 | "outputs": [ |
493 | 506 | { |
|
537 | 550 | "\n", |
538 | 551 | "client = Redis.from_url(\"redis://localhost:6379\")\n", |
539 | 552 | "\n", |
540 | | - "index = AsyncSearchIndex.from_dict(schema)\n", |
541 | | - "await index.set_client(client)" |
| 553 | + "index = AsyncSearchIndex.from_dict(schema, redis_client=client)" |
542 | 554 | ] |
543 | 555 | }, |
544 | 556 | { |
545 | 557 | "cell_type": "code", |
546 | | - "execution_count": 15, |
| 558 | + "execution_count": 16, |
547 | 559 | "metadata": {}, |
548 | 560 | "outputs": [ |
549 | 561 | { |
|
584 | 596 | }, |
585 | 597 | { |
586 | 598 | "cell_type": "code", |
587 | | - "execution_count": 16, |
| 599 | + "execution_count": 17, |
588 | 600 | "metadata": {}, |
589 | 601 | "outputs": [], |
590 | 602 | "source": [ |
|
609 | 621 | }, |
610 | 622 | { |
611 | 623 | "cell_type": "code", |
612 | | - "execution_count": 16, |
| 624 | + "execution_count": 18, |
613 | 625 | "metadata": {}, |
614 | 626 | "outputs": [ |
615 | 627 | { |
616 | 628 | "name": "stdout", |
617 | 629 | "output_type": "stream", |
618 | 630 | "text": [ |
619 | | - "11:53:25 redisvl.index.index INFO Index already exists, overwriting.\n" |
| 631 | + "11:28:32 redisvl.index.index INFO Index already exists, overwriting.\n" |
620 | 632 | ] |
621 | 633 | } |
622 | 634 | ], |
|
627 | 639 | }, |
628 | 640 | { |
629 | 641 | "cell_type": "code", |
630 | | - "execution_count": 17, |
| 642 | + "execution_count": 19, |
631 | 643 | "metadata": {}, |
632 | 644 | "outputs": [ |
633 | 645 | { |
634 | 646 | "data": { |
635 | 647 | "text/html": [ |
636 | | - "<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>" |
| 648 | + "<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>" |
637 | 649 | ], |
638 | 650 | "text/plain": [ |
639 | 651 | "<IPython.core.display.HTML object>" |
|
659 | 671 | }, |
660 | 672 | { |
661 | 673 | "cell_type": "code", |
662 | | - "execution_count": 18, |
| 674 | + "execution_count": 20, |
663 | 675 | "metadata": {}, |
664 | 676 | "outputs": [ |
665 | 677 | { |
|
677 | 689 | "│ num_records │ 22 │\n", |
678 | 690 | "│ percent_indexed │ 1 │\n", |
679 | 691 | "│ hash_indexing_failures │ 0 │\n", |
680 | | - "│ number_of_uses │ 5 │\n", |
681 | | - "│ bytes_per_record_avg │ 50.9091 │\n", |
| 692 | + "│ number_of_uses │ 2 │\n", |
| 693 | + "│ bytes_per_record_avg │ 47.8 │\n", |
682 | 694 | "│ doc_table_size_mb │ 0.000423431 │\n", |
683 | | - "│ inverted_sz_mb │ 0.00106812 │\n", |
| 695 | + "│ inverted_sz_mb │ 0.000911713 │\n", |
684 | 696 | "│ key_table_size_mb │ 0.000165939 │\n", |
685 | | - "│ offset_bits_per_record_avg │ 8 │\n", |
686 | | - "│ offset_vectors_sz_mb │ 5.72205e-06 │\n", |
687 | | - "│ offsets_per_term_avg │ 0.272727 │\n", |
688 | | - "│ records_per_doc_avg │ 5.5 │\n", |
| 697 | + "│ offset_bits_per_record_avg │ nan │\n", |
| 698 | + "│ offset_vectors_sz_mb │ 0 │\n", |
| 699 | + "│ offsets_per_term_avg │ 0 │\n", |
| 700 | + "│ records_per_doc_avg │ 5 │\n", |
689 | 701 | "│ sortable_values_size_mb │ 0 │\n", |
690 | | - "│ total_indexing_time │ 0.197 │\n", |
691 | | - "│ total_inverted_index_blocks │ 12 │\n", |
692 | | - "│ vector_index_sz_mb │ 0.0201416 │\n", |
| 702 | + "│ total_indexing_time │ 0.239 │\n", |
| 703 | + "│ total_inverted_index_blocks │ 11 │\n", |
| 704 | + "│ vector_index_sz_mb │ 0.235603 │\n", |
693 | 705 | "╰─────────────────────────────┴─────────────╯\n" |
694 | 706 | ] |
695 | 707 | } |
|
718 | 730 | }, |
719 | 731 | { |
720 | 732 | "cell_type": "code", |
721 | | - "execution_count": 19, |
| 733 | + "execution_count": 21, |
722 | 734 | "metadata": {}, |
723 | 735 | "outputs": [ |
724 | 736 | { |
|
727 | 739 | "4" |
728 | 740 | ] |
729 | 741 | }, |
730 | | - "execution_count": 19, |
| 742 | + "execution_count": 21, |
731 | 743 | "metadata": {}, |
732 | 744 | "output_type": "execute_result" |
733 | 745 | } |
|
739 | 751 | }, |
740 | 752 | { |
741 | 753 | "cell_type": "code", |
742 | | - "execution_count": 20, |
| 754 | + "execution_count": 22, |
743 | 755 | "metadata": {}, |
744 | 756 | "outputs": [ |
745 | 757 | { |
|
748 | 760 | "True" |
749 | 761 | ] |
750 | 762 | }, |
751 | | - "execution_count": 20, |
| 763 | + "execution_count": 22, |
752 | 764 | "metadata": {}, |
753 | 765 | "output_type": "execute_result" |
754 | 766 | } |
|
760 | 772 | }, |
761 | 773 | { |
762 | 774 | "cell_type": "code", |
763 | | - "execution_count": 21, |
| 775 | + "execution_count": 23, |
764 | 776 | "metadata": {}, |
765 | 777 | "outputs": [], |
766 | 778 | "source": [ |
|
771 | 783 | ], |
772 | 784 | "metadata": { |
773 | 785 | "kernelspec": { |
774 | | - "display_name": "Python 3", |
| 786 | + "display_name": "env", |
775 | 787 | "language": "python", |
776 | 788 | "name": "python3" |
777 | 789 | }, |
|
0 commit comments