From 8203326eb887d76fe2ed1c233df69be2b5e3a51d Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 28 Oct 2024 16:07:17 -0400 Subject: [PATCH 1/5] checkpoint --- source/indexes/atlas-search-index.txt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source/indexes/atlas-search-index.txt b/source/indexes/atlas-search-index.txt index 147aef68..a9fe6b5a 100644 --- a/source/indexes/atlas-search-index.txt +++ b/source/indexes/atlas-search-index.txt @@ -1,8 +1,8 @@ .. _pymongo-atlas-search-index: -==================== -Atlas Search Indexes -==================== +====================================== +Atlas Search and Vector Search Indexes +====================================== .. contents:: On this page :local: @@ -20,13 +20,20 @@ Atlas Search Indexes Overview -------- -The Atlas Search feature enables you to perform full-text searches on -collections hosted on MongoDB Atlas. The indexes specify the behavior of +You can manage your :atlas:`Atlas Search ` and +:atlas:`Atlas Vector Search ` +indexes by using the {+driver-short+}. The indexes specify the behavior of the search and which fields to index. -To learn more about MongoDB Atlas Search, see the -:atlas:`Atlas Search Indexes ` -documentation. +Atlas Search enables you to perform full-text searches on +collections hosted on MongoDB Atlas. Atlas Search indexes specify the behavior of +the search and which fields to index. + +Atlas Vector Search enables you to perform semantic searches on vector +embeddings stored in MongoDB Atlas. Vector Search indexes define the +indexes for the vector embeddings that you want to query and the boolean, +date, objectId, numeric, string, or UUID values that you want to use to +pre-filter your data. You can call the following methods on a collection to manage your Atlas Search indexes: From fb0c5f046538de257ec92933a47d56b51f5c1503 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 29 Oct 2024 14:58:39 -0400 Subject: [PATCH 2/5] full page --- source/includes/indexes/indexes.py | 82 ++++++++++++++++++++------- source/indexes/atlas-search-index.txt | 38 ++++++++++--- 2 files changed, 93 insertions(+), 27 deletions(-) diff --git a/source/includes/indexes/indexes.py b/source/includes/indexes/indexes.py index 11731636..b39f2cf1 100644 --- a/source/includes/indexes/indexes.py +++ b/source/includes/indexes/indexes.py @@ -88,26 +88,56 @@ collection.create_search_index(index) # end-create-search-index +# start-create-vector-search-index + +from pymongo.operations import SearchIndexModel + +search_index_model = SearchIndexModel( + definition={ + "fields": [ + { + "type": "vector", + "numDimensions": , + "path": "", + "similarity": "euclidean | cosine | dotProduct" + } + ] + }, + name="", + type="vectorSearch", +) + +collection.create_search_index(model=search_index_model) + +# end-create-vector-search-index + # start-create-search-indexes -index_one = { - "definition": { - "mappings": { - "dynamic": True - } - }, - "name": "my_index", -} -index_two = { - "definition": { +index_one = SearchIndexModel( + definition ={ "mappings": { "dynamic": True } }, - "name": "my_other_index", -} + name="my_index", +) + +index_two_vector = SearchIndexModel( + definition={ + "fields": [ + { + "type": "vector", + "numDimensions": , + "path": "", + "similarity": "euclidean | cosine | dotProduct" + } + ] + }, + name="my_vector_index", + type="vectorSearch", +) -indexes = [index_one, index_two] +indexes = [index_one, index_two_vector] collection.create_search_indexes(models=indexes) # end-create-search-indexes @@ -120,18 +150,30 @@ # end-list-search-indexes # start-update-search-indexes -new_index = { - "definition": { - "mappings": { - "dynamic": True - } - }, - "name": "my_new_index", +new_index_definition = { + "mappings": { + "dynamic": False + } } collection.update_search_index("my_index", new_index) # end-update-search-indexes +# start-update-vector-search-indexes +new_index_definition = { + "fields": [ + { + "type": "vector", + "numDimensions": 1536, + "path": "", + "similarity": "euclidean" + }, + ] +} + +collection.update_search_index("my_vector_index", new_index_definition) +# end-update-vector-search-indexes + # start-delete-search-indexes collection.drop_index("my_index") # end-delete-search-indexes \ No newline at end of file diff --git a/source/indexes/atlas-search-index.txt b/source/indexes/atlas-search-index.txt index a9fe6b5a..a1d7d6e8 100644 --- a/source/indexes/atlas-search-index.txt +++ b/source/indexes/atlas-search-index.txt @@ -62,16 +62,31 @@ Create a Search Index You can use the `create_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_index>`__ and the `create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__ -methods to create Atlas Search indexes. +methods to create Atlas Search indexes or Atlas Vector Search indexes. -The following code example shows how to create a single index: +The following code example shows how to create a single Atlas Search index: .. literalinclude:: /includes/indexes/indexes.py :language: python :start-after: start-create-search-index :end-before: end-create-search-index -The following code example shows how to create multiple indexes: +The following code example shows how to create a single Atlas Vector Search index +using the `SearchIndexModel <{+api-root+}pymongo/operations.html#pymongo.operations.SearchIndexModel>`__ +object: + +.. literalinclude:: /includes/indexes/indexes.py + :language: python + :start-after: start-create-vector-search-index + :end-before: end-create-vector-search-index + +You can use `create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__ +to create multiple indexes. These indexes can be Atlas Search indexes or Atlas +Vector Search indexes. ``create_search_indexes()`` requires the ``SearchIndexModel`` +object. + +The following code example shows how to create an Atlas Search index and Atlas +Vector Search index: .. literalinclude:: /includes/indexes/indexes.py :language: python @@ -85,7 +100,8 @@ List Search Indexes You can use the `list_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.list_search_indexes>`__ -method to return the Atlas Search indexes of a collection. +method to return the Atlas Search indexes and Atlas Vector Search indexes +of a collection. The following code example shows how to print a list of the search indexes of a collection: @@ -103,9 +119,9 @@ Update a Search Index You can use the `update_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.update_search_index>`__ -method to update an Atlas Search index. +method to update an Atlas Search index or Atlas Vector Search index. -The following code shows how to update a search index: +The following code example shows how to update an Atlas Search index: .. literalinclude:: /includes/indexes/indexes.py :language: python @@ -113,6 +129,14 @@ The following code shows how to update a search index: :start-after: start-update-search-indexes :end-before: end-update-search-indexes +The following code example shows how to update an Atlas Vector Search index: + +.. literalinclude:: /includes/indexes/indexes.py + :language: python + :dedent: + :start-after: start-update-vector-search-indexes + :end-before: end-update-vector-search-indexes + .. _pymongo-atlas-search-index-drop: Delete a Search Index @@ -120,7 +144,7 @@ Delete a Search Index You can use the `drop_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.drop_search_index>`__ -method to remove an Atlas Search index. +method to remove an Atlas Search index or Atlas Vector Search index. The following code shows how to delete a search index from a collection: From 6866297d276ca04e5f46b471c9c25a73d373f2e8 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 29 Oct 2024 15:12:50 -0400 Subject: [PATCH 3/5] small fixes --- source/indexes/atlas-search-index.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/indexes/atlas-search-index.txt b/source/indexes/atlas-search-index.txt index a1d7d6e8..3445c649 100644 --- a/source/indexes/atlas-search-index.txt +++ b/source/indexes/atlas-search-index.txt @@ -22,7 +22,7 @@ Overview You can manage your :atlas:`Atlas Search ` and :atlas:`Atlas Vector Search ` -indexes by using the {+driver-short+}. The indexes specify the behavior of +indexes by using {+driver-short+}. The indexes specify the behavior of the search and which fields to index. Atlas Search enables you to perform full-text searches on @@ -85,7 +85,7 @@ to create multiple indexes. These indexes can be Atlas Search indexes or Atlas Vector Search indexes. ``create_search_indexes()`` requires the ``SearchIndexModel`` object. -The following code example shows how to create an Atlas Search index and Atlas +The following code example shows how to create an Atlas Search index and an Atlas Vector Search index: .. literalinclude:: /includes/indexes/indexes.py From 38b72899602e77a0a1315d709f47a4eef8d4b593 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Wed, 30 Oct 2024 11:37:01 -0400 Subject: [PATCH 4/5] addressing feedback --- source/includes/indexes/indexes.py | 22 +++++++++++----------- source/indexes/atlas-search-index.txt | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source/includes/indexes/indexes.py b/source/includes/indexes/indexes.py index b39f2cf1..b5574a5c 100644 --- a/source/includes/indexes/indexes.py +++ b/source/includes/indexes/indexes.py @@ -97,13 +97,13 @@ "fields": [ { "type": "vector", - "numDimensions": , - "path": "", - "similarity": "euclidean | cosine | dotProduct" + "numDimensions": , + "path": "", + "similarity": } ] }, @@ -137,7 +137,7 @@ type="vectorSearch", ) -indexes = [index_one, index_two_vector] +indexes = [search_idx, vector_idx] collection.create_search_indexes(models=indexes) # end-create-search-indexes @@ -165,7 +165,7 @@ { "type": "vector", "numDimensions": 1536, - "path": "", + "path": "", "similarity": "euclidean" }, ] diff --git a/source/indexes/atlas-search-index.txt b/source/indexes/atlas-search-index.txt index 3445c649..df4c7b7e 100644 --- a/source/indexes/atlas-search-index.txt +++ b/source/indexes/atlas-search-index.txt @@ -36,7 +36,7 @@ date, objectId, numeric, string, or UUID values that you want to use to pre-filter your data. You can call the following methods on a collection to manage your Atlas Search -indexes: +and vector Search indexes: - ``create_search_index()`` - ``create_search_indexes()`` @@ -72,7 +72,7 @@ The following code example shows how to create a single Atlas Search index: :end-before: end-create-search-index The following code example shows how to create a single Atlas Vector Search index -using the `SearchIndexModel <{+api-root+}pymongo/operations.html#pymongo.operations.SearchIndexModel>`__ +by using the `SearchIndexModel <{+api-root+}pymongo/operations.html#pymongo.operations.SearchIndexModel>`__ object: .. literalinclude:: /includes/indexes/indexes.py @@ -80,10 +80,10 @@ object: :start-after: start-create-vector-search-index :end-before: end-create-vector-search-index -You can use `create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__ -to create multiple indexes. These indexes can be Atlas Search indexes or Atlas -Vector Search indexes. ``create_search_indexes()`` requires the ``SearchIndexModel`` -object. +You can use the `create_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.create_search_indexes>`__ +method to create multiple indexes. These indexes can be Atlas Search or +Vector Search indexes. The ``create_search_indexes()`` method takes a list of +``SearchIndexModel`` objects that correspond to each index you want to create. The following code example shows how to create an Atlas Search index and an Atlas Vector Search index: @@ -100,7 +100,7 @@ List Search Indexes You can use the `list_search_indexes() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.list_search_indexes>`__ -method to return the Atlas Search indexes and Atlas Vector Search indexes +method to get information about the Atlas Search and Vector Search indexes of a collection. The following code example shows how to print a list of the search indexes of @@ -119,7 +119,7 @@ Update a Search Index You can use the `update_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.update_search_index>`__ -method to update an Atlas Search index or Atlas Vector Search index. +method to update an Atlas Search or Vector Search index. The following code example shows how to update an Atlas Search index: @@ -144,7 +144,7 @@ Delete a Search Index You can use the `drop_search_index() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.drop_search_index>`__ -method to remove an Atlas Search index or Atlas Vector Search index. +method to remove an Atlas Search or Vector Search index. The following code shows how to delete a search index from a collection: From 7de7b4fbbd414cb208d327814ef813ed055d3086 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Wed, 30 Oct 2024 11:50:14 -0400 Subject: [PATCH 5/5] code example --- source/includes/indexes/indexes.py | 4 ++-- source/indexes/atlas-search-index.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/includes/indexes/indexes.py b/source/includes/indexes/indexes.py index b5574a5c..7b547017 100644 --- a/source/includes/indexes/indexes.py +++ b/source/includes/indexes/indexes.py @@ -99,7 +99,7 @@ "type": "vector", "numDimensions": , "path": "", - "similarity": " } ] }, @@ -129,7 +129,7 @@ "type": "vector", "numDimensions": , "path": "", - "similarity": " } ] }, diff --git a/source/indexes/atlas-search-index.txt b/source/indexes/atlas-search-index.txt index df4c7b7e..d0ad5091 100644 --- a/source/indexes/atlas-search-index.txt +++ b/source/indexes/atlas-search-index.txt @@ -36,7 +36,7 @@ date, objectId, numeric, string, or UUID values that you want to use to pre-filter your data. You can call the following methods on a collection to manage your Atlas Search -and vector Search indexes: +and Vector Search indexes: - ``create_search_index()`` - ``create_search_indexes()``