Skip to content

Commit

Permalink
clean vector collection redis cache (#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnJyong authored Jul 21, 2024
1 parent c57b393 commit f38034e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
21 changes: 12 additions & 9 deletions api/core/rag/datasource/vdb/analyticdb/analyticdb_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,18 @@ def search_by_full_text(self, query: str, **kwargs: Any) -> list[Document]:
return documents

def delete(self) -> None:
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
request = gpdb_20160503_models.DeleteCollectionRequest(
collection=self._collection_name,
dbinstance_id=self.config.instance_id,
namespace=self.config.namespace,
namespace_password=self.config.namespace_password,
region_id=self.config.region_id,
)
self._client.delete_collection(request)
try:
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
request = gpdb_20160503_models.DeleteCollectionRequest(
collection=self._collection_name,
dbinstance_id=self.config.instance_id,
namespace=self.config.namespace,
namespace_password=self.config.namespace_password,
region_id=self.config.region_id,
)
self._client.delete_collection(request)
except Exception as e:
raise e

class AnalyticdbVectorFactory(AbstractVectorFactory):
def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings):
Expand Down
2 changes: 0 additions & 2 deletions api/core/rag/datasource/vdb/tencent/tencent_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def delete(self) -> None:
self._db.drop_collection(name=self._collection_name)




class TencentVectorFactory(AbstractVectorFactory):
def init_vector(self, dataset: Dataset, attributes: list, embeddings: Embeddings) -> TencentVector:

Expand Down
4 changes: 4 additions & 0 deletions api/core/rag/datasource/vdb/vector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ def _filter_duplicate_texts(self, texts: list[Document]) -> list[Document]:

def _get_uuids(self, texts: list[Document]) -> list[str]:
return [text.metadata['doc_id'] for text in texts]

@property
def collection_name(self):
return self._collection_name
5 changes: 5 additions & 0 deletions api/core/rag/datasource/vdb/vector_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from core.rag.datasource.vdb.vector_base import BaseVector
from core.rag.datasource.vdb.vector_type import VectorType
from core.rag.models.document import Document
from extensions.ext_redis import redis_client
from models.dataset import Dataset


Expand Down Expand Up @@ -134,6 +135,10 @@ def search_by_full_text(

def delete(self) -> None:
self._vector_processor.delete()
# delete collection redis cache
if self._vector_processor.collection_name:
collection_exist_cache_key = 'vector_indexing_{}'.format(self._vector_processor.collection_name)
redis_client.delete(collection_exist_cache_key)

def _get_embeddings(self) -> Embeddings:
model_manager = ModelManager()
Expand Down

0 comments on commit f38034e

Please sign in to comment.