Skip to main content

馃憪 Perform vector search queries

Now let's run some vector search queries against the books collection.

Fill in any <CODE_BLOCK_N> placeholders and run the cells under the Step 6: Perform vector search queries section in the notebook to run vector search queries against your data.

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

CODE_BLOCK_9

Answer
get_embedding(user_query, mode)

CODE_BLOCK_10

Answer
[
{
"$vectorSearch": {
"index": ATLAS_VECTOR_SEARCH_INDEX_NAME,
"queryVector": query_embedding,
"path": "embedding",
"numCandidates": 50,
"filter": filter,
"limit": 5,
}
},
{"$project": {"_id": 0, "title": 1, "cover": 1, "year":1, "pages":1, "score": {"$meta": "vectorSearchScore"}}},
]

CODE_BLOCK_11

Answer
collection.aggregate(pipeline)