Skip to content

Commit 839912d

Browse files
committed
merge conflicts
2 parents 9366149 + b3fd18e commit 839912d

File tree

9 files changed

+503
-37
lines changed

9 files changed

+503
-37
lines changed

.github/workflows/backport.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Backport
2+
on:
3+
pull_request_target:
4+
types:
5+
- closed
6+
- labeled
7+
8+
jobs:
9+
backport:
10+
name: Backport
11+
runs-on: ubuntu-latest
12+
# Only react to merged PRs for security reasons.
13+
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
14+
if: >
15+
github.event.pull_request.merged
16+
&& (
17+
github.event.action == 'closed'
18+
|| (
19+
github.event.action == 'labeled'
20+
&& contains(github.event.label.name, 'backport')
21+
)
22+
)
23+
steps:
24+
- uses: tibdex/backport@v2
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}

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/includes/run-command.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# start-hello
2+
3+
database = client.get_database("my_db")
4+
5+
hello = database.command("hello")
6+
7+
print(hello)
8+
9+
# end-hello
10+
11+
# start-readpref
12+
13+
from pymongo.read_preferences import Secondary
14+
15+
database = client.get_database("my_db")
16+
17+
hello = database.command("hello", read_preference=Secondary())
18+
19+
print(hello)
20+
21+
# end-readpref
22+
23+
# start-cursor-command
24+
25+
database = client.get_database("sample_mflix")
26+
27+
result = database.cursor_command("find", "movies", filter={"runtime": 11})
28+
29+
print(result.to_list())
30+
31+
# end-cursor-command
32+
33+
# start-runcommand
34+
35+
database = client.get_database("sample_mflix")
36+
37+
result = database.command("dbStats")
38+
39+
print(result)
40+
41+
# end-runcommand

source/includes/troubleshooting/tls.rst

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,67 @@ following steps:
122122

123123
- Downgrade Python to v3.9 or earlier
124124
- Upgrade {+mdb-server+} to v4.2 or later
125-
- Install {+driver-short+} with the :ref:`OCSP <pymongo-disable-ocsp>` option, which relies on PyOpenSSL
125+
- Install {+driver-short+} with the :ref:`OCSP <pymongo-disable-ocsp>` option, which relies on PyOpenSSL
126+
127+
Unsafe Legacy Renegotiation Disabled
128+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129+
130+
When using OpenSSL v3 or later, you might see an error similar to the following
131+
message:
132+
133+
.. code-block:: python
134+
135+
[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled
136+
137+
These types of errors occur because of outdated or buggy SSL proxies that mistakenly
138+
enforce legacy `TLS renegotiation <https://www.ibm.com/docs/en/i/7.3?topic=settings-renegotiation>`__.
139+
140+
To resolve this issue, perform the following steps:
141+
142+
.. procedure::
143+
:style: normal
144+
145+
.. step:: Check OpenSSL Version
146+
147+
Run the following command to ensure that you have OpenSSL vv3.0.4 or
148+
later installed:
149+
150+
.. code-block:: bash
151+
152+
openssl version
153+
154+
.. step:: Use the ``UnsafeLegacyServerConnect`` Option
155+
156+
Create a configuration file that includes the
157+
``UnsafeLegacyServerConnect`` option. The following example shows how to set
158+
the ``UnsafeLegacyServerConnect`` option:
159+
160+
.. code-block:: shell
161+
:emphasize-lines: 10
162+
163+
openssl_conf = openssl_init
164+
165+
[openssl_init]
166+
ssl_conf = ssl_sect
167+
168+
[ssl_sect]
169+
system_default = system_default_sect
170+
171+
[system_default_sect]
172+
Options = UnsafeLegacyServerConnect
173+
174+
.. step:: Run Python with OpenSSL Configuration
175+
176+
Run Python while setting the ``OPENSSL_CONF`` environment variable to use
177+
the OpenSSL configuration file you just created:
178+
179+
.. code-block:: shell
180+
181+
OPENSSL_CONF=/path/to/the/config/file/above.cnf python ...
182+
183+
.. important::
184+
185+
Because setting the ``UnsafeLegacyServerConnect`` option has
186+
`security implications <https://docs.openssl.org/3.0/man3/SSL_CTX_set_options/#patched-openssl-client-and-unpatched-server>`__,
187+
use this workaround as a last
188+
resort to address ``unsafe legacy renegotiation disabled`` errors.

source/index.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ MongoDB {+driver-short+} Documentation
1717
/databases-collections
1818
/write-operations
1919
/read
20+
/run-command
2021
/indexes
2122
/aggregation
2223
/security
@@ -68,6 +69,11 @@ Read Data from MongoDB
6869

6970
Learn how you can retrieve data from MongoDB in the :ref:`pymongo-read` section.
7071

72+
Run a Database Command
73+
----------------------
74+
75+
Learn how to run a database command in the :ref:`pymongo-run-command` section.
76+
7177
Optimize Queries with Indexes
7278
-----------------------------
7379

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)