|
277 | 277 | " Returns:\n", |
278 | 278 | " List[float]: Embedding of the content as a list.\n", |
279 | 279 | " \"\"\"\n", |
280 | | - " # If an image URL is provided, first load the image\n", |
| 280 | + " # If the input is an image, first load the image content\n", |
281 | 281 | " if mode == \"image\":\n", |
282 | | - " content = Image.open(requests.get(content, stream=True).raw)\n", |
| 282 | + " if content.startswith(\"http\"):\n", |
| 283 | + " content = Image.open(requests.get(content, stream=True).raw)\n", |
| 284 | + " else:\n", |
| 285 | + " content = Image.open(content)\n", |
283 | 286 | " return vo.multimodal_embed(inputs=[[content]], model=\"voyage-multimodal-3\", input_type=input_type).embeddings[0]" |
284 | 287 | ] |
285 | 288 | }, |
|
470 | 473 | "outputs": [], |
471 | 474 | "source": [ |
472 | 475 | "# Test the vector search with a text query\n", |
473 | | - "vector_search(\"A peaceful and uplifting atmosphere\", \"text\")\n", |
| 476 | + "vector_search(\"A man wearing a golden crown\", \"text\")\n", |
474 | 477 | "\n", |
475 | 478 | "# Also try these text queries:\n", |
476 | | - "# - Healthy living and fitness\n", |
477 | | - "# - A man wearing a golden crown\n", |
478 | | - "# - Adorable fluffy creatures\n", |
479 | | - "# - Winning business agreement\n", |
480 | | - "# - A Winter's Tale on a Spanish Isle" |
| 479 | + "# - A rainbow of lively colors\n", |
| 480 | + "# - Creatures wondrous or familiar\n", |
| 481 | + "# - A boy and the ocean\n", |
| 482 | + "# - Houses" |
481 | 483 | ] |
482 | 484 | }, |
483 | 485 | { |
|
490 | 492 | "vector_search(\"https://images.isbndb.com/covers/10835953482746.jpg\", \"image\")\n", |
491 | 493 | "\n", |
492 | 494 | "# Also try these image queries:\n", |
493 | | - "# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/1.png\n", |
494 | | - "# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/2.png\n", |
495 | | - "# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/3.png\n", |
496 | | - "# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/4.png\n", |
497 | | - "# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/5.png" |
| 495 | + "# - ../data/images/salad.jpg\n", |
| 496 | + "# - ../data/images/kitten.png\n", |
| 497 | + "# - ../data/images/barn.png" |
498 | 498 | ] |
499 | 499 | }, |
500 | 500 | { |
|
574 | 574 | "filter = {\"year\": {\"$gte\": 2002}}\n", |
575 | 575 | "# Pass the `filter` as an argument to the `vector_search` function.\n", |
576 | 576 | "# Notice how this filter is incorporated in the `pipeline` in the `vector_search` function.\n", |
577 | | - "vector_search(\"A peaceful and uplifting atmosphere\", \"text\", filter)" |
| 577 | + "vector_search(\"A boy and the ocean\", \"text\", filter)" |
578 | 578 | ] |
579 | 579 | }, |
580 | 580 | { |
|
649 | 649 | "filter = {\"$and\": [{\"year\": {\"$gte\": 2002}}, {\"pages\": {\"$lte\": 250}}]}\n", |
650 | 650 | "# Pass the `filter` as an argument to the `vector_search` function.\n", |
651 | 651 | "# Notice how this filter is incorporated in the `pipeline` in the `vector_search` function.\n", |
652 | | - "vector_search(\"A peaceful and uplifting atmosphere\", \"text\", filter)" |
| 652 | + "vector_search(\"A boy and the ocean\", \"text\", filter)" |
653 | 653 | ] |
654 | 654 | }, |
655 | 655 | { |
|
944 | 944 | "source": [ |
945 | 945 | "# Test the hybrid search query with a weight of 1.0 for vector search and 0.0 for full-text search\n", |
946 | 946 | "hybrid_search(\n", |
947 | | - " user_query=\"A Winter's Tale on a Spanish Isle\",\n", |
| 947 | + " user_query=\"My Favorite Summer\",\n", |
948 | 948 | " vector_weight=1.0,\n", |
949 | 949 | " full_text_weight=0.0,\n", |
950 | 950 | ")" |
|
956 | 956 | "metadata": {}, |
957 | 957 | "outputs": [], |
958 | 958 | "source": [ |
959 | | - "# Test the hybrid search query with a weight of 0.5 for vector search and 0.5 for full-text search\n", |
| 959 | + "# Test the hybrid search query with a weight of 0.3 for vector search and 0.7 for full-text search\n", |
960 | 960 | "hybrid_search(\n", |
961 | | - " user_query=\"A Winter's Tale on a Spanish Isle\",\n", |
962 | | - " vector_weight=0.5,\n", |
963 | | - " full_text_weight=0.5,\n", |
| 961 | + " user_query=\"My Favorite Summer\",\n", |
| 962 | + " vector_weight=0.3,\n", |
| 963 | + " full_text_weight=0.7,\n", |
964 | 964 | ")" |
965 | 965 | ] |
966 | 966 | } |
967 | 967 | ], |
968 | 968 | "metadata": { |
969 | 969 | "kernelspec": { |
970 | | - "display_name": "Python 3", |
| 970 | + "display_name": "base", |
971 | 971 | "language": "python", |
972 | 972 | "name": "python3" |
973 | 973 | }, |
|
981 | 981 | "name": "python", |
982 | 982 | "nbconvert_exporter": "python", |
983 | 983 | "pygments_lexer": "ipython3", |
984 | | - "version": "3.9.6" |
| 984 | + "version": "3.11.6" |
985 | 985 | }, |
986 | 986 | "widgets": { |
987 | 987 | "application/vnd.jupyter.widget-state+json": { |
|
0 commit comments