Skip to main content

馃憪 Add embeddings to the data

Now that you know how to generate embeddings using the CLIP model, let's add embeddings to the books dataset you previously imported into MongoDB.

This is a common scenario you will run into where you might want to update your existing data in MongoDB with embeddings.

Fill in any <CODE_BLOCK_N> placeholders and run the cells under the Step 4: Adding embeddings to existing data in Atlas section in the notebook to add embeddings of the books' cover images to the documents in the books collection.

The answers for code blocks in this section are as follows:

CODE_BLOCK_2

Answer
collection.find({})

CODE_BLOCK_3

Answer
get_embedding(content, "image")

CODE_BLOCK_4

Answer
{"$set": {embedding_field: embedding}}

CODE_BLOCK_5

Answer
collection.update_one(filter, update)

To visually verify that embeddings have been added to the documents in the books collection, click on the leaf icon in the left navigation bar of the IDE.

Navigate to a document in the books collection and ensure that it has an embedding field.

Preview document