|
477 | 477 | "source": [ |
478 | 478 | "## 3. Document Management (Using LangChain)\n", |
479 | 479 | "\n", |
480 | | - "Here, we'll use **LangChain** for document loading, chunking, and vectorizing. Then,. we’ll **store documents** in Redis as JSON. Each document will look like:\n", |
| 480 | + "Here, we'll use **LangChain** for document loading, chunking, and vectorizing. Then, we’ll **store documents** in Redis as JSON. Each document will look like:\n", |
481 | 481 | "\n", |
482 | 482 | "```json\n", |
483 | 483 | "{\n", |
|
492 | 492 | "```" |
493 | 493 | ] |
494 | 494 | }, |
495 | | - { |
496 | | - "cell_type": "markdown", |
497 | | - "id": "0429e94c", |
498 | | - "metadata": { |
499 | | - "id": "0429e94c" |
500 | | - }, |
501 | | - "source": [ |
502 | | - "### Redis doc index creation\n", |
503 | | - "Below we use RedisVL to prepare a search index where we will load our docs." |
504 | | - ] |
505 | | - }, |
506 | | - { |
507 | | - "cell_type": "code", |
508 | | - "execution_count": 9, |
509 | | - "id": "b33c23e0", |
510 | | - "metadata": { |
511 | | - "id": "b33c23e0" |
512 | | - }, |
513 | | - "outputs": [], |
514 | | - "source": [ |
515 | | - "from redisvl.index import SearchIndex\n", |
516 | | - "from redisvl.schema import IndexSchema\n", |
517 | | - "\n", |
518 | | - "\n", |
519 | | - "schema = IndexSchema.from_dict({\n", |
520 | | - " \"index\": {\n", |
521 | | - " \"name\": \"docs\",\n", |
522 | | - " \"prefix\": \"doc\",\n", |
523 | | - " \"storage_type\": \"json\"\n", |
524 | | - " },\n", |
525 | | - " \"fields\": [\n", |
526 | | - " {\n", |
527 | | - " \"name\": \"doc_id\",\n", |
528 | | - " \"type\": \"tag\",\n", |
529 | | - " },\n", |
530 | | - " {\n", |
531 | | - " \"name\": \"chunk_id\",\n", |
532 | | - " \"type\": \"tag\",\n", |
533 | | - " },\n", |
534 | | - " {\n", |
535 | | - " \"name\": \"allowed_roles\",\n", |
536 | | - " \"path\": \"$.allowed_roles[*]\",\n", |
537 | | - " \"type\": \"tag\",\n", |
538 | | - " },\n", |
539 | | - " {\n", |
540 | | - " \"name\": \"content\",\n", |
541 | | - " \"type\": \"text\",\n", |
542 | | - " },\n", |
543 | | - " {\n", |
544 | | - " \"name\": \"embedding\",\n", |
545 | | - " \"type\": \"vector\",\n", |
546 | | - " \"attrs\": {\n", |
547 | | - " \"dims\": 768,\n", |
548 | | - " \"distance_metric\": \"cosine\",\n", |
549 | | - " \"algorithm\": \"flat\",\n", |
550 | | - " \"datatype\": \"float32\"\n", |
551 | | - " }\n", |
552 | | - " }\n", |
553 | | - " ]\n", |
554 | | - "})\n", |
555 | | - "\n", |
556 | | - "\n", |
557 | | - "index = SearchIndex(schema, redis_client=redis_client)\n", |
558 | | - "index.create(overwrite=True, drop=False)" |
559 | | - ] |
560 | | - }, |
561 | 495 | { |
562 | 496 | "cell_type": "markdown", |
563 | 497 | "id": "d3cJ5DSP5vXt", |
|
742 | 676 | " )\n", |
743 | 677 | " )\n", |
744 | 678 | " \n", |
745 | | - " return results\n" |
| 679 | + " return results" |
746 | 680 | ] |
747 | 681 | }, |
748 | 682 | { |
|
824 | 758 | " 4. Return top-K results.\n", |
825 | 759 | " \"\"\"\n", |
826 | 760 | " # 1. Load & validate user roles\n", |
827 | | - " user_obj = User.get(index.client, user_id)\n", |
| 761 | + " user_obj = User.get(redis_client, user_id)\n", |
828 | 762 | " if not user_obj:\n", |
829 | 763 | " raise ValueError(f\"User {user_id} not found.\")\n", |
830 | 764 | "\n", |
|
0 commit comments