{"record":{"id":"4fcfe0c1bcef4688","repo":"MemPalace/mempalace","slug":"embedding-dimension-must-be-positive-4fcfe0","errorCode":null,"errorMessage":"embedding dimension must be positive","messagePattern":"embedding dimension must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/qdrant.py","lineNumber":740,"sourceCode":"            info = self._client.get_collection_info(self._remote_collection)\n        except _QdrantHTTPError as exc:\n            if exc.status == 404:\n                return None\n            raise\n        result = info.get(\"result\") or info\n        params = (result.get(\"config\") or {}).get(\"params\") or {}\n        vectors = params.get(\"vectors\") or params.get(\"vectors_config\") or {}\n        if isinstance(vectors, dict) and \"size\" in vectors:\n            return int(vectors[\"size\"])\n        if isinstance(vectors, dict):\n            for value in vectors.values():\n                if isinstance(value, dict) and \"size\" in value:\n                    return int(value[\"size\"])\n        return None\n\n    def _ensure_remote_collection(self, dimension: int) -> None:\n        if dimension <= 0:\n            raise ValueError(\"embedding dimension must be positive\")\n        with self._lock:\n            self._ensure_open()\n            if self._known_dimension is not None:\n                if self._known_dimension != dimension:\n                    raise DimensionMismatchError(\n                        f\"qdrant collection {self._collection_name!r} expects \"\n                        f\"embedding dimension {self._known_dimension}, got {dimension}\"\n                    )\n                return\n            if not self._remote_exists():\n                self._client.create_collection(self._remote_collection, dimension)\n                self._client.create_payload_index(\n                    self._remote_collection, _PAYLOAD_DOCUMENT, \"text\"\n                )\n                self._known_dimension = dimension\n                return\n            remote_dim = self._remote_dimension()\n            if remote_dim is not None and remote_dim != dimension:","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/qdrant.py#L722-L758","documentation":"Raised by QdrantCollection._ensure_remote_collection() when the dimension passed for creating/validating the remote collection is zero or negative. A vector collection needs a positive vector size; this guard fires before any server call, typically because the computed embedding dimension was 0.","triggerScenarios":"Passing embeddings that are empty is caught earlier, but code paths that derive a dimension (e.g. int(arr.size) from a degenerate batch, or a caller-supplied dimension of 0) reach this check. Most commonly a bug where dimension is computed from an empty list or a failed embedder result.","commonSituations":"Embedding model not loaded (returns empty), dimension inferred from the first batch which was empty, or hardcoded/typo'd dimension config (0 or -1).","solutions":["Log the dimension value right before the write; find why it is <= 0 (usually an empty embeddings list slipped past earlier checks)","Verify the embedding model returns vectors: len(model.embed('test')) > 0","If dimension comes from config, correct the value to the model's actual output size (e.g. 768)","Add a startup assertion that the configured model's embedding length is positive"],"exampleFix":"# before\n dim = len(embeddings[0]) if embeddings else 0\ncollection._ensure_remote_collection(dim)  # ValueError\n# after\n dim = len(embeddings[0])\nassert dim > 0, f\"bad embedding dimension: {dim}\"","handlingStrategy":"validation","validationCode":"if not embeddings or len(embeddings[0]) <= 0:\n    raise ValueError(\"cannot derive a positive embedding dimension\")","typeGuard":"def positive_dim(embeddings) -> bool:\n    return bool(embeddings) and isinstance(embeddings[0], (list, tuple)) and len(embeddings[0]) > 0","tryCatchPattern":null,"preventionTips":["Never pass dimension 0 or inferred-from-empty values; validate the embedder at startup","Assert the model's output size once: dim = len(model.embed('test')); assert dim > 0"],"tags":["validation","embeddings","qdrant","configuration"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}