11from abc import abstractmethod , ABC
2- from typing import Generic , TypeVar , Union , Dict , Set , Callable , Optional , List , TYPE_CHECKING
2+ from typing import Generic , TypeVar , Union , Dict , Set , Callable , Optional , List , TYPE_CHECKING , Any
33
44from ravendb .documents .conventions import DocumentConventions
55from ravendb .documents .indexes .definitions import (
1616 SpatialOptions ,
1717 IndexFieldOptions ,
1818 IndexType ,
19+ SearchEngineType ,
1920)
2021from ravendb .documents .indexes .spatial .configuration import SpatialOptionsFactory
22+ from ravendb .documents .indexes .vector .options import VectorOptions
2123from ravendb .documents .operations .indexes import PutIndexesOperation
2224from ravendb .documents .store .definition import DocumentStoreBase
2325from ravendb .primitives import constants
@@ -40,13 +42,15 @@ def __init__(
4042 lock_mode : IndexLockMode = None ,
4143 deployment_mode : IndexDeploymentMode = None ,
4244 state : IndexState = None ,
45+ search_engine_type : SearchEngineType = None ,
4346 ):
4447 super ().__init__ ()
4548 self .conventions = conventions
4649 self .priority = priority
4750 self .lock_mode = lock_mode
4851 self .deployment_mode = deployment_mode
4952 self .state = state
53+ self .search_engine_type = search_engine_type
5054
5155 def execute (self , store : "DocumentStore" , conventions : DocumentConventions = None , database : str = None ):
5256 old_conventions = self .conventions
@@ -68,6 +72,11 @@ def execute(self, store: "DocumentStore", conventions: DocumentConventions = Non
6872 if self .deployment_mode is not None :
6973 index_definition .deployment_mode = self .deployment_mode
7074
75+ if self .search_engine_type is not None :
76+ if not index_definition .configuration :
77+ index_definition .configuration = {}
78+ index_definition .configuration ["Indexing.Static.SearchEngineType" ] = self .search_engine_type .__str__ ()
79+
7180 store .maintenance .for_database (database ).send (PutIndexesOperation (index_definition ))
7281
7382 finally :
@@ -88,6 +97,7 @@ def __init__(self):
8897 self ._index_suggestions : Set [str ] = set ()
8998 self ._term_vectors_strings : Dict [str , FieldTermVector ] = {}
9099 self ._spatial_options_strings : Dict [str , SpatialOptions ] = {}
100+ self ._vector_indexes_strings : Dict [str , VectorOptions ] = {}
91101
92102 self ._output_reduce_to_collection : Union [None , str ] = None
93103 self ._pattern_for_output_reduce_to_collection_references : Union [None , str ] = None
@@ -150,6 +160,9 @@ def _add_assembly(self, assembly: AdditionalAssembly) -> None:
150160
151161 self .additional_assemblies .add (assembly )
152162
163+ def _vector (self , field : str , vector_options : VectorOptions ) -> None :
164+ self ._vector_indexes_strings [field ] = vector_options
165+
153166
154167class AbstractIndexDefinitionBuilder (Generic [_T_IndexDefinition ]):
155168 def __init__ (self , index_name : str ):
@@ -165,6 +178,7 @@ def __init__(self, index_name: str):
165178 self .suggestions_options : Set [str ] = set ()
166179 self .term_vectors_strings : Dict [str , FieldTermVector ] = {}
167180 self .spatial_indexes_strings : Dict [str , SpatialOptions ] = {}
181+ self .vector_indexes_strings : Dict [str , VectorOptions ] = {}
168182
169183 self .lock_mode : Optional [IndexLockMode ] = None
170184 self .priority : Optional [IndexLockMode ] = None
@@ -191,7 +205,7 @@ def __apply_values(
191205 self ,
192206 index_definition : IndexDefinition ,
193207 values : Dict [str , object ],
194- action : Callable [[IndexFieldOptions , object ], None ],
208+ action : Callable [[IndexFieldOptions , Any ], None ],
195209 ) -> None :
196210 for key , value in values .items ():
197211 field = index_definition .fields .get (key , IndexFieldOptions ())
@@ -216,29 +230,33 @@ def to_index_definition(self, conventions: DocumentConventions, validate_map: bo
216230 for suggestions_option in self .suggestions_options :
217231 suggestions [suggestions_option ] = True
218232
219- def __set_indexing (options , value ):
233+ def __set_indexing (options : IndexFieldOptions , value : FieldIndexing ):
220234 options .indexing = value
221235
222- def __set_storage (options , value ):
236+ def __set_storage (options : IndexFieldOptions , value : FieldStorage ):
223237 options .storage = value
224238
225- def __set_analyzer (options , value ):
239+ def __set_analyzer (options : IndexFieldOptions , value : str ):
226240 options .analyzer = value
227241
228- def __set_term_vector (options , value ):
242+ def __set_term_vector (options : IndexFieldOptions , value : FieldTermVector ):
229243 options .term_vector = value
230244
231- def __set_spatial (options , value ):
245+ def __set_spatial (options : IndexFieldOptions , value : SpatialOptions ):
232246 options .spatial = value
233247
234- def __set_suggestions (options , value ):
248+ def __set_vector (options : IndexFieldOptions , value : VectorOptions ):
249+ options .vector = value
250+
251+ def __set_suggestions (options : IndexFieldOptions , value : bool ):
235252 options .suggestions = value
236253
237254 self .__apply_values (index_definition , self .indexes_strings , __set_indexing )
238255 self .__apply_values (index_definition , self .stores_strings , __set_storage )
239256 self .__apply_values (index_definition , self .analyzers_strings , __set_analyzer )
240257 self .__apply_values (index_definition , self .term_vectors_strings , __set_term_vector )
241258 self .__apply_values (index_definition , self .spatial_indexes_strings , __set_spatial )
259+ self .__apply_values (index_definition , self .vector_indexes_strings , __set_vector )
242260 self .__apply_values (index_definition , suggestions , __set_suggestions )
243261
244262 index_definition .additional_sources = self .additional_sources
@@ -302,6 +320,7 @@ def create_index_definition(self) -> IndexDefinition:
302320 index_definition_builder .suggestions_options = self ._index_suggestions
303321 index_definition_builder .term_vectors_strings = self ._term_vectors_strings
304322 index_definition_builder .spatial_indexes_strings = self ._spatial_options_strings
323+ index_definition_builder .vector_indexes_strings = self ._vector_indexes_strings
305324 index_definition_builder .output_reduce_to_collection = self ._output_reduce_to_collection
306325 index_definition_builder .pattern_for_output_reduce_to_collection_references = (
307326 self ._pattern_for_output_reduce_to_collection_references
0 commit comments