{"record":{"id":"41c6b578fa80f9b5","repo":"run-llama/llama_index","slug":"one-of-nodes-objects-or-index-struct-must-be-pro","errorCode":null,"errorMessage":"One of nodes, objects, or index_struct must be provided.","messagePattern":"One of nodes, objects, or index_struct must be provided\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/base.py","lineNumber":50,"sourceCode":"\n    \"\"\"\n\n    index_struct_cls: Type[IS]\n\n    def __init__(\n        self,\n        nodes: Optional[Sequence[BaseNode]] = None,\n        objects: Optional[Sequence[IndexNode]] = None,\n        index_struct: Optional[IS] = None,\n        storage_context: Optional[StorageContext] = None,\n        callback_manager: Optional[CallbackManager] = None,\n        transformations: Optional[List[TransformComponent]] = None,\n        show_progress: bool = False,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize with parameters.\"\"\"\n        if index_struct is None and nodes is None and objects is None:\n            raise ValueError(\"One of nodes, objects, or index_struct must be provided.\")\n        if index_struct is not None and nodes is not None and len(nodes) >= 1:\n            raise ValueError(\"Only one of nodes or index_struct can be provided.\")\n        # This is to explicitly make sure that the old UX is not used\n        if nodes is not None and len(nodes) >= 1 and not isinstance(nodes[0], BaseNode):\n            if isinstance(nodes[0], Document):\n                raise ValueError(\n                    \"The constructor now takes in a list of Node objects. \"\n                    \"Since you are passing in a list of Document objects, \"\n                    \"please use `from_documents` instead.\"\n                )\n            else:\n                raise ValueError(\"nodes must be a list of Node objects.\")\n\n        self._storage_context = storage_context or StorageContext.from_defaults()\n        self._docstore = self._storage_context.docstore\n        self._show_progress = show_progress\n        self._vector_store = self._storage_context.vector_store\n        self._graph_store = self._storage_context.graph_store","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/base.py#L32-L68","documentation":"The BaseIndex constructor requires exactly one source of index material: pre-built nodes, IndexNode objects, or an existing index_struct (the serialized index skeleton used when rehydrating an index). If all three are None there is nothing to build from, so it raises ValueError. This is a constructor-contract error, not a data error.","triggerScenarios":"Calling BaseIndex(...) (or a subclass constructor) with no nodes, objects, or index_struct; writing a custom index subclass whose __init__ forwards **kwargs but drops the required arguments; calling a subclass constructor directly instead of a factory like from_documents or as_index.","commonSituations":"Custom index implementations that forget to pass index_struct up to super().__init__; accidentally invoking the constructor when intending to call a classmethod; refactors that pass StorageContext but omit index_struct.","solutions":["Pass index_struct=self.index_struct from your subclass (the standard pattern: super().__init__(nodes=..., index_struct=self.index_struct, ...)).","If you have documents, use the class factory: IndexClass.from_documents(documents) instead of the raw constructor.","If you have parsed nodes, pass them via nodes=[...].","If rehydrating a persisted index, load the index_struct from storage and pass it, or use the storage context reload helpers."],"exampleFix":"# before\nclass MyIndex(BaseIndex):\n    def __init__(self, *args, **kwargs):\n        super().__init__()  # no nodes/objects/index_struct -> ValueError\n\n# after\nclass MyIndex(BaseIndex):\n    index_struct_cls = MyIndexStruct\n    def __init__(self, nodes=None, index_struct=None, **kwargs):\n        index_struct = index_struct or MyIndexStruct()\n        super().__init__(nodes=nodes, index_struct=index_struct, **kwargs)","handlingStrategy":"validation","validationCode":"if nodes is None and objects is None and index_struct is None:\n    raise ValueError(\"Supply nodes, objects, or index_struct before constructing the index\")","typeGuard":"def has_index_inputs(nodes, objects, index_struct) -> bool:\n    return any([nodes, objects, index_struct])","tryCatchPattern":null,"preventionTips":["Custom index subclasses must always forward index_struct=self.index_struct to super().__init__.","Prefer factories (from_documents, from_nodes) over raw constructors."],"tags":["index","constructor","validation","base-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}