When using the $vectorSearch aggregation stage and specifying filter, using the $exists operator isn't supported, but another way of effectively doing the same thing is to check if the property value is null. For example:
{ property: null }
{ property: { $eq: null } }
This works fine when doing a $match aggregation stage; it successfully retrieves the documents that don't have property set to a value, or documents that have property set to null.
However, specifying this as filter when doing $vectorSearch doesn't work the same. It does not match to documents that don't have property .
Is there a way to $vectorSearch and filter by a property value that does not exist?
If not, you'd have to set the property values to null or some other value, and then query based on this value, rather than checking if the property exists or not. This would also mean having to update any existing $match queries that use $exists on the property.
You could also add a $match stage after the $vectorSearch stage but this isn't a great option when you want to limit the number of documents returned by $vectorSearch (because it could be limiting/excluding documents that would otherwise match).
Thanks!
filter: { property: { $and [ { $ne: null }, { $ne: undefined } ] } }or{ $nin: [null, undefined ] }. If you want to search on those fields not existing then reverse the comparisons above$vectorSearch. And as a side note for future readers,filter: { property: { $and [ { $ne: null }, { $ne: undefined } ] } }isn't a correct filter. It'd be{ $and: [{ property: { $ne: null } }, { property: { $ne: undefined }}] }