{"record":{"id":"67ae3de6995e461f","repo":"cocoindex-io/cocoindex","slug":"embedding-dimension-is-unknown-for-model-self-mo","errorCode":null,"errorMessage":"Embedding dimension is unknown for model {self._model_name_or_path}.","messagePattern":"Embedding dimension is unknown for model (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/ops/sentence_transformers.py","lineNumber":218,"sourceCode":"            RuntimeError: If the model's embedding dimension cannot be determined.\n        \"\"\"\n        dim = await self.dimension()\n        return _schema.VectorSchema(dtype=_np.dtype(_np.float32), size=dim)\n\n    @coco.fn.as_async(runner=coco.GPU, memo=True)\n    def dimension(self) -> int:\n        \"\"\"Return the embedding dimension for this model.\n\n        Returns:\n            The embedding dimension as an integer.\n\n        Raises:\n            RuntimeError: If the model's embedding dimension cannot be determined.\n        \"\"\"\n        model = self._get_model()\n        dim = model.get_sentence_embedding_dimension()\n        if dim is None:\n            raise RuntimeError(\n                f\"Embedding dimension is unknown for model {self._model_name_or_path}.\"\n            )\n        return int(dim)\n\n    def __coco_memo_key__(self) -> object:\n        return (self._model_name_or_path, self._device, self._trust_remote_code)\n","sourceCodeStart":200,"sourceCodeEnd":225,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/ops/sentence_transformers.py#L200-L225","documentation":"Raised by the `dimension` property of a sentence-transformers embedding function when the loaded model reports `None` from `get_sentence_embedding_dimension()`. The library needs a concrete integer dimension (e.g. for schema/index setup) and cannot proceed when the model cannot report one.","triggerScenarios":"Accessing `.dimension` on a SentenceTransformerEmbedding wrapper for a model whose sentence-transformers backend cannot determine an embedding dimension — typically models loaded without a sentence-transformers pooling/ sentence embedding head.","commonSituations":"Pointing the op at a raw HF model (e.g. a bare transformer or a CLIP-style model) that is not a sentence-transformers model; loading a local path with missing config files; model files for a repo that doesn't declare dimension in its configuration.","solutions":["Use a model that is actually a sentence-transformers model (has modules.json / sentence-transformers config), or wrap a plain transformer with sentence_transformers itself.","Load the model and call `model.get_sentence_embedding_dimension()` directly to confirm whether the backend can report a dimension.","If the model is local, verify the download is complete and config files (modules.json, config_sentence_transformers.json) are present.","Pick a known embedding model with a declared dimension (e.g. all-MiniLM-L6-v2) if the current model fundamentally has none."],"exampleFix":"// before\nemb = SentenceTransformerEmbedding(model=\"openai/clip-vit-base-patch32\")\nprint(emb.dimension)  # RuntimeError\n// after\nemb = SentenceTransformerEmbedding(model=\"sentence-transformers/all-MiniLM-L6-v2\")\nprint(emb.dimension)  # 384","handlingStrategy":"validation","validationCode":"from sentence_transformers import SentenceTransformer\nm = SentenceTransformer(model_name)\nassert m.get_sentence_embedding_dimension() is not None, f\"{model_name} has no declared embedding dimension\"","typeGuard":null,"tryCatchPattern":"try:\n    dim = emb.dimension\nexcept RuntimeError as e:\n    if 'Embedding dimension is unknown' in str(e):\n        emb = SentenceTransformerEmbedding(model=FALLBACK_MODEL)\n        dim = emb.dimension\n    else:\n        raise","preventionTips":["Only use models from the sentence-transformers ecosystem (with modules.json) for this op.","Probe `get_sentence_embedding_dimension()` on any new model before registering it.","Verify local model directories are fully downloaded (config + modules.json present)."],"tags":["python","embeddings","sentence-transformers","model-config"],"backgroundTag":"missing-config-value","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}