6767
6868
6969class ElasticDocIndex (BaseDocIndex , Generic [TSchema ]):
70+ _index_vector_params : Optional [Tuple [str ]] = ('dims' , 'similarity' , 'index' )
71+ _index_vector_options : Optional [Tuple [str ]] = ('m' , 'ef_construction' )
72+
7073 def __init__ (self , db_config = None , ** kwargs ):
7174 """Initialize ElasticDocIndex"""
7275 super ().__init__ (db_config = db_config , ** kwargs )
@@ -82,9 +85,6 @@ def __init__(self, db_config=None, **kwargs):
8285 self ._logger .debug ('ElasticSearch client has been created' )
8386
8487 # ElasticSearh index setup
85- self ._index_vector_params = ('dims' , 'similarity' , 'index' )
86- self ._index_vector_options = ('m' , 'ef_construction' )
87-
8888 mappings : Dict [str , Any ] = {
8989 'dynamic' : True ,
9090 '_source' : {'enabled' : 'true' },
@@ -572,20 +572,23 @@ def _filter_by_parent_id(self, id: str) -> List[str]:
572572 # Helpers #
573573 ###############################################
574574
575- def _create_index_mapping (self , col : '_ColumnInfo' ) -> Dict [str , Any ]:
575+ @classmethod
576+ def _create_index_mapping (cls , col : '_ColumnInfo' ) -> Dict [str , Any ]:
576577 """Create a new HNSW index for a column, and initialize it."""
577578
578579 index = {'type' : col .config ['type' ] if 'type' in col .config else col .db_type }
579580
580581 if col .db_type == 'dense_vector' :
581- for k in self ._index_vector_params :
582- index [k ] = col .config [k ]
582+ if cls ._index_vector_params is not None :
583+ for k in cls ._index_vector_params :
584+ index [k ] = col .config [k ]
583585 if col .n_dim :
584586 index ['dims' ] = col .n_dim
585- index ['index_options' ] = dict (
586- (k , col .config [k ]) for k in self ._index_vector_options
587- )
588- index ['index_options' ]['type' ] = 'hnsw'
587+ if cls ._index_vector_options is not None :
588+ index ['index_options' ] = dict (
589+ (k , col .config [k ]) for k in cls ._index_vector_options
590+ )
591+ index ['index_options' ]['type' ] = 'hnsw'
589592 return index
590593
591594 def _send_requests (
0 commit comments