@@ -49,10 +49,10 @@ def to_opensearch_params(self) -> dict[str, Any]:
49
49
50
50
51
51
class LindormVectorStore (BaseVector ):
52
- def __init__ (self , collection_name : str , config : LindormVectorStoreConfig , ** kwargs ):
52
+ def __init__ (self , collection_name : str , config : LindormVectorStoreConfig , using_ugc : bool , ** kwargs ):
53
53
self ._routing = None
54
54
self ._routing_field = None
55
- if config . using_ugc :
55
+ if using_ugc :
56
56
routing_value : str = kwargs .get ("routing_value" )
57
57
if routing_value is None :
58
58
raise ValueError ("UGC index should init vector with valid 'routing_value' parameter value" )
@@ -64,7 +64,7 @@ def __init__(self, collection_name: str, config: LindormVectorStoreConfig, **kwa
64
64
super ().__init__ (collection_name .lower ())
65
65
self ._client_config = config
66
66
self ._client = OpenSearch (** config .to_opensearch_params ())
67
- self ._using_ugc = config . using_ugc
67
+ self ._using_ugc = using_ugc
68
68
self .kwargs = kwargs
69
69
70
70
def get_type (self ) -> str :
@@ -467,12 +467,16 @@ def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings
467
467
using_ugc = dify_config .USING_UGC_INDEX
468
468
routing_value = None
469
469
if dataset .index_struct :
470
- if using_ugc :
470
+ # if an existed record's index_struct_dict doesn't contain using_ugc field,
471
+ # it actually stores in the normal index format
472
+ stored_in_ugc = dataset .index_struct_dict .get ("using_ugc" , False )
473
+ using_ugc = stored_in_ugc
474
+ if stored_in_ugc :
471
475
dimension = dataset .index_struct_dict ["dimension" ]
472
476
index_type = dataset .index_struct_dict ["index_type" ]
473
477
distance_type = dataset .index_struct_dict ["distance_type" ]
474
- index_name = f"{ UGC_INDEX_PREFIX } _{ dimension } _{ index_type } _{ distance_type } "
475
478
routing_value = dataset .index_struct_dict ["vector_store" ]["class_prefix" ]
479
+ index_name = f"{ UGC_INDEX_PREFIX } _{ dimension } _{ index_type } _{ distance_type } "
476
480
else :
477
481
index_name = dataset .index_struct_dict ["vector_store" ]["class_prefix" ]
478
482
else :
@@ -487,11 +491,12 @@ def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings
487
491
"index_type" : index_type ,
488
492
"dimension" : dimension ,
489
493
"distance_type" : distance_type ,
494
+ "using_ugc" : using_ugc ,
490
495
}
491
496
dataset .index_struct = json .dumps (index_struct_dict )
492
497
if using_ugc :
493
498
index_name = f"{ UGC_INDEX_PREFIX } _{ dimension } _{ index_type } _{ distance_type } "
494
499
routing_value = class_prefix
495
500
else :
496
501
index_name = class_prefix
497
- return LindormVectorStore (index_name , lindorm_config , routing_value = routing_value )
502
+ return LindormVectorStore (index_name , lindorm_config , routing_value = routing_value , using_ugc = using_ugc )
0 commit comments