{"record":{"id":"b87dffafe7c218f6","repo":"microsoft/semantic-kernel","slug":"dimensionality-must-be-a-positive-integer","errorCode":null,"errorMessage":"Dimensionality must be a positive integer. ","messagePattern":"Dimensionality must be a positive integer\\. ","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py","lineNumber":499,"sourceCode":"\n    async def __get_collections(self, cur: Cursor) -> list[str]:\n        cur.execute(\n            \"\"\"\n            SELECT table_name\n            FROM information_schema.tables\n            WHERE table_schema = %s\n            \"\"\",\n            (self._schema,),\n        )\n        return [row[0] for row in cur.fetchall()]\n\n    def _check_dimensionality(self, dimension_num):\n        if dimension_num > MAX_DIMENSIONALITY:\n            raise ServiceInitializationError(\n                f\"Dimensionality of {dimension_num} exceeds \" + f\"the maximum allowed value of {MAX_DIMENSIONALITY}.\"\n            )\n        if dimension_num <= 0:\n            raise ServiceInitializationError(\"Dimensionality must be a positive integer. \")\n\n    def __serialize_metadata(self, record: MemoryRecord) -> str:\n        return json.dumps({\n            \"text\": record._text,\n            \"description\": record._description,\n            \"additional_metadata\": record._additional_metadata,\n        })\n\n    # Enable the connection pool to be closed when using as a context manager\n    def __enter__(self) -> \"PostgresMemoryStore\":\n        \"\"\"Enter the runtime context.\"\"\"\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback) -> bool:\n        \"\"\"Exit the runtime context and dispose of the connection pool.\"\"\"\n        self._connection_pool.close()\n        return False\n","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py#L481-L517","documentation":"Raised by PostgresMemoryStore._check_dimensionality() when dimension_num <= 0. It is a ServiceInitializationError fired at construction or at create_collection time, indicating an invalid (non-positive) dimensionality was supplied.","triggerScenarios":"Passing default_dimensionality=0 or a negative value to the constructor, or create_collection(name, dimension_num=0). Often happens when the value is read from an unset config/env var that defaults to 0.","commonSituations":"Unset embedding-dimension env var coerced to 0; passing None through an int cast that yields 0; logic that computes dimension from a failed model load.","solutions":["Supply a concrete positive integer (e.g. 1536 for ada-002, 1536/3072 for text-embedding-3).","Validate config: assert dimension_num and dimension_num > 0 before constructing the store.","Fix the source of the value (env var, settings model) so it resolves to the model's real dimensionality.","Default to the embedding generator's documented dimension rather than 0."],"exampleFix":"// before\nstore = PostgresMemoryStore(conn_str, default_dimensionality=int(os.getenv('DIM') or 0))\n// after\ndim = int(os.getenv('DIM') or 1536)\nassert dim > 0\nstore = PostgresMemoryStore(conn_str, default_dimensionality=dim)","handlingStrategy":"validation","validationCode":"assert isinstance(dim, int) and dim > 0, 'dimensionality must be a positive integer'\nstore = PostgresMemoryStore(conn_str, default_dimensionality=dim)","typeGuard":"def valid_dim(dim) -> bool:\n    return isinstance(dim, int) and dim > 0","tryCatchPattern":null,"preventionTips":["Never default dimensionality to 0; default to the model's real dimension (e.g. 1536).","Validate env-sourced ints before passing to the constructor.","Fail fast in config loading rather than at store construction."],"tags":["postgres","memory-store","dimensionality","service-initialization-error","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}