Skip to content

Commit ad17ff9

Browse files
AlwaysBluerjiangzhijie
and
jiangzhijie
authored
Lindorm vdb bug-fix (#11790)
Co-authored-by: jiangzhijie <[email protected]>
1 parent 558ab25 commit ad17ff9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

api/core/rag/datasource/vdb/lindorm/lindorm_vector.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def to_opensearch_params(self) -> dict[str, Any]:
4949

5050

5151
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):
5353
self._routing = None
5454
self._routing_field = None
55-
if config.using_ugc:
55+
if using_ugc:
5656
routing_value: str = kwargs.get("routing_value")
5757
if routing_value is None:
5858
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
6464
super().__init__(collection_name.lower())
6565
self._client_config = config
6666
self._client = OpenSearch(**config.to_opensearch_params())
67-
self._using_ugc = config.using_ugc
67+
self._using_ugc = using_ugc
6868
self.kwargs = kwargs
6969

7070
def get_type(self) -> str:
@@ -467,12 +467,16 @@ def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings
467467
using_ugc = dify_config.USING_UGC_INDEX
468468
routing_value = None
469469
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:
471475
dimension = dataset.index_struct_dict["dimension"]
472476
index_type = dataset.index_struct_dict["index_type"]
473477
distance_type = dataset.index_struct_dict["distance_type"]
474-
index_name = f"{UGC_INDEX_PREFIX}_{dimension}_{index_type}_{distance_type}"
475478
routing_value = dataset.index_struct_dict["vector_store"]["class_prefix"]
479+
index_name = f"{UGC_INDEX_PREFIX}_{dimension}_{index_type}_{distance_type}"
476480
else:
477481
index_name = dataset.index_struct_dict["vector_store"]["class_prefix"]
478482
else:
@@ -487,11 +491,12 @@ def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings
487491
"index_type": index_type,
488492
"dimension": dimension,
489493
"distance_type": distance_type,
494+
"using_ugc": using_ugc,
490495
}
491496
dataset.index_struct = json.dumps(index_struct_dict)
492497
if using_ugc:
493498
index_name = f"{UGC_INDEX_PREFIX}_{dimension}_{index_type}_{distance_type}"
494499
routing_value = class_prefix
495500
else:
496501
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

Comments
 (0)