{"record":{"id":"d84b7edf443a9e73","repo":"open-webui/open-webui","slug":"cannot-create-milvus-collection-without-items-to-d","errorCode":null,"errorMessage":"Cannot create Milvus collection without items to determine vector dimension.","messagePattern":"Cannot create Milvus collection without items to determine vector dimension\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/open_webui/retrieval/vector/dbs/milvus.py","lineNumber":273,"sourceCode":"        # Get all the items in the collection. This can be very resource-intensive for large collections.\n        collection_name = collection_name.replace('-', '_')\n        log.warning(\n            f\"Fetching ALL items from collection '{self.collection_prefix}_{collection_name}'. This might be slow for large collections.\"\n        )\n        # Using query with a trivial filter to get all items.\n        # This will use the paginated query logic.\n        return self.query(collection_name=collection_name, filter={}, limit=-1)\n\n    def insert(self, collection_name: str, items: list[VectorItem]):\n        # Insert the items into the collection, if the collection does not exist, it will be created.\n        collection_name = collection_name.replace('-', '_')\n        if not self.client.has_collection(collection_name=f'{self.collection_prefix}_{collection_name}'):\n            log.info(f'Collection {self.collection_prefix}_{collection_name} does not exist. Creating now.')\n            if not items:\n                log.error(\n                    f'Cannot create collection {self.collection_prefix}_{collection_name} without items to determine dimension.'\n                )\n                raise ValueError('Cannot create Milvus collection without items to determine vector dimension.')\n            self._create_collection(collection_name=collection_name, dimension=len(items[0]['vector']))\n\n        log.info(f'Inserting {len(items)} items into collection {self.collection_prefix}_{collection_name}.')\n        data = []\n        for item in items:\n            text = item['text'] or ''\n            if len(text) > MILVUS_TEXT_MAX_LENGTH:\n                log.warning(f'Milvus: truncating text id={item[\"id\"]} {len(text)}->{MILVUS_TEXT_MAX_LENGTH} chars')\n                text = text[:MILVUS_TEXT_MAX_LENGTH]\n            data.append(\n                {\n                    'id': item['id'],\n                    'vector': item['vector'],\n                    'data': {'text': text},\n                    'metadata': process_metadata(item['metadata']),\n                }\n            )\n        try:","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/retrieval/vector/dbs/milvus.py#L255-L291","documentation":"Raised by MilvusClient.insert when the target collection does not exist yet and the items list is empty. Milvus collections require a fixed vector dimension at creation, and this client derives it from len(items[0]['vector']); with zero items there is no dimension to infer, so creating on-first-insert is impossible and the call fails fast instead of creating a broken collection.","triggerScenarios":"VECTOR_DB=milvus and calling insert() (e.g., saving knowledge documents) with an empty batch for a collection name that doesn't exist yet — typically a chunking/parsing step upstream produced zero chunks (empty PDF, failed extraction) on a brand-new collection.","commonSituations":"First upload to a knowledge base being an empty/unparseable document; ingestion pipeline bug yielding empty chunk lists; automated tests calling insert with fixtures that are empty.","solutions":["Check upstream: ensure the document produced at least one chunk before calling insert (verify the loader/parser output).","Skip the insert call when items is empty: if not items: return before touching the vector DB.","If the collection should exist, verify collection naming/prefix (collections are prefixed and '-' replaced by '_') — you may be checking a differently-named collection."],"exampleFix":"# before\nclient.insert(collection_name='kb_docs', items=[])  # collection missing -> ValueError\n\n# after\nif items:\n    client.insert(collection_name='kb_docs', items=items)\nelse:\n    log.warning('No chunks to insert; skipping vector store write')","handlingStrategy":"validation","validationCode":"def insertable(items: list, collection_exists: bool) -> bool:\n    \"\"\"Milvus auto-create needs >=1 item to infer the vector dimension.\"\"\"\n    return bool(items) or collection_exists\n\n# before calling insert:\nif not items and not client.client.has_collection(f'{client.collection_prefix}_{name}'):\n    log.warning(f'Skipping insert into new collection {name}: no items to infer dimension')\n    return","typeGuard":"def is_non_empty_vector_items(items: object) -> bool:\n    return (\n        isinstance(items, list)\n        and len(items) > 0\n        and all(isinstance(i, dict) and isinstance(i.get('vector'), (list, tuple)) and len(i['vector']) > 0 for i in items)\n    )","tryCatchPattern":"try:\n    client.insert(collection_name=name, items=items)\nexcept ValueError as e:\n    if 'without items to determine vector dimension' in str(e):\n        log.warning(f'No content to store for {name}; nothing inserted')\n        return []\n    raise","preventionTips":["Filter empty chunk lists at the parsing stage — never hand the vector store an empty batch.","Fail document ingestion early with a clear user message when a document yields zero chunks.","When creating collections intentionally, pass a schema/dimension explicitly instead of relying on first-insert inference."],"tags":["milvus","vector-db","rag","validation","ingestion"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}