{"record":{"id":"b9f25eaaa37becab","repo":"microsoft/semantic-kernel","slug":"index-for-vector-field-name-must-be-a-subtype-of","errorCode":null,"errorMessage":"Index for {vector_field.name} must be a subtype of faiss.Index","messagePattern":"Index for (.+?) must be a subtype of faiss\\.Index","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/faiss.py","lineNumber":129,"sourceCode":"\n    def _create_indexes(self, index: faiss.Index | None = None, indexes: dict[str, faiss.Index] | None = None) -> None:\n        \"\"\"Create Faiss indexes for each vector field.\n\n        Args:\n            index: The index to use, this can be used when there is only one vector field.\n            indexes: A dictionary of indexes, the key is the name of the vector field.\n        \"\"\"\n        if len(self.definition.vector_fields) == 1 and index is not None:\n            if not isinstance(index, faiss.Index):\n                raise VectorStoreInitializationException(\"Index must be a subtype of faiss.Index\")\n            if not index.is_trained:\n                raise VectorStoreInitializationException(\"Index must be trained before using.\")\n            self.indexes[self.definition.vector_fields[0].name] = index\n            return\n        for vector_field in self.definition.vector_fields:\n            if indexes and vector_field.name in indexes:\n                if not isinstance(indexes[vector_field.name], faiss.Index):\n                    raise VectorStoreInitializationException(\n                        f\"Index for {vector_field.name} must be a subtype of faiss.Index\"\n                    )\n                if not indexes[vector_field.name].is_trained:\n                    raise VectorStoreInitializationException(\n                        f\"Index for {vector_field.name} must be trained before using.\"\n                    )\n                self.indexes[vector_field.name] = indexes[vector_field.name]\n                if vector_field.name not in self.indexes_key_map:\n                    self.indexes_key_map.setdefault(vector_field.name, {})\n                continue\n            if vector_field.name not in self.indexes:\n                self.indexes[vector_field.name] = _create_index(vector_field)\n            if vector_field.name not in self.indexes_key_map:\n                self.indexes_key_map.setdefault(vector_field.name, {})\n\n    @override\n    async def ensure_collection_exists(\n        self, index: faiss.Index | None = None, indexes: dict[str, faiss.Index] | None = None, **kwargs: Any","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/faiss.py#L111-L147","documentation":"A VectorStoreInitializationException raised in the multi-vector-field path of _create_indexes() when an entry in the 'indexes' dict (keyed by vector field name) is not an instance of faiss.Index. This is the per-field equivalent of error 1296: each supplied index object must be a real faiss.Index.","triggerScenarios":"Passing FaissCollection(..., indexes={\"field_a\": <not faiss.Index>}) for a model with multiple vector fields, where one or more values are the wrong type (array, string, dict, etc.).","commonSituations":"Mixing correctly-built indexes with placeholders/raw data when configuring a multi-vector collection; passing index factory strings per field.","solutions":["Ensure every value in the 'indexes' dict is an instance of faiss.Index built via faiss.IndexFlat*/index_factory.","Omit any field you want auto-created from the dict so _create_index builds a flat index for it."],"exampleFix":"// before\ncollection = FaissCollection(record_type=Doc, indexes={\"vec1\": faiss.IndexFlatL2(1536), \"vec2\": matrix})\n// after\ncollection = FaissCollection(record_type=Doc, indexes={\"vec1\": faiss.IndexFlatL2(1536), \"vec2\": faiss.IndexFlatIP(300)})","handlingStrategy":"type-guard","validationCode":"import faiss\nbad = {name: obj for name, obj in (indexes or {}).items() if not isinstance(obj, faiss.Index)}\nassert not bad, f\"These indexes are not faiss.Index: {list(bad)}\"","typeGuard":"import faiss\n\ndef all_indexes_are_faiss(indexes: dict) -> bool:\n    return all(isinstance(v, faiss.Index) for v in indexes.values())","tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreInitializationException\ntry:\n    collection = FaissCollection(record_type=Doc, indexes=indexes)\nexcept VectorStoreInitializationException as e:\n    if \"must be a subtype of faiss.Index\" in str(e):\n        for k, v in indexes.items():\n            if not isinstance(v, faiss.Index):\n                indexes[k] = faiss.IndexFlatL2(dims[k])\n        collection = FaissCollection(record_type=Doc, indexes=indexes)","preventionTips":["Ensure every value in the 'indexes' dict is a faiss.Index instance.","Omit fields you want auto-created rather than passing placeholders."],"tags":["faiss","vector-store","configuration","index","multi-vector"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}