Feat/vdb migrate command (#2562)

Co-authored-by: jyong <jyong@dify.ai>
This commit is contained in:
Jyong
2024-02-26 19:47:29 +08:00
committed by GitHub
parent d93288f711
commit 0620fa3094
5 changed files with 134 additions and 57 deletions

View File

@@ -127,9 +127,15 @@ class MilvusVector(BaseVector):
self._client.delete(collection_name=self._collection_name, pks=doc_ids)
def delete(self) -> None:
alias = uuid4().hex
if self._client_config.secure:
uri = "https://" + str(self._client_config.host) + ":" + str(self._client_config.port)
else:
uri = "http://" + str(self._client_config.host) + ":" + str(self._client_config.port)
connections.connect(alias=alias, uri=uri, user=self._client_config.user, password=self._client_config.password)
from pymilvus import utility
utility.drop_collection(self._collection_name, None)
utility.drop_collection(self._collection_name, None, using=alias)
def text_exists(self, id: str) -> bool:

View File

@@ -1,3 +1,4 @@
import json
from typing import Any, cast
from flask import current_app
@@ -39,6 +40,11 @@ class Vector:
else:
dataset_id = self._dataset.id
collection_name = "Vector_index_" + dataset_id.replace("-", "_") + '_Node'
index_struct_dict = {
"type": 'weaviate',
"vector_store": {"class_prefix": collection_name}
}
self._dataset.index_struct = json.dumps(index_struct_dict)
return WeaviateVector(
collection_name=collection_name,
config=WeaviateConfig(
@@ -66,6 +72,13 @@ class Vector:
dataset_id = self._dataset.id
collection_name = "Vector_index_" + dataset_id.replace("-", "_") + '_Node'
if not self._dataset.index_struct_dict:
index_struct_dict = {
"type": 'qdrant',
"vector_store": {"class_prefix": collection_name}
}
self._dataset.index_struct = json.dumps(index_struct_dict)
return QdrantVector(
collection_name=collection_name,
group_id=self._dataset.id,
@@ -84,6 +97,11 @@ class Vector:
else:
dataset_id = self._dataset.id
collection_name = "Vector_index_" + dataset_id.replace("-", "_") + '_Node'
index_struct_dict = {
"type": 'milvus',
"vector_store": {"class_prefix": collection_name}
}
self._dataset.index_struct = json.dumps(index_struct_dict)
return MilvusVector(
collection_name=collection_name,
config=MilvusConfig(

View File

@@ -127,7 +127,10 @@ class WeaviateVector(BaseVector):
)
def delete(self):
self._client.schema.delete_class(self._collection_name)
# check whether the index already exists
schema = self._default_schema(self._collection_name)
if self._client.schema.contains(schema):
self._client.schema.delete_class(self._collection_name)
def text_exists(self, id: str) -> bool:
collection_name = self._collection_name