crewplus 0.2.53__tar.gz → 0.2.55__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.

Files changed (24) hide show
  1. {crewplus-0.2.53 → crewplus-0.2.55}/PKG-INFO +1 -1
  2. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/vectorstores/milvus/vdb_service.py +49 -12
  3. {crewplus-0.2.53 → crewplus-0.2.55}/pyproject.toml +1 -1
  4. {crewplus-0.2.53 → crewplus-0.2.55}/LICENSE +0 -0
  5. {crewplus-0.2.53 → crewplus-0.2.55}/README.md +0 -0
  6. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/__init__.py +0 -0
  7. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/callbacks/__init__.py +0 -0
  8. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/callbacks/async_langfuse_handler.py +0 -0
  9. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/__init__.py +0 -0
  10. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/azure_chat_model.py +0 -0
  11. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/gemini_chat_model.py +0 -0
  12. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/init_services.py +0 -0
  13. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/model_load_balancer.py +0 -0
  14. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/services/tracing_manager.py +0 -0
  15. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/utils/__init__.py +0 -0
  16. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/utils/schema_action.py +0 -0
  17. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/utils/schema_document_updater.py +0 -0
  18. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/vectorstores/milvus/__init__.py +0 -0
  19. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
  20. {crewplus-0.2.53 → crewplus-0.2.55}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
  21. {crewplus-0.2.53 → crewplus-0.2.55}/docs/GeminiChatModel.md +0 -0
  22. {crewplus-0.2.53 → crewplus-0.2.55}/docs/ModelLoadBalancer.md +0 -0
  23. {crewplus-0.2.53 → crewplus-0.2.55}/docs/VDBService.md +0 -0
  24. {crewplus-0.2.53 → crewplus-0.2.55}/docs/index.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.53
3
+ Version: 0.2.55
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -95,6 +95,7 @@ class VDBService(object):
95
95
  _client: MilvusClient
96
96
  _async_client: AsyncMilvusClient
97
97
  _instances: Dict[str, Milvus] = {}
98
+ _async_instances: Dict[str, Milvus] = {}
98
99
 
99
100
  schema: str
100
101
  embedding_function: Embeddings
@@ -255,6 +256,30 @@ class VDBService(object):
255
256
  """
256
257
  return self._async_client
257
258
 
259
+ def get_vector_field(self, collection_name: str) -> str:
260
+ """
261
+ Retrieves the vector field name for a given collection from a cached instance.
262
+
263
+ Args:
264
+ collection_name (str): The name of the collection.
265
+
266
+ Returns:
267
+ str: The name of the vector field.
268
+
269
+ Raises:
270
+ ValueError: If no cached instance is found for the collection.
271
+ """
272
+ if collection_name in self._instances:
273
+ return self._instances[collection_name]._vector_field
274
+ if collection_name in self._async_instances:
275
+ return self._async_instances[collection_name]._vector_field
276
+
277
+ self.logger.warning(f"No cached instance found for collection '{collection_name}' to get vector field. Creating a temporary sync instance.")
278
+ # As a fallback, create a temporary sync instance to fetch the schema info.
279
+ # This is less efficient but ensures the method is robust.
280
+ temp_instance = self.get_vector_store(collection_name)
281
+ return temp_instance._vector_field
282
+
258
283
  def get_embeddings(self, from_model_balancer: bool = False, provider: Optional[str] = "azure-openai", model_type: Optional[str] = "embedding-large") -> Embeddings:
259
284
  """
260
285
  Gets an embedding function, either from the model balancer or directly from settings.
@@ -482,21 +507,21 @@ class VDBService(object):
482
507
  raise ValueError("collection_name must be provided.")
483
508
 
484
509
  check_existence = True
485
- if collection_name in self._instances:
486
- instance = self._instances[collection_name]
510
+ if collection_name in self._async_instances:
511
+ instance = self._async_instances[collection_name]
487
512
  is_connected, collection_exists = await self._ais_good_connection(instance, collection_name)
488
513
 
489
514
  if is_connected and collection_exists:
490
- self.logger.info(f"Returning existing vector store instance for collection: {collection_name}")
515
+ self.logger.info(f"Returning existing async vector store instance for collection: {collection_name}")
491
516
  return instance
492
517
 
493
- self.logger.warning(f"Cached instance for '{collection_name}' is invalid. Removing it from cache.")
494
- del self._instances[collection_name]
518
+ self.logger.warning(f"Cached async instance for '{collection_name}' is invalid. Removing it from cache.")
519
+ del self._async_instances[collection_name]
495
520
 
496
521
  if is_connected and not collection_exists:
497
522
  check_existence = False
498
523
 
499
- self.logger.info(f"Creating new vector store instance for collection: {collection_name}")
524
+ self.logger.info(f"Creating new async vector store instance for collection: {collection_name}")
500
525
  if embeddings is None:
501
526
  embeddings = self.get_embeddings()
502
527
 
@@ -519,28 +544,40 @@ class VDBService(object):
519
544
  "params": {}
520
545
  }
521
546
 
547
+ # For async, we MUST instantiate Milvus with a sync alias because its __init__ is sync.
548
+ # Then, we hot-swap the client and alias for async operations.
549
+ sync_connection_args = self.connection_args.copy()
550
+ sync_connection_args["alias"] = self.sync_alias
551
+
522
552
  vdb = await asyncio.to_thread(
523
553
  self._create_milvus_instance_with_retry,
524
554
  collection_name=collection_name,
525
555
  embeddings=embeddings,
526
- index_params=index_params
556
+ index_params=index_params,
557
+ connection_args=sync_connection_args
527
558
  )
528
559
 
529
- self._instances[collection_name] = vdb
560
+ # Hot-swap to the async client and alias for async operations.
561
+ self.logger.debug(f"Swapping to async client for instance of collection {collection_name}")
562
+ vdb.alias = self.async_alias
563
+ vdb.aclient = self._async_client
564
+
565
+ self._async_instances[collection_name] = vdb
530
566
 
531
567
  return vdb
532
568
 
533
- def _create_milvus_instance_with_retry(self, collection_name: str, embeddings: Embeddings, index_params: dict) -> Milvus:
569
+ def _create_milvus_instance_with_retry(self, collection_name: str, embeddings: Embeddings, index_params: dict, connection_args: Optional[dict] = None) -> Milvus:
534
570
  """
535
571
  Creates a Milvus instance with a retry mechanism for connection failures.
536
572
  """
537
573
  retries = 2
574
+ conn_args = connection_args if connection_args is not None else self.connection_args
538
575
  for attempt in range(retries + 1):
539
576
  try:
540
577
  vdb = Milvus(
541
578
  embedding_function=embeddings,
542
579
  collection_name=collection_name,
543
- connection_args=self.connection_args,
580
+ connection_args=conn_args,
544
581
  index_params=index_params
545
582
  )
546
583
  self.logger.info(f"Successfully connected to Milvus for collection '{collection_name}' on attempt {attempt + 1}.")
@@ -612,8 +649,8 @@ class VDBService(object):
612
649
  raise RuntimeError(f"An error occurred while dropping collection '{collection_name}' asynchronously.") from e
613
650
  finally:
614
651
  # Whether successful or not, remove the stale instance from the cache.
615
- if collection_name in self._instances:
616
- del self._instances[collection_name]
652
+ if collection_name in self._async_instances:
653
+ del self._async_instances[collection_name]
617
654
  self.logger.info(f"Removed '{collection_name}' from instance cache.")
618
655
 
619
656
  def delete_data_by_filter(self, collection_name: str = None, filter: str = None) -> None:
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "crewplus"
9
- version = "0.2.53"
9
+ version = "0.2.55"
10
10
  description = "Base services for CrewPlus AI applications"
11
11
  authors = [
12
12
  { name = "Tim Liu", email = "tim@opsmateai.com" },
File without changes
File without changes
File without changes
File without changes