Skip to content

Commit c3e0f25

Browse files
authored
Merge pull request #24 from mongodb-developer/update-sample-queries
Update sample queries for the vector search lab
2 parents 7f09cc7 + a0b9efe commit c3e0f25

File tree

6 files changed

+43
-43
lines changed

6 files changed

+43
-43
lines changed

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
network_mode: service:mongodb
1515

1616
mongodb:
17-
image: mongodb/mongodb-atlas-local:8.0.3-20250506T093411Z
17+
image: mongodb/mongodb-atlas-local:8.2.0
1818
restart: unless-stopped
1919
volumes:
2020
- mongodb_data:/data/db

data/images/barn.png

68.6 KB
Loading

data/images/kitten.png

334 KB
Loading

data/images/salad.jpg

72.1 KB
Loading

labs/vector-search-lab.ipynb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,12 @@
277277
" Returns:\n",
278278
" List[float]: Embedding of the content as a list.\n",
279279
" \"\"\"\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",
281281
" 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",
283286
" return vo.multimodal_embed(inputs=[[content]], model=\"voyage-multimodal-3\", input_type=input_type).embeddings[0]"
284287
]
285288
},
@@ -458,14 +461,13 @@
458461
"outputs": [],
459462
"source": [
460463
"# Test the vector search with a text query\n",
461-
"vector_search(\"A peaceful and uplifting atmosphere\", \"text\")\n",
464+
"vector_search(\"A man wearing a golden crown\", \"text\")\n",
462465
"\n",
463466
"# Also try these text queries:\n",
464-
"# - Healthy living and fitness\n",
465-
"# - A man wearing a golden crown\n",
466-
"# - Adorable fluffy creatures\n",
467-
"# - Winning business agreement\n",
468-
"# - A Winter's Tale on a Spanish Isle"
467+
"# - A rainbow of lively colors\n",
468+
"# - Creatures wondrous or familiar\n",
469+
"# - A boy and the ocean\n",
470+
"# - Houses"
469471
]
470472
},
471473
{
@@ -478,11 +480,9 @@
478480
"vector_search(\"https://images.isbndb.com/covers/10835953482746.jpg\", \"image\")\n",
479481
"\n",
480482
"# Also try these image queries:\n",
481-
"# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/1.png\n",
482-
"# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/2.png\n",
483-
"# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/3.png\n",
484-
"# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/4.png\n",
485-
"# - https://mongodb-developer.github.io/vector-search-lab/img/query-sample/5.png"
483+
"# - ../data/images/salad.jpg\n",
484+
"# - ../data/images/kitten.png\n",
485+
"# - ../data/images/barn.png"
486486
]
487487
},
488488
{
@@ -548,7 +548,7 @@
548548
"filter = <CODE_BLOCK_11>\n",
549549
"# Pass the `filter` as an argument to the `vector_search` function.\n",
550550
"# Notice how this filter is incorporated in the `pipeline` in the `vector_search` function.\n",
551-
"vector_search(\"A peaceful and uplifting atmosphere\", \"text\", filter)"
551+
"vector_search(\"A boy and the ocean\", \"text\", filter)"
552552
]
553553
},
554554
{
@@ -608,7 +608,7 @@
608608
"filter = <CODE_BLOCK_13>\n",
609609
"# Pass the `filter` as an argument to the `vector_search` function.\n",
610610
"# Notice how this filter is incorporated in the `pipeline` in the `vector_search` function.\n",
611-
"vector_search(\"A peaceful and uplifting atmosphere\", \"text\", filter)"
611+
"vector_search(\"A boy and the ocean\", \"text\", filter)"
612612
]
613613
},
614614
{
@@ -889,7 +889,7 @@
889889
"source": [
890890
"# Test the hybrid search query with a weight of 1.0 for vector search and 0.0 for full-text search\n",
891891
"hybrid_search(\n",
892-
" user_query=\"A Winter's Tale on a Spanish Isle\",\n",
892+
" user_query=\"My Favorite Summer\",\n",
893893
" vector_weight=1.0,\n",
894894
" full_text_weight=0.0,\n",
895895
")"
@@ -901,11 +901,11 @@
901901
"metadata": {},
902902
"outputs": [],
903903
"source": [
904-
"# Test the hybrid search query with a weight of 0.5 for vector search and 0.5 for full-text search\n",
904+
"# Test the hybrid search query with a weight of 0.3 for vector search and 0.7 for full-text search\n",
905905
"hybrid_search(\n",
906-
" user_query=\"A Winter's Tale on a Spanish Isle\",\n",
907-
" vector_weight=0.5,\n",
908-
" full_text_weight=0.5,\n",
906+
" user_query=\"My Favorite Summer\",\n",
907+
" vector_weight=0.3,\n",
908+
" full_text_weight=0.7,\n",
909909
")"
910910
]
911911
}

solutions/vector-search-lab.ipynb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,12 @@
277277
" Returns:\n",
278278
" List[float]: Embedding of the content as a list.\n",
279279
" \"\"\"\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",
281281
" 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",
283286
" return vo.multimodal_embed(inputs=[[content]], model=\"voyage-multimodal-3\", input_type=input_type).embeddings[0]"
284287
]
285288
},
@@ -470,14 +473,13 @@
470473
"outputs": [],
471474
"source": [
472475
"# 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",
474477
"\n",
475478
"# 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"
481483
]
482484
},
483485
{
@@ -490,11 +492,9 @@
490492
"vector_search(\"https://images.isbndb.com/covers/10835953482746.jpg\", \"image\")\n",
491493
"\n",
492494
"# 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"
498498
]
499499
},
500500
{
@@ -574,7 +574,7 @@
574574
"filter = {\"year\": {\"$gte\": 2002}}\n",
575575
"# Pass the `filter` as an argument to the `vector_search` function.\n",
576576
"# 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)"
578578
]
579579
},
580580
{
@@ -649,7 +649,7 @@
649649
"filter = {\"$and\": [{\"year\": {\"$gte\": 2002}}, {\"pages\": {\"$lte\": 250}}]}\n",
650650
"# Pass the `filter` as an argument to the `vector_search` function.\n",
651651
"# 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)"
653653
]
654654
},
655655
{
@@ -944,7 +944,7 @@
944944
"source": [
945945
"# Test the hybrid search query with a weight of 1.0 for vector search and 0.0 for full-text search\n",
946946
"hybrid_search(\n",
947-
" user_query=\"A Winter's Tale on a Spanish Isle\",\n",
947+
" user_query=\"My Favorite Summer\",\n",
948948
" vector_weight=1.0,\n",
949949
" full_text_weight=0.0,\n",
950950
")"
@@ -956,18 +956,18 @@
956956
"metadata": {},
957957
"outputs": [],
958958
"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",
960960
"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",
964964
")"
965965
]
966966
}
967967
],
968968
"metadata": {
969969
"kernelspec": {
970-
"display_name": "Python 3",
970+
"display_name": "base",
971971
"language": "python",
972972
"name": "python3"
973973
},
@@ -981,7 +981,7 @@
981981
"name": "python",
982982
"nbconvert_exporter": "python",
983983
"pygments_lexer": "ipython3",
984-
"version": "3.9.6"
984+
"version": "3.11.6"
985985
},
986986
"widgets": {
987987
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)