Get or initialize the appropriate vector database client for a specific endpoint. Uses a cache to avoid creating duplicate client instances. Args: endpoint_name: Name of the endpoint to get client for Returns: Appropriate vector database cli
(self, endpoint_name: str)
| 500 | return False |
| 501 | |
| 502 | async def get_client(self, endpoint_name: str) -> VectorDBClientInterface: |
| 503 | """ |
| 504 | Get or initialize the appropriate vector database client for a specific endpoint. |
| 505 | Uses a cache to avoid creating duplicate client instances. |
| 506 | |
| 507 | Args: |
| 508 | endpoint_name: Name of the endpoint to get client for |
| 509 | |
| 510 | Returns: |
| 511 | Appropriate vector database client |
| 512 | """ |
| 513 | if endpoint_name not in self.enabled_endpoints: |
| 514 | raise ValueError(f"Endpoint {endpoint_name} is not in enabled endpoints") |
| 515 | |
| 516 | config = self.enabled_endpoints[endpoint_name] |
| 517 | db_type = config.db_type |
| 518 | |
| 519 | # Use cache key combining db_type and endpoint |
| 520 | cache_key = f"{db_type}_{endpoint_name}" |
| 521 | |
| 522 | # Check if client already exists in cache |
| 523 | async with _client_cache_lock: |
| 524 | if cache_key in _client_cache: |
| 525 | return _client_cache[cache_key] |
| 526 | |
| 527 | # Ensure required packages are installed |
| 528 | _ensure_package_installed(db_type) |
| 529 | |
| 530 | # Create the appropriate client with dynamic imports |
| 531 | logger.debug(f"Creating new client for {db_type} with endpoint {endpoint_name}") |
| 532 | |
| 533 | try: |
| 534 | # Use preloaded module if available, otherwise load on demand |
| 535 | if db_type in _preloaded_modules: |
| 536 | client_class = _preloaded_modules[db_type] |
| 537 | client = client_class(endpoint_name) |
| 538 | elif db_type == "azure_ai_search": |
| 539 | from retrieval_providers.azure_search_client import AzureSearchClient |
| 540 | client = AzureSearchClient(endpoint_name) |
| 541 | elif db_type == "milvus": |
| 542 | from retrieval_providers.milvus_client import MilvusVectorClient |
| 543 | client = MilvusVectorClient(endpoint_name) |
| 544 | elif db_type == "opensearch": |
| 545 | from retrieval_providers.opensearch_client import OpenSearchClient |
| 546 | client = OpenSearchClient(endpoint_name) |
| 547 | elif db_type == "qdrant": |
| 548 | from retrieval_providers.qdrant import QdrantVectorClient |
| 549 | client = QdrantVectorClient(endpoint_name) |
| 550 | elif db_type == "snowflake_cortex_search": |
| 551 | from retrieval_providers.snowflake_client import SnowflakeCortexSearchClient |
| 552 | client = SnowflakeCortexSearchClient(endpoint_name) |
| 553 | elif db_type == "cloudflare_autorag": |
| 554 | from retrieval_providers.cf_autorag_client import ( |
| 555 | CloudflareAutoRAGClient, |
| 556 | ) |
| 557 | |
| 558 | client = CloudflareAutoRAGClient(endpoint_name) |
| 559 | elif db_type == "elasticsearch": |
no test coverage detected