@@ -34,60 +34,6 @@ def _vector_search_index_definition(
3434 return definition
3535
3636
37- def create_vector_search_index (
38- collection : Collection ,
39- index_name : str ,
40- dimensions : int ,
41- path : str ,
42- similarity : str ,
43- filters : Optional [List [str ]] = None ,
44- * ,
45- wait_until_complete : Optional [float ] = None ,
46- ** kwargs : Any ,
47- ) -> None :
48- """Experimental Utility function to create a vector search index
49-
50- Args:
51- collection (Collection): MongoDB Collection
52- index_name (str): Name of Index
53- dimensions (int): Number of dimensions in embedding
54- path (str): field with vector embedding
55- similarity (str): The similarity score used for the index
56- filters (List[str]): Fields/paths to index to allow filtering in $vectorSearch
57- wait_until_complete (Optional[float]): If provided, number of seconds to wait
58- until search index is ready.
59- kwargs: Keyword arguments supplying any additional options to SearchIndexModel.
60- """
61- logger .info ("Creating Search Index %s on %s" , index_name , collection .name )
62-
63- if collection .name not in collection .database .list_collection_names (
64- authorizedCollections = True
65- ):
66- collection .database .create_collection (collection .name )
67-
68- result = collection .create_search_index (
69- SearchIndexModel (
70- definition = _vector_search_index_definition (
71- dimensions = dimensions ,
72- path = path ,
73- similarity = similarity ,
74- filters = filters ,
75- ** kwargs ,
76- ),
77- name = index_name ,
78- type = "vectorSearch" ,
79- )
80- )
81-
82- if wait_until_complete :
83- _wait_for_predicate (
84- predicate = lambda : _is_index_ready (collection , index_name ),
85- err = f"{ index_name = } did not complete in { wait_until_complete } !" ,
86- timeout = wait_until_complete ,
87- )
88- logger .info (result )
89-
90-
9137def drop_vector_search_index (
9238 collection : Collection ,
9339 index_name : str ,
0 commit comments