Skip to content

Commit

Permalink
fix: add redis lock to AnalyticdbVector init (langgenius#6859)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaozeyu <xiaozeyu.xzy@alibaba-inc.com>
  • Loading branch information
lpdink and xiaozeyu authored Aug 7, 2024
1 parent df8f8c9 commit 40c6f3c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/core/rag/datasource/vdb/analyticdb/analyticdb_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ def __init__(self, collection_name: str, config: AnalyticdbConfig):
AnalyticdbVector._init = True

def _initialize(self) -> None:
self._initialize_vector_database()
self._create_namespace_if_not_exists()
cache_key = f"vector_indexing_{self.config.instance_id}"
lock_name = f"{cache_key}_lock"
with redis_client.lock(lock_name, timeout=20):
collection_exist_cache_key = f"vector_indexing_{self.config.instance_id}"
if redis_client.get(collection_exist_cache_key):
return
self._initialize_vector_database()
self._create_namespace_if_not_exists()
redis_client.set(collection_exist_cache_key, 1, ex=3600)

def _initialize_vector_database(self) -> None:
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
Expand Down

0 comments on commit 40c6f3c

Please sign in to comment.