{"record":{"id":"d6da711345169e02","repo":"microsoft/semantic-kernel","slug":"the-collection-name-is-required-can-be-passed-dir","errorCode":null,"errorMessage":"The collection name is required, can be passed directly or through the data model.","messagePattern":"The collection name is required, can be passed directly or through the data model\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":319,"sourceCode":"            record_type: The type of the data model.\n            definition: The model definition, optional.\n            collection_name: The name of the collection, optional.\n            embedding_generator: The embedding generator to use for generating embeddings.\n            mongo_client: The MongoDB client for interacting with Azure CosmosDB for MongoDB,\n                used for creating and deleting collections.\n            connection_string: The connection string for MongoDB Atlas, optional.\n            Can be read from environment variables.\n            database_name: The name of the database, will be filled from the env when this is not set.\n            connection_string: str | None = None,\n            env_file_path: str | None = None,\n            env_file_encoding: str | None = None\n            **kwargs: Additional keyword arguments\n\n        \"\"\"\n        if not collection_name:\n            collection_name = _get_collection_name_from_model(record_type, definition)\n        if not collection_name:\n            raise VectorStoreInitializationException(\n                \"The collection name is required, can be passed directly or through the data model.\"\n            )\n        managed_client = not mongo_client\n        if mongo_client:\n            super().__init__(\n                record_type=record_type,\n                definition=definition,\n                mongo_client=mongo_client,\n                collection_name=collection_name,\n                database_name=database_name or DEFAULT_DB_NAME,\n                managed_client=managed_client,\n                embedding_generator=embedding_generator,\n            )\n            return\n\n        try:\n            settings = CosmosMongoSettings(\n                env_file_path=env_file_path,","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L301-L337","documentation":"CosmosMongoCollection requires a collection name either passed explicitly or derivable from the record type's data model (via a collection_name attribute or decorator metadata). When neither is present, the constructor cannot proceed and raises a VectorStoreInitializationException. This is an initialization-time guard, not a runtime failure.","triggerScenarios":"Raised in CosmosMongoCollection.__init__ when collection_name is falsy AND _get_collection_name_from_model(record_type, definition) also returns falsy. Happens when you instantiate CosmosMongoCollection(record_type=MyModel) without collection_name and MyModel has no collection_name metadata (no @vectorstoremodel(collection_name=...) and no class attribute).","commonSituations":"Forgetting to pass collection_name when the model class wasn't decorated with a name. Renaming or removing the decorator metadata. Using a plain dataclass / pydantic model as record_type that was never registered as a vector store model.","solutions":["Pass collection_name explicitly to the CosmosMongoCollection constructor.","Decorate the model with @vectorstoremodel(collection_name=\"my_collection\") or set collection_name on the model.","Verify the record_type passed is the intended model class and not None or a base type."],"exampleFix":"// before\ncollection = CosmosMongoCollection(record_type=MyModel)\n// after\ncollection = CosmosMongoCollection(record_type=MyModel, collection_name=\"my_collection\")","handlingStrategy":"validation","validationCode":"from semantic_kernel.data.vector import _get_collection_name_from_model\n\nresolved = collection_name or _get_collection_name_from_model(record_type, definition)\nif not resolved:\n    raise ValueError(\"collection_name must be passed or defined on the model\")\ncollection = CosmosMongoCollection(record_type=record_type, collection_name=resolved)\n","typeGuard":"def has_collection_name(record_type: type, explicit: str | None) -> bool:\n    return bool(explicit or getattr(record_type, \"__collection_name__\", None) or getattr(record_type, \"collection_name\", None))\n","tryCatchPattern":null,"preventionTips":["Always pass collection_name explicitly in production code.","Decorate models with @vectorstoremodel(collection_name=...) as a single source of truth.","Add an integration test that constructs each collection to catch missing names early."],"tags":["azure-cosmos-db","vector-store","initialization","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}