@@ -74,58 +74,57 @@ def connect(self, **kwargs: Any) -> Any:
7474 not_supported_error = "Azure AI Search expects `url`."
7575 raise ValueError (not_supported_error )
7676
77- def load_documents (
78- self , documents : list [VectorStoreDocument ], overwrite : bool = True
79- ) -> None :
77+ def create_index (self ) -> None :
8078 """Load documents into an Azure AI Search index."""
81- if overwrite :
82- if (
83- self .index_name is not None
84- and self .index_name in self .index_client .list_index_names ()
85- ):
86- self .index_client .delete_index (self .index_name )
87-
88- # Configure vector search profile
89- vector_search = VectorSearch (
90- algorithms = [
91- HnswAlgorithmConfiguration (
92- name = "HnswAlg" ,
93- parameters = HnswParameters (
94- metric = VectorSearchAlgorithmMetric .COSINE
95- ),
96- )
97- ],
98- profiles = [
99- VectorSearchProfile (
100- name = self .vector_search_profile_name ,
101- algorithm_configuration_name = "HnswAlg" ,
102- )
103- ],
104- )
105- # Configure the index
106- index = SearchIndex (
107- name = self .index_name if self .index_name else "" ,
108- fields = [
109- SimpleField (
110- name = self .id_field ,
111- type = SearchFieldDataType .String ,
112- key = True ,
113- ),
114- SearchField (
115- name = self .vector_field ,
116- type = SearchFieldDataType .Collection (SearchFieldDataType .Single ),
117- searchable = True ,
118- hidden = False , # DRIFT needs to return the vector for client-side similarity
119- vector_search_dimensions = self .vector_size ,
120- vector_search_profile_name = self .vector_search_profile_name ,
79+ if (
80+ self .index_name is not None
81+ and self .index_name in self .index_client .list_index_names ()
82+ ):
83+ self .index_client .delete_index (self .index_name )
84+
85+ # Configure vector search profile
86+ vector_search = VectorSearch (
87+ algorithms = [
88+ HnswAlgorithmConfiguration (
89+ name = "HnswAlg" ,
90+ parameters = HnswParameters (
91+ metric = VectorSearchAlgorithmMetric .COSINE
12192 ),
122- ],
123- vector_search = vector_search ,
124- )
125- self .index_client .create_or_update_index (
126- index ,
127- )
93+ )
94+ ],
95+ profiles = [
96+ VectorSearchProfile (
97+ name = self .vector_search_profile_name ,
98+ algorithm_configuration_name = "HnswAlg" ,
99+ )
100+ ],
101+ )
102+ # Configure the index
103+ index = SearchIndex (
104+ name = self .index_name if self .index_name else "" ,
105+ fields = [
106+ SimpleField (
107+ name = self .id_field ,
108+ type = SearchFieldDataType .String ,
109+ key = True ,
110+ ),
111+ SearchField (
112+ name = self .vector_field ,
113+ type = SearchFieldDataType .Collection (SearchFieldDataType .Single ),
114+ searchable = True ,
115+ hidden = False , # DRIFT needs to return the vector for client-side similarity
116+ vector_search_dimensions = self .vector_size ,
117+ vector_search_profile_name = self .vector_search_profile_name ,
118+ ),
119+ ],
120+ vector_search = vector_search ,
121+ )
122+ self .index_client .create_or_update_index (
123+ index ,
124+ )
128125
126+ def load_documents (self , documents : list [VectorStoreDocument ]) -> None :
127+ """Load documents into an Azure AI Search index."""
129128 batch = [
130129 {
131130 self .id_field : doc .id ,
0 commit comments