Skip to content

Commit 6a33c27

Browse files
authored
CSHARP-4960: Add new type field support for search indexes (#1528)
1 parent 0417b13 commit 6a33c27

File tree

11 files changed

+456
-73
lines changed

11 files changed

+456
-73
lines changed

specifications/index-management/tests/createSearchIndex.json

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@
2828
],
2929
"runOnRequirements": [
3030
{
31-
"minServerVersion": "7.0.0",
31+
"minServerVersion": "7.0.5",
32+
"maxServerVersion": "7.0.99",
33+
"topologies": [
34+
"replicaset",
35+
"load-balanced",
36+
"sharded"
37+
],
38+
"serverless": "forbid"
39+
},
40+
{
41+
"minServerVersion": "7.2.0",
3242
"topologies": [
3343
"replicaset",
3444
"load-balanced",
@@ -50,7 +60,8 @@
5060
"mappings": {
5161
"dynamic": true
5262
}
53-
}
63+
},
64+
"type": "search"
5465
}
5566
},
5667
"expectError": {
@@ -73,7 +84,8 @@
7384
"mappings": {
7485
"dynamic": true
7586
}
76-
}
87+
},
88+
"type": "search"
7789
}
7890
],
7991
"$db": "database0"
@@ -97,7 +109,8 @@
97109
"dynamic": true
98110
}
99111
},
100-
"name": "test index"
112+
"name": "test index",
113+
"type": "search"
101114
}
102115
},
103116
"expectError": {
@@ -121,7 +134,68 @@
121134
"dynamic": true
122135
}
123136
},
124-
"name": "test index"
137+
"name": "test index",
138+
"type": "search"
139+
}
140+
],
141+
"$db": "database0"
142+
}
143+
}
144+
}
145+
]
146+
}
147+
]
148+
},
149+
{
150+
"description": "create a vector search index",
151+
"operations": [
152+
{
153+
"name": "createSearchIndex",
154+
"object": "collection0",
155+
"arguments": {
156+
"model": {
157+
"definition": {
158+
"fields": [
159+
{
160+
"type": "vector",
161+
"path": "plot_embedding",
162+
"numDimensions": 1536,
163+
"similarity": "euclidean"
164+
}
165+
]
166+
},
167+
"name": "test index",
168+
"type": "vectorSearch"
169+
}
170+
},
171+
"expectError": {
172+
"isError": true,
173+
"errorContains": "Atlas"
174+
}
175+
}
176+
],
177+
"expectEvents": [
178+
{
179+
"client": "client0",
180+
"events": [
181+
{
182+
"commandStartedEvent": {
183+
"command": {
184+
"createSearchIndexes": "collection0",
185+
"indexes": [
186+
{
187+
"definition": {
188+
"fields": [
189+
{
190+
"type": "vector",
191+
"path": "plot_embedding",
192+
"numDimensions": 1536,
193+
"similarity": "euclidean"
194+
}
195+
]
196+
},
197+
"name": "test index",
198+
"type": "vectorSearch"
125199
}
126200
],
127201
"$db": "database0"

specifications/index-management/tests/createSearchIndex.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ createEntities:
1616
collectionName: *collection0
1717

1818
runOnRequirements:
19-
- minServerVersion: "7.0.0"
19+
# Skip server versions without fix of SERVER-83107 to avoid error message "BSON field 'createSearchIndexes.indexes.type' is an unknown field."
20+
# SERVER-83107 was not backported to 7.1.
21+
- minServerVersion: "7.0.5"
22+
maxServerVersion: "7.0.99"
23+
topologies: [ replicaset, load-balanced, sharded ]
24+
serverless: forbid
25+
- minServerVersion: "7.2.0"
2026
topologies: [ replicaset, load-balanced, sharded ]
2127
serverless: forbid
2228

@@ -26,7 +32,7 @@ tests:
2632
- name: createSearchIndex
2733
object: *collection0
2834
arguments:
29-
model: { definition: &definition { mappings: { dynamic: true } } }
35+
model: { definition: &definition { mappings: { dynamic: true } } , type: 'search' }
3036
expectError:
3137
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
3238
# that the driver constructs and sends the correct command.
@@ -39,15 +45,37 @@ tests:
3945
- commandStartedEvent:
4046
command:
4147
createSearchIndexes: *collection0
42-
indexes: [ { definition: *definition } ]
48+
indexes: [ { definition: *definition, type: 'search'} ]
4349
$db: *database0
4450

4551
- description: "name provided for an index definition"
4652
operations:
4753
- name: createSearchIndex
4854
object: *collection0
49-
arguments:
50-
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index' }
55+
arguments:
56+
model: { definition: &definition { mappings: { dynamic: true } } , name: 'test index', type: 'search' }
57+
expectError:
58+
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
59+
# that the driver constructs and sends the correct command.
60+
# The expected error message was changed in SERVER-83003. Check for the substring "Atlas" shared by both error messages.
61+
isError: true
62+
errorContains: Atlas
63+
expectEvents:
64+
- client: *client0
65+
events:
66+
- commandStartedEvent:
67+
command:
68+
createSearchIndexes: *collection0
69+
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
70+
$db: *database0
71+
72+
- description: "create a vector search index"
73+
operations:
74+
- name: createSearchIndex
75+
object: *collection0
76+
arguments:
77+
model: { definition: &definition { fields: [ {"type": "vector", "path": "plot_embedding", "numDimensions": 1536, "similarity": "euclidean"} ] }
78+
, name: 'test index', type: 'vectorSearch' }
5179
expectError:
5280
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
5381
# that the driver constructs and sends the correct command.
@@ -60,5 +88,5 @@ tests:
6088
- commandStartedEvent:
6189
command:
6290
createSearchIndexes: *collection0
63-
indexes: [ { definition: *definition, name: 'test index' } ]
91+
indexes: [ { definition: *definition, name: 'test index', type: 'vectorSearch' } ]
6492
$db: *database0

specifications/index-management/tests/createSearchIndexes.json

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@
2828
],
2929
"runOnRequirements": [
3030
{
31-
"minServerVersion": "7.0.0",
31+
"minServerVersion": "7.0.5",
32+
"maxServerVersion": "7.0.99",
33+
"topologies": [
34+
"replicaset",
35+
"load-balanced",
36+
"sharded"
37+
],
38+
"serverless": "forbid"
39+
},
40+
{
41+
"minServerVersion": "7.2.0",
3242
"topologies": [
3343
"replicaset",
3444
"load-balanced",
@@ -83,7 +93,8 @@
8393
"mappings": {
8494
"dynamic": true
8595
}
86-
}
96+
},
97+
"type": "search"
8798
}
8899
]
89100
},
@@ -107,7 +118,8 @@
107118
"mappings": {
108119
"dynamic": true
109120
}
110-
}
121+
},
122+
"type": "search"
111123
}
112124
],
113125
"$db": "database0"
@@ -132,7 +144,8 @@
132144
"dynamic": true
133145
}
134146
},
135-
"name": "test index"
147+
"name": "test index",
148+
"type": "search"
136149
}
137150
]
138151
},
@@ -157,7 +170,70 @@
157170
"dynamic": true
158171
}
159172
},
160-
"name": "test index"
173+
"name": "test index",
174+
"type": "search"
175+
}
176+
],
177+
"$db": "database0"
178+
}
179+
}
180+
}
181+
]
182+
}
183+
]
184+
},
185+
{
186+
"description": "create a vector search index",
187+
"operations": [
188+
{
189+
"name": "createSearchIndexes",
190+
"object": "collection0",
191+
"arguments": {
192+
"models": [
193+
{
194+
"definition": {
195+
"fields": [
196+
{
197+
"type": "vector",
198+
"path": "plot_embedding",
199+
"numDimensions": 1536,
200+
"similarity": "euclidean"
201+
}
202+
]
203+
},
204+
"name": "test index",
205+
"type": "vectorSearch"
206+
}
207+
]
208+
},
209+
"expectError": {
210+
"isError": true,
211+
"errorContains": "Atlas"
212+
}
213+
}
214+
],
215+
"expectEvents": [
216+
{
217+
"client": "client0",
218+
"events": [
219+
{
220+
"commandStartedEvent": {
221+
"command": {
222+
"createSearchIndexes": "collection0",
223+
"indexes": [
224+
{
225+
"definition": {
226+
"fields": [
227+
{
228+
"type": "vector",
229+
"path": "plot_embedding",
230+
"numDimensions": 1536,
231+
"similarity": "euclidean"
232+
}
233+
]
234+
},
235+
"name": "test index",
236+
"type": "vectorSearch"
161237
}
162238
],
163239
"$db": "database0"

specifications/index-management/tests/createSearchIndexes.yml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ createEntities:
1616
collectionName: *collection0
1717

1818
runOnRequirements:
19-
- minServerVersion: "7.0.0"
19+
# Skip server versions without fix of SERVER-83107 to avoid error message "BSON field 'createSearchIndexes.indexes.type' is an unknown field."
20+
# SERVER-83107 was not backported to 7.1.
21+
- minServerVersion: "7.0.5"
22+
maxServerVersion: "7.0.99"
23+
topologies: [ replicaset, load-balanced, sharded ]
24+
serverless: forbid
25+
- minServerVersion: "7.2.0"
2026
topologies: [ replicaset, load-balanced, sharded ]
2127
serverless: forbid
2228

@@ -25,7 +31,7 @@ tests:
2531
operations:
2632
- name: createSearchIndexes
2733
object: *collection0
28-
arguments:
34+
arguments:
2935
models: []
3036
expectError:
3137
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
@@ -48,7 +54,7 @@ tests:
4854
- name: createSearchIndexes
4955
object: *collection0
5056
arguments:
51-
models: [ { definition: &definition { mappings: { dynamic: true } } } ]
57+
models: [ { definition: &definition { mappings: { dynamic: true } } , type: 'search' } ]
5258
expectError:
5359
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
5460
# that the driver constructs and sends the correct command.
@@ -61,15 +67,37 @@ tests:
6167
- commandStartedEvent:
6268
command:
6369
createSearchIndexes: *collection0
64-
indexes: [ { definition: *definition } ]
70+
indexes: [ { definition: *definition, type: 'search'} ]
6571
$db: *database0
6672

6773
- description: "name provided for an index definition"
6874
operations:
6975
- name: createSearchIndexes
7076
object: *collection0
71-
arguments:
72-
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' } ]
77+
arguments:
78+
models: [ { definition: &definition { mappings: { dynamic: true } } , name: 'test index' , type: 'search' } ]
79+
expectError:
80+
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
81+
# that the driver constructs and sends the correct command.
82+
# The expected error message was changed in SERVER-83003. Check for the substring "Atlas" shared by both error messages.
83+
isError: true
84+
errorContains: Atlas
85+
expectEvents:
86+
- client: *client0
87+
events:
88+
- commandStartedEvent:
89+
command:
90+
createSearchIndexes: *collection0
91+
indexes: [ { definition: *definition, name: 'test index', type: 'search' } ]
92+
$db: *database0
93+
94+
- description: "create a vector search index"
95+
operations:
96+
- name: createSearchIndexes
97+
object: *collection0
98+
arguments:
99+
models: [ { definition: &definition { fields: [ {"type": "vector", "path": "plot_embedding", "numDimensions": 1536, "similarity": "euclidean"} ] },
100+
name: 'test index' , type: 'vectorSearch' } ]
73101
expectError:
74102
# This test always errors in a non-Atlas environment. The test functions as a unit test by asserting
75103
# that the driver constructs and sends the correct command.
@@ -82,5 +110,5 @@ tests:
82110
- commandStartedEvent:
83111
command:
84112
createSearchIndexes: *collection0
85-
indexes: [ { definition: *definition, name: 'test index' } ]
113+
indexes: [ { definition: *definition, name: 'test index', type: 'vectorSearch' } ]
86114
$db: *database0

0 commit comments

Comments
 (0)