|
32 | 32 | },
|
33 | 33 | {
|
34 | 34 | "cell_type": "code",
|
35 |
| - "execution_count": 27, |
| 35 | + "execution_count": 56, |
36 | 36 | "metadata": {},
|
37 | 37 | "outputs": [],
|
38 | 38 | "source": [
|
|
88 | 88 | },
|
89 | 89 | {
|
90 | 90 | "cell_type": "code",
|
91 |
| - "execution_count": 28, |
| 91 | + "execution_count": 57, |
92 | 92 | "metadata": {},
|
93 | 93 | "outputs": [],
|
94 | 94 | "source": [
|
|
110 | 110 | },
|
111 | 111 | {
|
112 | 112 | "cell_type": "code",
|
113 |
| - "execution_count": 3, |
| 113 | + "execution_count": 63, |
114 | 114 | "metadata": {},
|
115 | 115 | "outputs": [
|
116 | 116 | {
|
|
142 | 142 | "!rvl index info -i topic-router"
|
143 | 143 | ]
|
144 | 144 | },
|
| 145 | + { |
| 146 | + "cell_type": "code", |
| 147 | + "execution_count": 64, |
| 148 | + "metadata": {}, |
| 149 | + "outputs": [ |
| 150 | + { |
| 151 | + "data": { |
| 152 | + "text/plain": [ |
| 153 | + "11" |
| 154 | + ] |
| 155 | + }, |
| 156 | + "execution_count": 64, |
| 157 | + "metadata": {}, |
| 158 | + "output_type": "execute_result" |
| 159 | + } |
| 160 | + ], |
| 161 | + "source": [ |
| 162 | + "router._index.info()[\"num_docs\"]" |
| 163 | + ] |
| 164 | + }, |
145 | 165 | {
|
146 | 166 | "cell_type": "markdown",
|
147 | 167 | "metadata": {},
|
|
421 | 441 | "router.add_route_references(route_name=\"technology\", references=[\"latest AI trends\", \"new tech gadgets\"])"
|
422 | 442 | ]
|
423 | 443 | },
|
424 |
| - { |
425 |
| - "cell_type": "markdown", |
426 |
| - "metadata": {}, |
427 |
| - "source": [ |
428 |
| - "# Add references without re-instantiating\n", |
429 |
| - "\n", |
430 |
| - "If you don't have access to the initial object you can also connect to the index as a class method." |
431 |
| - ] |
432 |
| - }, |
433 |
| - { |
434 |
| - "cell_type": "code", |
435 |
| - "execution_count": 46, |
436 |
| - "metadata": {}, |
437 |
| - "outputs": [ |
438 |
| - { |
439 |
| - "data": { |
440 |
| - "text/plain": [ |
441 |
| - "['topic-router:sports:cf0ff6d4ee9bf4845d64aedbd3df5d0d47deb97d96c6dbddde3ac8422c107bb3']" |
442 |
| - ] |
443 |
| - }, |
444 |
| - "execution_count": 46, |
445 |
| - "metadata": {}, |
446 |
| - "output_type": "execute_result" |
447 |
| - } |
448 |
| - ], |
449 |
| - "source": [ |
450 |
| - "from redisvl.extensions.router import SemanticRouter\n", |
451 |
| - "from redisvl.utils.vectorize import HFTextVectorizer\n", |
452 |
| - "\n", |
453 |
| - "SemanticRouter.add_route_references(\n", |
454 |
| - " router_name=\"topic-router\",\n", |
455 |
| - " vectorizer=HFTextVectorizer(),\n", |
456 |
| - " redis_url=\"redis://localhost:6379\",\n", |
457 |
| - " route_name=\"sports\",\n", |
458 |
| - " references=[\"Lamelo ball charlotte hornets\"],\n", |
459 |
| - ")" |
460 |
| - ] |
461 |
| - }, |
462 | 444 | {
|
463 | 445 | "cell_type": "markdown",
|
464 | 446 | "metadata": {},
|
|
524 | 506 | "refs"
|
525 | 507 | ]
|
526 | 508 | },
|
527 |
| - { |
528 |
| - "cell_type": "markdown", |
529 |
| - "metadata": {}, |
530 |
| - "source": [ |
531 |
| - "# Get reference without re-instantiating" |
532 |
| - ] |
533 |
| - }, |
534 |
| - { |
535 |
| - "cell_type": "code", |
536 |
| - "execution_count": 49, |
537 |
| - "metadata": {}, |
538 |
| - "outputs": [ |
539 |
| - { |
540 |
| - "data": { |
541 |
| - "text/plain": [ |
542 |
| - "[{'id': 'topic-router:sports:e203d270698c8fd4a49e0d21c7e5f0d521c29117d30e798caea7f05d8642203f',\n", |
543 |
| - " 'reference_id': 'e203d270698c8fd4a49e0d21c7e5f0d521c29117d30e798caea7f05d8642203f',\n", |
544 |
| - " 'route_name': 'sports',\n", |
545 |
| - " 'reference': 'who won the game last night?'},\n", |
546 |
| - " {'id': 'topic-router:sports:0ab39eac7ae994eb43da81a4f5c657e4da13c45aed66dee61860d19be6426a3a',\n", |
547 |
| - " 'reference_id': '0ab39eac7ae994eb43da81a4f5c657e4da13c45aed66dee61860d19be6426a3a',\n", |
548 |
| - " 'route_name': 'sports',\n", |
549 |
| - " 'reference': \"what's the latest in the world of sports?\"},\n", |
550 |
| - " {'id': 'topic-router:sports:cf0ff6d4ee9bf4845d64aedbd3df5d0d47deb97d96c6dbddde3ac8422c107bb3',\n", |
551 |
| - " 'reference_id': 'cf0ff6d4ee9bf4845d64aedbd3df5d0d47deb97d96c6dbddde3ac8422c107bb3',\n", |
552 |
| - " 'route_name': 'sports',\n", |
553 |
| - " 'reference': 'Lamelo ball charlotte hornets'},\n", |
554 |
| - " {'id': 'topic-router:sports:b590e928dd8b00bdac89eac0f23b62a5b5984e91a4bdfffb65f6fbf0341fc914',\n", |
555 |
| - " 'reference_id': 'b590e928dd8b00bdac89eac0f23b62a5b5984e91a4bdfffb65f6fbf0341fc914',\n", |
556 |
| - " 'route_name': 'sports',\n", |
557 |
| - " 'reference': 'tell me about the upcoming sports events'},\n", |
558 |
| - " {'id': 'topic-router:sports:1cb542228c76558789d114d3cb273a75850cca54ec3ee9a41100f2dc56ee561e',\n", |
559 |
| - " 'reference_id': '1cb542228c76558789d114d3cb273a75850cca54ec3ee9a41100f2dc56ee561e',\n", |
560 |
| - " 'route_name': 'sports',\n", |
561 |
| - " 'reference': 'sports'},\n", |
562 |
| - " {'id': 'topic-router:sports:f04652c202be48fc02a6dd2e90488f5eeff611339d62bf78d482870b64d82038',\n", |
563 |
| - " 'reference_id': 'f04652c202be48fc02a6dd2e90488f5eeff611339d62bf78d482870b64d82038',\n", |
564 |
| - " 'route_name': 'sports',\n", |
565 |
| - " 'reference': 'basketball and football'}]" |
566 |
| - ] |
567 |
| - }, |
568 |
| - "execution_count": 49, |
569 |
| - "metadata": {}, |
570 |
| - "output_type": "execute_result" |
571 |
| - } |
572 |
| - ], |
573 |
| - "source": [ |
574 |
| - "# by route name\n", |
575 |
| - "refs = SemanticRouter.get_route_references(\n", |
576 |
| - " router_name=\"topic-router\",\n", |
577 |
| - " redis_url=\"redis://localhost:6379\",\n", |
578 |
| - " route_name=\"sports\",\n", |
579 |
| - ")\n", |
580 |
| - "refs" |
581 |
| - ] |
582 |
| - }, |
583 |
| - { |
584 |
| - "cell_type": "code", |
585 |
| - "execution_count": 50, |
586 |
| - "metadata": {}, |
587 |
| - "outputs": [ |
588 |
| - { |
589 |
| - "data": { |
590 |
| - "text/plain": [ |
591 |
| - "[{'id': 'topic-router:sports:e203d270698c8fd4a49e0d21c7e5f0d521c29117d30e798caea7f05d8642203f',\n", |
592 |
| - " 'reference_id': 'e203d270698c8fd4a49e0d21c7e5f0d521c29117d30e798caea7f05d8642203f',\n", |
593 |
| - " 'route_name': 'sports',\n", |
594 |
| - " 'reference': 'who won the game last night?'}]" |
595 |
| - ] |
596 |
| - }, |
597 |
| - "execution_count": 50, |
598 |
| - "metadata": {}, |
599 |
| - "output_type": "execute_result" |
600 |
| - } |
601 |
| - ], |
602 |
| - "source": [ |
603 |
| - "# by reference id\n", |
604 |
| - "refs = SemanticRouter.get_route_references(\n", |
605 |
| - " router_name=\"topic-router\",\n", |
606 |
| - " redis_url=\"redis://localhost:6379\",\n", |
607 |
| - " reference_ids=[refs[0][\"reference_id\"]]\n", |
608 |
| - ")\n", |
609 |
| - "refs" |
610 |
| - ] |
611 |
| - }, |
612 | 509 | {
|
613 | 510 | "cell_type": "markdown",
|
614 | 511 | "metadata": {},
|
|
660 | 557 | "deleted_count"
|
661 | 558 | ]
|
662 | 559 | },
|
663 |
| - { |
664 |
| - "cell_type": "markdown", |
665 |
| - "metadata": {}, |
666 |
| - "source": [ |
667 |
| - "# Delete without re-instantiating" |
668 |
| - ] |
669 |
| - }, |
670 |
| - { |
671 |
| - "cell_type": "code", |
672 |
| - "execution_count": 53, |
673 |
| - "metadata": {}, |
674 |
| - "outputs": [ |
675 |
| - { |
676 |
| - "data": { |
677 |
| - "text/plain": [ |
678 |
| - "5" |
679 |
| - ] |
680 |
| - }, |
681 |
| - "execution_count": 53, |
682 |
| - "metadata": {}, |
683 |
| - "output_type": "execute_result" |
684 |
| - } |
685 |
| - ], |
686 |
| - "source": [ |
687 |
| - "deleted_count = SemanticRouter.delete_route_references(\n", |
688 |
| - " route_name=\"sports\",\n", |
689 |
| - " redis_url=\"redis://localhost:6379\",\n", |
690 |
| - " router_name=\"topic-router\"\n", |
691 |
| - ")\n", |
692 |
| - "deleted_count" |
693 |
| - ] |
694 |
| - }, |
695 | 560 | {
|
696 | 561 | "cell_type": "markdown",
|
697 | 562 | "metadata": {},
|
|
0 commit comments