{"record":{"id":"321f7b2eea9308b7","repo":"microsoft/graphrag","slug":"cosmosdb-requires-the-id-field-to-be-id","errorCode":null,"errorMessage":"CosmosDB requires the id_field to be 'id'.","messagePattern":"CosmosDB requires the id_field to be 'id'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-vectors/graphrag_vectors/cosmosdb.py","lineNumber":45,"sourceCode":"\nclass CosmosDBVectorStore(VectorStore):\n    \"\"\"Azure CosmosDB vector storage implementation.\"\"\"\n\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            )","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-vectors/graphrag_vectors/cosmosdb.py#L27-L63","documentation":"The CosmosDB vector store hard-requires id_field == \"id\" because Cosmos documents' partition/identity key is the immutable 'id' property; the store maps vector record IDs onto it and cannot honor a custom id_field like other backends. The check runs first in __init__ before credential validation.","triggerScenarios":"Instantiating the CosmosDB vector store with id_field=\"text_id\" (or a config/base class default other than \"id\").","commonSituations":"Copying vector store config from a LanceDB/Postgres setup that sets a custom id_field; a base class defaulting id_field to something else that the caller didn't override.","solutions":["Remove id_field from the cosmosdb vector store config or set it to \"id\"","If a custom id_field is a hard requirement, choose a different vector backend"],"exampleFix":"# before\nCosmosDBVectorStore(id_field=\"text_id\", ...)\n# after\nCosmosDBVectorStore(id_field=\"id\", ...)  # or omit id_field","handlingStrategy":"validation","validationCode":"cfg.pop(\"id_field\", None)\ncfg[\"id_field\"] = \"id\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never carry id_field overrides into cosmosdb vector configs","Keep backend-specific config files separate"],"tags":["cosmosdb","vectors","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}