MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / get_client

Method get_client

AskAgent/python/core/retriever.py:502–581  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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":

Callers 5

upload_documentsMethod · 0.95
searchMethod · 0.95
search_by_urlMethod · 0.95
get_sitesMethod · 0.95

Calls 13

AzureSearchClientClass · 0.90
MilvusVectorClientClass · 0.90
OpenSearchClientClass · 0.90
QdrantVectorClientClass · 0.90
ElasticsearchClientClass · 0.90
PgVectorClientClass · 0.90
ShopifyMCPClientClass · 0.90
BingSearchClientClass · 0.90
debugMethod · 0.45

Tested by

no test coverage detected