crewplus 0.2.14__tar.gz → 0.2.15__tar.gz
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.
- {crewplus-0.2.14 → crewplus-0.2.15}/PKG-INFO +1 -1
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/vectorstores/milvus/vdb_service.py +43 -6
- {crewplus-0.2.14 → crewplus-0.2.15}/pyproject.toml +1 -1
- {crewplus-0.2.14 → crewplus-0.2.15}/LICENSE +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/README.md +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/__init__.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/services/__init__.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/services/gemini_chat_model.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/services/init_services.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/services/model_load_balancer.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/utils/__init__.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/utils/schema_action.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/utils/schema_document_updater.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/vectorstores/milvus/__init__.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/docs/GeminiChatModel.md +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/docs/ModelLoadBalancer.md +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/docs/VDBService.md +0 -0
- {crewplus-0.2.14 → crewplus-0.2.15}/docs/index.md +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
299
|
-
|
|
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:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|