{"record":{"id":"daf7efad561790c6","repo":"microsoft/graphrag","slug":"either-connection-string-or-url-must-be-provided-f","errorCode":null,"errorMessage":"Either connection_string or url must be provided for CosmosDB.","messagePattern":"Either connection_string or url must be provided for CosmosDB\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-vectors/graphrag_vectors/cosmosdb.py","lineNumber":48,"sourceCode":"\n    _cosmos_client: CosmosClient\n    _database_client: DatabaseProxy\n    _container_client: ContainerProxy\n\n    def __init__(\n        self,\n        database_name: str,\n        connection_string: str | None = None,\n        url: str | None = None,\n        **kwargs,\n    ):\n        super().__init__(**kwargs)\n        if self.id_field != \"id\":\n            msg = \"CosmosDB requires the id_field to be 'id'.\"\n            raise ValueError(msg)\n        if not connection_string and not url:\n            msg = \"Either connection_string or url must be provided for CosmosDB.\"\n            raise ValueError(msg)\n\n        self.database_name = database_name\n        self.connection_string = connection_string\n        self.url = url\n\n    def connect(self) -> Any:\n        \"\"\"Connect to CosmosDB vector storage.\"\"\"\n        if self.connection_string:\n            self._cosmos_client = CosmosClient.from_connection_string(\n                self.connection_string\n            )\n        else:\n            self._cosmos_client = CosmosClient(\n                url=self.url, credential=DefaultAzureCredential()\n            )\n\n        self._create_database()\n        self._create_container()","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-vectors/graphrag_vectors/cosmosdb.py#L30-L66","documentation":"The CosmosDB vector store requires exactly one of connection_string or url to build its client; with both absent it cannot reach any account and __init__ raises immediately. url-mode relies on DefaultAzureCredential underneath.","triggerScenarios":"Creating the CosmosDB vector store with neither connection_string nor url — unset env vars, empty YAML values, or unresolved ${placeholders}.","commonSituations":"Deployment missing the cosmos secret; .env not loaded locally; placeholder left because the env var name doesn't match what the config expects.","solutions":["Set connection_string (env var or YAML) for key-based auth","Or set url to the account endpoint and ensure DefaultAzureCredential resolves (az login / managed identity)","Validate effective config at startup before the pipeline runs"],"exampleFix":"# before\nCosmosDBVectorStore(database_name=\"graphrag\")\n# after\nCosmosDBVectorStore(database_name=\"graphrag\", connection_string=os.environ[\"COSMOS_CONN_STR\"])","handlingStrategy":"validation","validationCode":"assert cfg.get(\"connection_string\") or cfg.get(\"url\"), \"cosmos vector store needs a credential\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize credential preflight checks","Use env templates listing every required cosmos variable"],"tags":["cosmosdb","vectors","credentials","missing-env-var"],"backgroundTag":"missing-credentials","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}