Driver handles index types.
(self)
| 298 | self.assertEqual(index["latestDefinition"], model["definition"]) |
| 299 | |
| 300 | def test_case_7(self): |
| 301 | """Driver handles index types.""" |
| 302 | |
| 303 | # Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``). |
| 304 | coll0 = self.db[f"col{uuid.uuid4()}"] |
| 305 | coll0.insert_one({}) |
| 306 | |
| 307 | # Use these search and vector search definitions for indexes. |
| 308 | search_definition = {"mappings": {"dynamic": False}} |
| 309 | vector_search_definition = { |
| 310 | "fields": [ |
| 311 | { |
| 312 | "type": "vector", |
| 313 | "path": "plot_embedding", |
| 314 | "numDimensions": 1536, |
| 315 | "similarity": "euclidean", |
| 316 | }, |
| 317 | ] |
| 318 | } |
| 319 | |
| 320 | # Create a new search index on ``coll0`` that implicitly passes its type. |
| 321 | implicit_search_resp = coll0.create_search_index( |
| 322 | model={"name": _NAME + "-implicit", "definition": search_definition} |
| 323 | ) |
| 324 | |
| 325 | # Get the index definition. |
| 326 | resp = (coll0.list_search_indexes(name=implicit_search_resp)).next() |
| 327 | |
| 328 | # Assert that the index model contains the correct index type: ``"search"``. |
| 329 | self.assertEqual(resp["type"], "search") |
| 330 | |
| 331 | # Create a new search index on ``coll0`` that explicitly passes its type. |
| 332 | explicit_search_resp = coll0.create_search_index( |
| 333 | model={"name": _NAME + "-explicit", "type": "search", "definition": search_definition} |
| 334 | ) |
| 335 | |
| 336 | # Get the index definition. |
| 337 | resp = (coll0.list_search_indexes(name=explicit_search_resp)).next() |
| 338 | |
| 339 | # Assert that the index model contains the correct index type: ``"search"``. |
| 340 | self.assertEqual(resp["type"], "search") |
| 341 | |
| 342 | # Create a new vector search index on ``coll0`` that explicitly passes its type. |
| 343 | explicit_vector_resp = coll0.create_search_index( |
| 344 | model={ |
| 345 | "name": _NAME + "-vector", |
| 346 | "type": "vectorSearch", |
| 347 | "definition": vector_search_definition, |
| 348 | } |
| 349 | ) |
| 350 | |
| 351 | # Get the index definition. |
| 352 | resp = (coll0.list_search_indexes(name=explicit_vector_resp)).next() |
| 353 | |
| 354 | # Assert that the index model contains the correct index type: ``"vectorSearch"``. |
| 355 | self.assertEqual(resp["type"], "vectorSearch") |
| 356 | |
| 357 | # Catch the error raised when trying to create a vector search index without specifying the type |
nothing calls this directly
no test coverage detected