{"record":{"id":"9d8767b20ba59347","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-definition-vectors","errorCode":null,"errorMessage":"Invalid vector definition: {vectors}","messagePattern":"Invalid vector definition: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/qdrant/_target.py","lineNumber":224,"sourceCode":"                raise ValueError(\"Qdrant named vectors must not be empty\")\n            _validate_vector_names(vectors.keys(), \"vector\")\n            resolved_entries: dict[\n                str, _ResolvedQdrantVectorDef | _ResolvedQdrantSparseVectorDef\n            ] = {}\n            for name, vector_def in vectors.items():\n                if isinstance(vector_def, QdrantVectorDef):\n                    resolved_entries[name] = await _resolve_vector_def(vector_def)\n                elif isinstance(vector_def, QdrantSparseVectorDef):\n                    resolved_entries[name] = _resolve_sparse_vector_def(vector_def)\n                else:\n                    raise ValueError(f\"Invalid vector definition: {vector_def}\")\n            resolved = _ResolvedQdrantNamedVectorsDef(vectors=resolved_entries)\n        elif vectors is None:\n            raise ValueError(\n                \"Qdrant collection schema must declare at least one vector\"\n            )\n        else:\n            raise ValueError(f\"Invalid vector definition: {vectors}\")\n        return cls(resolved)\n\n    @property\n    def vectors(\n        self,\n    ) -> _ResolvedQdrantVectorDef | _ResolvedQdrantNamedVectorsDef:\n        \"\"\"Get vector definitions (all VectorSchemaProviders resolved).\"\"\"\n        return self._vectors\n\n\nclass _PointAction(NamedTuple):\n    point_id: _PointId\n    point: qdrant_models.PointStruct | None\n\n\nclass _PointHandler(coco.TargetHandler[qdrant_models.PointStruct, _PointFingerprint]):\n    _client: QdrantClient\n    _collection_name: str","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/qdrant/_target.py#L206-L242","documentation":"CollectionSchema.create() in the Qdrant connector only accepts a QdrantVectorDef, a non-empty dict of names mapped to QdrantVectorDef/QdrantSparseVectorDef, or None (which has its own clearer error). Any other value — or a dict whose per-entry value is not a recognized vector def type — raises this ValueError. It is an upfront input-validation guard so invalid schemas fail in Python instead of at Qdrant collection creation time.","triggerScenarios":"Calling `await CollectionSchema.create(vectors=...)` where `vectors` is not a QdrantVectorDef and not a dict (e.g. a list, a bare string, a QdrantSparseVectorDef handled elsewhere, or a dataclass-like object); or passing a dict whose value for some vector name is neither QdrantVectorDef nor QdrantSparseVectorDef (e.g. a raw dict or a dict of parameters).","commonSituations":"Hand-building the vectors config from YAML/JSON and forgetting to construct QdrantVectorDef objects; typos where a dict of plain kwargs is passed instead of the def class; mixing sparse vectors without wrapping them in QdrantSparseVectorDef inside a dict.","solutions":["Wrap each vector configuration in QdrantVectorDef (or QdrantSparseVectorDef for sparse) instead of passing raw dicts or lists.","If vectors is empty/None, pass at least one vector, e.g. CollectionSchema.create(vectors={\"embedding\": QdrantVectorDef(schema=VectorSchema(dtype=np.float32, size=384), distance=\"cosine\")}).","Pass sparse vectors only inside a dict (sparse vectors are always named in Qdrant).","Print type(vectors) and each dict value's type to confirm they are the connector's def classes, not plain dicts."],"exampleFix":"// before\nawait CollectionSchema.create(vectors={\"embedding\": {\"size\": 384, \"distance\": \"cosine\"}})\n// after\nfrom cocoindex.connectors.qdrant import QdrantVectorDef\nawait CollectionSchema.create(vectors={\"embedding\": QdrantVectorDef(schema=VectorSchema(dtype=np.float32, size=384), distance=\"cosine\")})","handlingStrategy":"type-guard","validationCode":"def _valid_vectors(v):\n    from cocoindex.connectors.qdrant import QdrantVectorDef, QdrantSparseVectorDef\n    if isinstance(v, QdrantVectorDef):\n        return True\n    return isinstance(v, dict) and bool(v) and all(\n        isinstance(x, (QdrantVectorDef, QdrantSparseVectorDef)) for x in v.values()\n    )\nassert _valid_vectors(vectors), f\"bad vectors: {type(vectors)}\"","typeGuard":"isinstance(vectors, QdrantVectorDef) or (isinstance(vectors, dict) and all(isinstance(d, (QdrantVectorDef, QdrantSparseVectorDef)) for d in vectors.values()))","tryCatchPattern":"try:\n    schema = await CollectionSchema.create(vectors=cfg[\"vectors\"])\nexcept ValueError as e:\n    raise ConfigError(f\"qdrant vectors config invalid: {e}\") from None","preventionTips":["Always build vector configs via QdrantVectorDef/QdrantSparseVectorDef classes, never raw dicts.","Parse external config into def objects in one dedicated function so bad shapes fail early.","Add a unit test that round-trips your config through CollectionSchema.create."],"tags":["qdrant","validation","vector-schema"],"backgroundTag":"invalid-argument-value","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}