crewplus 0.2.14__py3-none-any.whl → 0.2.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of crewplus might be problematic. Click here for more details.

@@ -245,7 +245,7 @@ class VDBService(object):
245
245
  self.logger.error(f"Unsupported embedding provider: {provider}")
246
246
  raise NotImplementedError(f"Embedding provider '{provider}' is not supported yet.")
247
247
 
248
- def _ensure_collection_exists(self, collection_name: str, embeddings: Embeddings):
248
+ def _ensure_collection_exists(self, collection_name: str, embeddings: Embeddings, check_existence: bool = True):
249
249
  """
250
250
  Checks if a collection exists and creates it if it doesn't.
251
251
  This operation is wrapped in a try-except block to handle potential failures
@@ -253,7 +253,7 @@ class VDBService(object):
253
253
  """
254
254
  try:
255
255
  client = self.get_vector_client()
256
- if not client.has_collection(collection_name):
256
+ if check_existence and not client.has_collection(collection_name):
257
257
  self.logger.info(f"Collection '{collection_name}' does not exist. Creating it.")
258
258
 
259
259
  schema_milvus = SchemaMilvus(
@@ -275,6 +275,31 @@ class VDBService(object):
275
275
  self.logger.error(f"An error occurred while ensuring collection '{collection_name}' : {e}")
276
276
  raise RuntimeError(f"Failed to ensure collection '{collection_name}' .") from e
277
277
 
278
+ def _is_good_connection(self, vdb_instance: Milvus, collection_name: str) -> tuple[bool, bool | None]:
279
+ """
280
+ Checks if the Milvus instance has a good connection by verifying collection existence.
281
+
282
+ Args:
283
+ vdb_instance (Milvus): The cached vector store instance.
284
+ collection_name (str): The name of the collection to check.
285
+
286
+ Returns:
287
+ tuple[bool, bool | None]: A tuple of (is_connected, collection_exists).
288
+ collection_exists is None if the connection failed.
289
+ """
290
+ try:
291
+ # Use has_collection as a lightweight way to verify the connection and collection status.
292
+ # If the server is unreachable, this will raise an exception.
293
+ collection_exists = vdb_instance.client.has_collection(collection_name)
294
+ if collection_exists:
295
+ self.logger.debug(f"Connection for cached instance of '{collection_name}' is alive.")
296
+ else:
297
+ self.logger.warning(f"Collection '{collection_name}' not found for cached instance. It may have been dropped.")
298
+ return True, collection_exists
299
+ except Exception as e:
300
+ self.logger.warning(f"Connection check failed for cached instance of '{collection_name}': {e}")
301
+ return False, None
302
+
278
303
  def get_vector_store(self, collection_name: str, embeddings: Embeddings = None, metric_type: str = "IP") -> Milvus:
279
304
  """
280
305
  Gets a vector store instance, creating it if it doesn't exist for the collection.
@@ -293,17 +318,29 @@ class VDBService(object):
293
318
  self.logger.error("get_vector_store called with no collection_name.")
294
319
  raise ValueError("collection_name must be provided.")
295
320
 
296
- # Return the cached instance if it already exists.
321
+ check_existence = True
322
+ # Check for a cached instance and validate its connection before returning.
297
323
  if collection_name in self._instances:
298
- self.logger.info(f"Returning existing vector store instance for collection: {collection_name}")
299
- return self._instances[collection_name]
324
+ instance = self._instances[collection_name]
325
+ is_connected, collection_exists = self._is_good_connection(instance, collection_name)
326
+
327
+ if is_connected and collection_exists:
328
+ self.logger.info(f"Returning existing vector store instance for collection: {collection_name}")
329
+ return instance
330
+
331
+ self.logger.warning(f"Cached instance for '{collection_name}' is invalid. Removing it from cache.")
332
+ del self._instances[collection_name]
333
+
334
+ if is_connected and not collection_exists:
335
+ # We know the collection doesn't exist, so no need to check again.
336
+ check_existence = False
300
337
 
301
338
  self.logger.info(f"Creating new vector store instance for collection: {collection_name}")
302
339
  if embeddings is None:
303
340
  embeddings = self.get_embeddings()
304
341
 
305
342
  # Ensure the collection exists before proceeding.
306
- self._ensure_collection_exists(collection_name, embeddings)
343
+ self._ensure_collection_exists(collection_name, embeddings, check_existence=check_existence)
307
344
 
308
345
  # 1. Validate the embedding function before proceeding.
309
346
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.14
3
+ Version: 0.2.15
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- crewplus-0.2.14.dist-info/METADATA,sha256=r1Czargd06hF_rDNnysOU4sH2mFoq6qczAb_fSQijoU,5087
2
- crewplus-0.2.14.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- crewplus-0.2.14.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- crewplus-0.2.14.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
1
+ crewplus-0.2.15.dist-info/METADATA,sha256=UsIzsZEpV38aiw_SP-wLsjA3bcEYf4Q3lp3oEzcLSaI,5087
2
+ crewplus-0.2.15.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ crewplus-0.2.15.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ crewplus-0.2.15.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
5
5
  crewplus/__init__.py,sha256=m46HkZL1Y4toD619NL47Sn2Qe084WFFSFD7e6VoYKZc,284
6
6
  crewplus/services/__init__.py,sha256=ra_ciHcJN_sbv7q8UCP2kY91SbD32-QBpQLRgIosEcE,267
7
7
  crewplus/services/gemini_chat_model.py,sha256=i9p5KvSJYaHSUBLPKM_bpyGVLWCDQoNeah_WjQVJRXs,26227
@@ -13,9 +13,9 @@ crewplus/utils/schema_document_updater.py,sha256=frvffxn2vbi71fHFPoGb9hq7gH2azmm
13
13
  crewplus/vectorstores/milvus/__init__.py,sha256=egGncAdjlXG6ekTQvKMKqhvKBifrUrPlsSB0-bpvq4A,229
14
14
  crewplus/vectorstores/milvus/milvus_schema_manager.py,sha256=2IZT61LVui21Pt5Z3y8YYS2dYcwzkgUKxMq2NA0-lQE,9222
15
15
  crewplus/vectorstores/milvus/schema_milvus.py,sha256=IvKdUCH451HJ-F3TUR5jDjqwQlQs4SEXAQ_th4JAnfc,12117
16
- crewplus/vectorstores/milvus/vdb_service.py,sha256=i-imqk4tnIXkf5O406lHaq5H7YSPy8UZhqN1o5NpanI,19194
16
+ crewplus/vectorstores/milvus/vdb_service.py,sha256=ojKzwk_SIXw89nJIeMa9fi_IbtWe96HB__hlmwEAn0s,21287
17
17
  docs/GeminiChatModel.md,sha256=_IQyup3ofAa2HxfSurO1GYUEezTHYYt5Q1khYNVThGM,8040
18
18
  docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
19
19
  docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
20
20
  docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
21
- crewplus-0.2.14.dist-info/RECORD,,
21
+ crewplus-0.2.15.dist-info/RECORD,,