Skip to content

Commit 74ac25e

Browse files
committed
DOCSP-44135: Mention vector search in pymongo search indexes page (#116)
1 parent f94d004 commit 74ac25e

File tree

2 files changed

+109
-36
lines changed

2 files changed

+109
-36
lines changed

source/includes/indexes/indexes.py

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,56 @@
8888
collection.create_search_index(index)
8989
# end-create-search-index
9090

91+
# start-create-vector-search-index
92+
93+
from pymongo.operations import SearchIndexModel
94+
95+
search_index_model = SearchIndexModel(
96+
definition={
97+
"fields": [
98+
{
99+
"type": "vector",
100+
"numDimensions": <number of dimensions>,
101+
"path": "<field to index>",
102+
"similarity": "<select from euclidean, cosine, dotProduct>"
103+
}
104+
]
105+
},
106+
name="<index name>",
107+
type="vectorSearch",
108+
)
109+
110+
collection.create_search_index(model=search_index_model)
111+
112+
# end-create-vector-search-index
113+
91114
# start-create-search-indexes
92-
index_one = {
93-
"definition": {
94-
"mappings": {
95-
"dynamic": True
96-
}
97-
},
98-
"name": "my_index",
99-
}
100115

101-
index_two = {
102-
"definition": {
116+
search_idx = SearchIndexModel(
117+
definition ={
103118
"mappings": {
104119
"dynamic": True
105120
}
106121
},
107-
"name": "my_other_index",
108-
}
122+
name="my_index",
123+
)
124+
125+
vector_idx = SearchIndexModel(
126+
definition={
127+
"fields": [
128+
{
129+
"type": "vector",
130+
"numDimensions": <number of dimensions>,
131+
"path": "<field to index>",
132+
"similarity": "<select from euclidean, cosine, dotProduct>"
133+
}
134+
]
135+
},
136+
name="my_vector_index",
137+
type="vectorSearch",
138+
)
109139

110-
indexes = [index_one, index_two]
140+
indexes = [search_idx, vector_idx]
111141

112142
collection.create_search_indexes(models=indexes)
113143
# end-create-search-indexes
@@ -120,18 +150,30 @@
120150
# end-list-search-indexes
121151

122152
# start-update-search-indexes
123-
new_index = {
124-
"definition": {
125-
"mappings": {
126-
"dynamic": True
127-
}
128-
},
129-
"name": "my_new_index",
153+
new_index_definition = {
154+
"mappings": {
155+
"dynamic": False
156+
}
130157
}
131158

132159
collection.update_search_index("my_index", new_index)
133160
# end-update-search-indexes
134161

162+
# start-update-vector-search-indexes
163+
new_index_definition = {
164+
"fields": [
165+
{
166+
"type": "vector",
167+
"numDimensions": 1536,
168+
"path": "<field to index>",
169+
"similarity": "euclidean"
170+
},
171+
]
172+
}
173+
174+
collection.update_search_index("my_vector_index", new_index_definition)
175+
# end-update-vector-search-indexes
176+
135177
# start-delete-search-indexes
136178
collection.drop_index("my_index")
137179
# end-delete-search-indexes

source/indexes/atlas-search-index.txt

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _pymongo-atlas-search-index:
22

3-
====================
4-
Atlas Search Indexes
5-
====================
3+
======================================
4+
Atlas Search and Vector Search Indexes
5+
======================================
66

77
.. contents:: On this page
88
:local:
@@ -20,16 +20,23 @@ Atlas Search Indexes
2020
Overview
2121
--------
2222

23-
The Atlas Search feature enables you to perform full-text searches on
24-
collections hosted on MongoDB Atlas. The indexes specify the behavior of
23+
You can manage your :atlas:`Atlas Search </atlas-search>` and
24+
:atlas:`Atlas Vector Search </atlas-vector-search/vector-search-overview/>`
25+
indexes by using {+driver-short+}. The indexes specify the behavior of
2526
the search and which fields to index.
2627

27-
To learn more about MongoDB Atlas Search, see the
28-
:atlas:`Atlas Search Indexes </atlas-search/atlas-search-overview/>`
29-
documentation.
28+
Atlas Search enables you to perform full-text searches on
29+
collections hosted on MongoDB Atlas. Atlas Search indexes specify the behavior of
30+
the search and which fields to index.
31+
32+
Atlas Vector Search enables you to perform semantic searches on vector
33+
embeddings stored in MongoDB Atlas. Vector Search indexes define the
34+
indexes for the vector embeddings that you want to query and the boolean,
35+
date, objectId, numeric, string, or UUID values that you want to use to
36+
pre-filter your data.
3037

3138
You can call the following methods on a collection to manage your Atlas Search
32-
indexes:
39+
and Vector Search indexes:
3340

3441
- ``create_search_index()``
3542
- ``create_search_indexes()``
@@ -55,16 +62,31 @@ Create a Search Index
5562
You can use the `create_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_index>`__
5663
and the
5764
`create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__
58-
methods to create Atlas Search indexes.
65+
methods to create Atlas Search indexes or Atlas Vector Search indexes.
5966

60-
The following code example shows how to create a single index:
67+
The following code example shows how to create a single Atlas Search index:
6168

6269
.. literalinclude:: /includes/indexes/indexes.py
6370
:language: python
6471
:start-after: start-create-search-index
6572
:end-before: end-create-search-index
6673

67-
The following code example shows how to create multiple indexes:
74+
The following code example shows how to create a single Atlas Vector Search index
75+
by using the `SearchIndexModel <{+api-root+}pymongo/operations.html#pymongo.operations.SearchIndexModel>`__
76+
object:
77+
78+
.. literalinclude:: /includes/indexes/indexes.py
79+
:language: python
80+
:start-after: start-create-vector-search-index
81+
:end-before: end-create-vector-search-index
82+
83+
You can use the `create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__
84+
method to create multiple indexes. These indexes can be Atlas Search or
85+
Vector Search indexes. The ``create_search_indexes()`` method takes a list of
86+
``SearchIndexModel`` objects that correspond to each index you want to create.
87+
88+
The following code example shows how to create an Atlas Search index and an Atlas
89+
Vector Search index:
6890

6991
.. literalinclude:: /includes/indexes/indexes.py
7092
:language: python
@@ -78,7 +100,8 @@ List Search Indexes
78100

79101
You can use the
80102
`list_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.list_search_indexes>`__
81-
method to return the Atlas Search indexes of a collection.
103+
method to get information about the Atlas Search and Vector Search indexes
104+
of a collection.
82105

83106
The following code example shows how to print a list of the search indexes of
84107
a collection:
@@ -96,24 +119,32 @@ Update a Search Index
96119

97120
You can use the
98121
`update_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.update_search_index>`__
99-
method to update an Atlas Search index.
122+
method to update an Atlas Search or Vector Search index.
100123

101-
The following code shows how to update a search index:
124+
The following code example shows how to update an Atlas Search index:
102125

103126
.. literalinclude:: /includes/indexes/indexes.py
104127
:language: python
105128
:dedent:
106129
:start-after: start-update-search-indexes
107130
:end-before: end-update-search-indexes
108131

132+
The following code example shows how to update an Atlas Vector Search index:
133+
134+
.. literalinclude:: /includes/indexes/indexes.py
135+
:language: python
136+
:dedent:
137+
:start-after: start-update-vector-search-indexes
138+
:end-before: end-update-vector-search-indexes
139+
109140
.. _pymongo-atlas-search-index-drop:
110141

111142
Delete a Search Index
112143
---------------------
113144

114145
You can use the
115146
`drop_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.drop_search_index>`__
116-
method to remove an Atlas Search index.
147+
method to remove an Atlas Search or Vector Search index.
117148

118149
The following code shows how to delete a search index from a collection:
119150

0 commit comments

Comments
 (0)