Skip to content

Commit

Permalink
Update pre-filtering notes
Browse files Browse the repository at this point in the history
in the new vectorSearch index creation, there is no longer dynamic mapping, so both filtering on year would not work as well
  • Loading branch information
wjteo authored Apr 17, 2024
1 parent f3bbbb6 commit 084ebcf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions docs/7-vector-search/9-filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ One of the nice things about Vector Search in Atlas is its seamless integration

## Pre-filtering using number fields

If we want to pre-filter all books that are from 2001 we can do:
If we want to pre-filter all books that are from 2001 we can try this (but it won't work right now):

```js
[
Expand All @@ -26,7 +26,7 @@ If we want to pre-filter all books that are from 2001 we can do:

## Pre-filtering using string fields

Strings are a bit more tricky. We can think this will work, but right now it wont:
We can try this and it won't work as well:

```js
[
Expand All @@ -44,7 +44,7 @@ Strings are a bit more tricky. We can think this will work, but right now it won

The problem lies on the `vectorsearch` index, not in this code. For String fields to be pre-filtered we need to add a mapping to those fields in our Search Index definition. To do that, go to MongoDB Atlas, go to your collections and open again the Search Indexes tab, as you did while [creating the indexes](/docs/vector-search/create-index)

In this case, we already have our index and we're going to edit it in the JSON editor. Just change the index adding a mapping for the `language` field. The index should look like:
In this case, we already have our index and we're going to edit it in the JSON editor. Just change the index adding a mapping for the `year` field and `language` field. The index should look like:

```js
{
Expand All @@ -55,6 +55,10 @@ In this case, we already have our index and we're going to edit it in the JSON e
"numDimensions": 1536,
"similarity": "cosine"
},
{
"type": "filter",
"path": "year"
},
{
"type": "filter",
"path": "language"
Expand All @@ -63,9 +67,13 @@ In this case, we already have our index and we're going to edit it in the JSON e
}
```

The only difference is that we've added this part, stating that `language` should be indexed as a [filter](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/#about-the-filter-type).
The only difference is that we've added this part, stating that `year` and `language` should be indexed as a [filter](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/#about-the-filter-type).

```js
{
"type": "filter",
"path": "year"
},
{
"type": "filter",
"path": "language"
Expand Down

0 comments on commit 084ebcf

Please sign in to comment.