{"record":{"id":"0a68392b8ee08177","repo":"stanford-oval/storm","slug":"qdrant-client-is-not-initialized","errorCode":null,"errorMessage":"Qdrant client is not initialized.","messagePattern":"Qdrant client is not initialized\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"knowledge_storm/rm.py","lineNumber":235,"sourceCode":"        encode_kwargs = {\"normalize_embeddings\": True}\n        self.model = HuggingFaceEmbeddings(\n            model_name=embedding_model,\n            model_kwargs=model_kwargs,\n            encode_kwargs=encode_kwargs,\n        )\n\n        self.collection_name = collection_name\n        self.client = None\n        self.qdrant = None\n\n    def _check_collection(self):\n        from langchain_qdrant import Qdrant\n\n        \"\"\"\n        Check if the Qdrant collection exists and create it if it does not.\n        \"\"\"\n        if self.client is None:\n            raise ValueError(\"Qdrant client is not initialized.\")\n        if self.client.collection_exists(collection_name=f\"{self.collection_name}\"):\n            print(\n                f\"Collection {self.collection_name} exists. Loading the collection...\"\n            )\n            self.qdrant = Qdrant(\n                client=self.client,\n                collection_name=self.collection_name,\n                embeddings=self.model,\n            )\n        else:\n            raise ValueError(\n                f\"Collection {self.collection_name} does not exist. Please create the collection first.\"\n            )\n\n    def init_online_vector_db(self, url: str, api_key: str):\n        from qdrant_client import QdrantClient\n\n        \"\"\"","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/knowledge_storm/rm.py#L217-L253","documentation":"VectorRM._check_collection verifies self.client exists before querying collection_exists. The client is only assigned inside init_online_vector_db or init_offline_vector_db, so if _check_collection runs before those methods, self.client is still None (its __init__ default) and a ValueError is raised.","triggerScenarios":"Calling rm._check_collection() directly, or a code path where init_online_vector_db/init_offline_vector_db raised or was skipped (e.g. caught exception) before _check_collection is invoked; misordered initialization in a subclass override.","commonSituations":"Subclassing VectorRM and overriding init methods without setting self.client; swallowing the exception from init_online_vector_db and continuing; calling private internals directly in tests.","solutions":["Initialize the client first via rm.init_online_vector_db(url, api_key) or rm.init_offline_vector_db(path) before any other operation","If subclassing, ensure the overridden init methods assign self.client = QdrantClient(...)","Do not call the private _check_collection yourself; let the init methods do it"],"exampleFix":"// before\nrm = VectorRM(collection_name='docs', source='offline', vector_store_path='./qdrant', embedding_model='...')\nrm._check_collection()  # client is None\n// after\nrm = VectorRM(...)\nrm.init_offline_vector_db('./qdrant')  # sets self.client and runs _check_collection","handlingStrategy":"validation","validationCode":"rm = VectorRM(collection_name='docs', source='offline', vector_store_path='./qdrant', embedding_model=MODEL)\nassert rm.client is not None or True  # client is set only after init\nrm.init_offline_vector_db('./qdrant')  # this sets self.client\nassert rm.client is not None and rm.qdrant is not None","typeGuard":"def vectorrm_ready(rm) -> bool:\n    return getattr(rm, 'client', None) is not None and getattr(rm, 'qdrant', None) is not None","tryCatchPattern":"try:\n    rm.init_offline_vector_db('./qdrant')\nexcept ValueError as e:\n    if 'not initialized' in str(e):\n        raise SystemExit('Initialize client via init_online/offline_vector_db first')\n    raise","preventionTips":["Never call private methods like _check_collection directly","Always run init_online_vector_db or init_offline_vector_db immediately after construction"],"tags":["python","qdrant","initialization","vector-database"],"backgroundTag":"uninitialized-client","analyzedSha":"fb951af7744dab086e34962e9bc6fe878e145f83","analyzedAt":"2026-08-28T11:56:54.780Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}