Skip to content

[ENH]: Add install dependencies section in multimodal_retrieval.ipynb #4491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions examples/multimodal/multimodal_retrieval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,37 @@
"This notebook shows an example of how to create and query a collection with both text and images, using Chroma's built-in features. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install Dependencies\n",
"Before we start, let's install some dependencies first to ensure that the example below works."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install datasets chromadb open-clip-torch"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dataset\n",
"\n",
"We us a small subset of the [coco object detection dataset](https://huggingface.co/datasets/detection-datasets/coco), hosted on HuggingFace. \n",
"We use a small subset of the [coco object detection dataset](https://huggingface.co/datasets/detection-datasets/coco), hosted on HuggingFace. \n",
"\n",
"We download a small fraction of all the images in the dataset locally, and use it to create a multimodal collection."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -334,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -414,7 +431,7 @@
"\n",
"print(\"Results\")\n",
"retrieved = collection.query(query_images=[query_image], include=['data'], n_results=5)\n",
"for img in retrieved['data'][0][1:]:\n",
"for img in retrieved['data'][0][:]:\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

In both result loops, you're now including the query image itself in the display loop by using [:] instead of [1:]. This means the first displayed image will be the query image itself, which may be redundant and confusing to users.

Consider keeping the original slicing to exclude the query image from results:

Suggested change
"for img in retrieved['data'][0][:]:\n",
"for img in retrieved['data'][0][1:]:\n",

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

" plt.imshow(img)\n",
" plt.axis(\"off\")\n",
" plt.show()"
Expand All @@ -429,7 +446,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -477,7 +494,7 @@
"query_uri = image_uris[1]\n",
"\n",
"query_result = collection.query(query_uris=query_uri, include=['data'], n_results=5)\n",
"for img in query_result['data'][0][1:]:\n",
"for img in query_result['data'][0][:]:\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

Same issue here - this loop now includes the query image in the display results. Unless this is intentional, you should keep the original slicing to exclude the query image:

Suggested change
"for img in query_result['data'][0][:]:\n",
"for img in query_result['data'][0][1:]:\n",

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

" plt.imshow(img)\n",
" plt.axis(\"off\")\n",
" plt.show()"
Expand Down