๐๐ Pre-Filtering
You can also pre-filter your data by indexing any boolean, date, numeric, objectId, string, and UUID fields in your collection that you want to run your Atlas Vector Search queries against.
Filtering your data narrows the scope of your search and ensures that certain vector embeddings aren't considered for comparison.
Published after the year 2000โ
CODE_BLOCK_11
Answer
{
"name": ATLAS_VECTOR_SEARCH_INDEX_NAME,
"type": "vectorSearch",
"definition": {
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 512,
"similarity": "cosine",
},
{"type": "filter", "path": "year"},
]
},
}
CODE_BLOCK_12
Answer
{"year": {"$gte": 2000}}
Published after the year 2000 and under 100 pagesโ
CODE_BLOCK_13
Answer
{
"name": ATLAS_VECTOR_SEARCH_INDEX_NAME,
"type": "vectorSearch",
"definition": {
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 512,
"similarity": "cosine",
},
{"type": "filter", "path": "year"},
{"type": "filter", "path": "pages"},
]
},
}
CODE_BLOCK_14
Answer
{"$and": [{"year": {"$gte": 2000}}, {"pages": {"$lte": 100}}]}