|
6 | 6 |
|
7 | 7 | from pymongo.collection import Collection |
8 | 8 | from pymongo.operations import SearchIndexModel |
9 | | -from pymongo_search_utils import create_vector_search_index # noqa: F401 |
10 | 9 |
|
11 | 10 | logger = logging.getLogger(__file__) |
12 | 11 |
|
@@ -35,81 +34,6 @@ def _vector_search_index_definition( |
35 | 34 | return definition |
36 | 35 |
|
37 | 36 |
|
38 | | -def drop_vector_search_index( |
39 | | - collection: Collection, |
40 | | - index_name: str, |
41 | | - *, |
42 | | - wait_until_complete: Optional[float] = None, |
43 | | -) -> None: |
44 | | - """Drop a created vector search index |
45 | | -
|
46 | | - Args: |
47 | | - collection (Collection): MongoDB Collection with index to be dropped |
48 | | - index_name (str): Name of the MongoDB index |
49 | | - wait_until_complete (Optional[float]): If provided, number of seconds to wait |
50 | | - until search index is ready. |
51 | | - """ |
52 | | - logger.info( |
53 | | - "Dropping Search Index %s from Collection: %s", index_name, collection.name |
54 | | - ) |
55 | | - collection.drop_search_index(index_name) |
56 | | - if wait_until_complete: |
57 | | - _wait_for_predicate( |
58 | | - predicate=lambda: len(list(collection.list_search_indexes())) == 0, |
59 | | - err=f"Index {index_name} did not drop in {wait_until_complete}!", |
60 | | - timeout=wait_until_complete, |
61 | | - ) |
62 | | - logger.info("Vector Search index %s.%s dropped", collection.name, index_name) |
63 | | - |
64 | | - |
65 | | -def update_vector_search_index( |
66 | | - collection: Collection, |
67 | | - index_name: str, |
68 | | - dimensions: int, |
69 | | - path: str, |
70 | | - similarity: str, |
71 | | - filters: Optional[List[str]] = None, |
72 | | - *, |
73 | | - wait_until_complete: Optional[float] = None, |
74 | | - **kwargs: Any, |
75 | | -) -> None: |
76 | | - """Update a search index. |
77 | | -
|
78 | | - Replace the existing index definition with the provided definition. |
79 | | -
|
80 | | - Args: |
81 | | - collection (Collection): MongoDB Collection |
82 | | - index_name (str): Name of Index |
83 | | - dimensions (int): Number of dimensions in embedding |
84 | | - path (str): field with vector embedding |
85 | | - similarity (str): The similarity score used for the index. |
86 | | - filters (List[str]): Fields/paths to index to allow filtering in $vectorSearch |
87 | | - wait_until_complete (Optional[float]): If provided, number of seconds to wait |
88 | | - until search index is ready. |
89 | | - kwargs: Keyword arguments supplying any additional options to SearchIndexModel. |
90 | | - """ |
91 | | - logger.info( |
92 | | - "Updating Search Index %s from Collection: %s", index_name, collection.name |
93 | | - ) |
94 | | - collection.update_search_index( |
95 | | - name=index_name, |
96 | | - definition=_vector_search_index_definition( |
97 | | - dimensions=dimensions, |
98 | | - path=path, |
99 | | - similarity=similarity, |
100 | | - filters=filters, |
101 | | - **kwargs, |
102 | | - ), |
103 | | - ) |
104 | | - if wait_until_complete: |
105 | | - _wait_for_predicate( |
106 | | - predicate=lambda: _is_index_ready(collection, index_name), |
107 | | - err=f"Index {index_name} update did not complete in {wait_until_complete}!", |
108 | | - timeout=wait_until_complete, |
109 | | - ) |
110 | | - logger.info("Update succeeded") |
111 | | - |
112 | | - |
113 | 37 | def _is_index_ready(collection: Collection, index_name: str) -> bool: |
114 | 38 | """Check for the index name in the list of available search indexes to see if the |
115 | 39 | specified index is of status READY |
|
0 commit comments