crewplus 0.2.13__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.
- crewplus/vectorstores/milvus/vdb_service.py +55 -18
- {crewplus-0.2.13.dist-info → crewplus-0.2.15.dist-info}/METADATA +1 -1
- {crewplus-0.2.13.dist-info → crewplus-0.2.15.dist-info}/RECORD +6 -6
- {crewplus-0.2.13.dist-info → crewplus-0.2.15.dist-info}/WHEEL +0 -0
- {crewplus-0.2.13.dist-info → crewplus-0.2.15.dist-info}/entry_points.txt +0 -0
- {crewplus-0.2.13.dist-info → crewplus-0.2.15.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import logging
|
|
8
8
|
from typing import List, Dict, Union, Optional
|
|
9
|
-
from langchain_milvus import
|
|
9
|
+
from langchain_milvus import Milvus
|
|
10
10
|
from langchain_core.embeddings import Embeddings
|
|
11
11
|
from langchain_openai import AzureOpenAIEmbeddings
|
|
12
12
|
from pymilvus import MilvusClient
|
|
@@ -60,8 +60,8 @@ class VDBService(object):
|
|
|
60
60
|
... }
|
|
61
61
|
... },
|
|
62
62
|
... "index_params": {
|
|
63
|
-
... "metric_type": "
|
|
64
|
-
... "index_type": "
|
|
63
|
+
... "metric_type": "IP",
|
|
64
|
+
... "index_type": "HNSW",
|
|
65
65
|
... "params": {}
|
|
66
66
|
... }
|
|
67
67
|
... }
|
|
@@ -83,7 +83,7 @@ class VDBService(object):
|
|
|
83
83
|
>>> assert vector_store is same_vector_store
|
|
84
84
|
"""
|
|
85
85
|
_client: MilvusClient
|
|
86
|
-
_instances: Dict[str,
|
|
86
|
+
_instances: Dict[str, Milvus] = {}
|
|
87
87
|
|
|
88
88
|
schema: str
|
|
89
89
|
embedding_function: Embeddings
|
|
@@ -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,7 +275,32 @@ 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
|
|
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
|
+
|
|
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.
|
|
281
306
|
This method validates both the embedding function and the vector store connection
|
|
@@ -284,26 +309,38 @@ class VDBService(object):
|
|
|
284
309
|
Args:
|
|
285
310
|
collection_name (str): The name of the collection in the vector database.
|
|
286
311
|
embeddings (Embeddings, optional): An embedding model instance. If None, one is created.
|
|
287
|
-
metric_type (str): The distance metric for the index. Defaults to "
|
|
312
|
+
metric_type (str): The distance metric for the index. Defaults to "IP".
|
|
288
313
|
|
|
289
314
|
Returns:
|
|
290
|
-
|
|
315
|
+
Milvus: LangChain Milvus instance, which is compatible with both Zilliz and Milvus.
|
|
291
316
|
"""
|
|
292
317
|
if not collection_name:
|
|
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:
|
|
@@ -317,14 +354,14 @@ class VDBService(object):
|
|
|
317
354
|
)
|
|
318
355
|
raise RuntimeError(f"Invalid embedding function provided.") from e
|
|
319
356
|
|
|
320
|
-
# If embeddings are valid, proceed to create the
|
|
357
|
+
# If embeddings are valid, proceed to create the Milvus instance.
|
|
321
358
|
index_params = self.index_params or {
|
|
322
359
|
"metric_type": metric_type,
|
|
323
360
|
"index_type": "AUTOINDEX",
|
|
324
361
|
"params": {}
|
|
325
362
|
}
|
|
326
363
|
|
|
327
|
-
vdb =
|
|
364
|
+
vdb = Milvus(
|
|
328
365
|
embedding_function=embeddings,
|
|
329
366
|
collection_name=collection_name,
|
|
330
367
|
connection_args=self.connection_args,
|
|
@@ -336,12 +373,12 @@ class VDBService(object):
|
|
|
336
373
|
|
|
337
374
|
return vdb
|
|
338
375
|
|
|
339
|
-
def delete_old_indexes(self, url: str = None, vdb:
|
|
376
|
+
def delete_old_indexes(self, url: str = None, vdb: Milvus = None) -> (bool | None):
|
|
340
377
|
""" Delete old indexes of the same source_url
|
|
341
378
|
|
|
342
379
|
Args:
|
|
343
380
|
url (str): source url
|
|
344
|
-
vdb (
|
|
381
|
+
vdb (Milvus): Milvus/Zilliz instance
|
|
345
382
|
"""
|
|
346
383
|
self.logger.info(f"Delete old indexes of the same source_url:{url}")
|
|
347
384
|
|
|
@@ -358,7 +395,7 @@ class VDBService(object):
|
|
|
358
395
|
self.logger.info("Deleted old indexes result: " + str(res))
|
|
359
396
|
return res
|
|
360
397
|
|
|
361
|
-
def delete_old_indexes_by_id(self, source_id: str = None, vdb:
|
|
398
|
+
def delete_old_indexes_by_id(self, source_id: str = None, vdb: Milvus = None) -> (bool | None):
|
|
362
399
|
""" Delete old indexes of the same source_id
|
|
363
400
|
|
|
364
401
|
Args:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
crewplus-0.2.
|
|
2
|
-
crewplus-0.2.
|
|
3
|
-
crewplus-0.2.
|
|
4
|
-
crewplus-0.2.
|
|
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=
|
|
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.
|
|
21
|
+
crewplus-0.2.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|