{"record":{"id":"9166c5855387175f","repo":"run-llama/llama_index","slug":"servicecontext-is-deprecated-use-llama-index-sett","errorCode":null,"errorMessage":"ServiceContext is deprecated. Use llama_index.settings.Settings instead, or pass in modules to local functions/methods/interfaces.\\nSee the docs for updated usage/migration: \\nhttps://docs.llamaindex.ai/en/stable/module_guides/supporting_modules/service_context_migration/","messagePattern":"ServiceContext is deprecated\\. Use llama_index\\.settings\\.Settings instead, or pass in modules to local functions/methods/interfaces\\.\\\\nSee the docs for updated usage/migration: \\\\nhttps://docs\\.llamaindex\\.ai/en/stable/module_guides/supporting_modules/service_context_migration/","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"llama-index-core/llama_index/core/service_context.py","lineNumber":14,"sourceCode":"from typing import Any, Optional\n\n\nclass ServiceContext:\n    \"\"\"\n    Service Context container.\n\n    NOTE: Deprecated, use llama_index.settings.Settings instead or pass in\n    modules to local functions/methods/interfaces.\n\n    \"\"\"\n\n    def __init__(self, **kwargs: Any) -> None:\n        raise ValueError(\n            \"ServiceContext is deprecated. Use llama_index.settings.Settings instead, \"\n            \"or pass in modules to local functions/methods/interfaces.\\n\"\n            \"See the docs for updated usage/migration: \\n\"\n            \"https://docs.llamaindex.ai/en/stable/module_guides/supporting_modules/service_context_migration/\"\n        )\n\n    @classmethod\n    def from_defaults(\n        cls,\n        **kwargs: Any,\n    ) -> \"ServiceContext\":\n        \"\"\"\n        Create a ServiceContext from defaults.\n\n        NOTE: Deprecated, use llama_index.settings.Settings instead or pass in\n        modules to local functions/methods/interfaces.\n\n        \"\"\"","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/service_context.py#L1-L32","documentation":"ServiceContext was the pre-settings dependency container and is fully removed: its __init__ unconditionally raises a ValueError pointing at the Settings singleton and the migration docs. Any instantiation — including ServiceContext.from_defaults — fails by design in current llama-index versions.","triggerScenarios":"Calling ServiceContext(...), ServiceContext.from_defaults(...), or any old tutorial/API that passes service_context=... into indices, retrievers, or query engines.","commonSituations":"Upgrading from llama_index <0.10 to >=0.10; running legacy notebooks/blog code; third-party packages still importing ServiceContext.","solutions":["Replace ServiceContext usage with the global Settings object (Settings.llm, Settings.embed_model, Settings.node_parser) or pass modules directly to constructors","Remove all service_context= arguments from index/query-engine construction","Update pinned third-party packages to versions compatible with llama-index >= 0.10","Follow the migration guide referenced in the error message"],"exampleFix":"# before\nfrom llama_index.core import ServiceContext\nctx = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(docs, service_context=ctx)\n\n# after\nfrom llama_index.core import Settings, VectorStoreIndex\nSettings.llm = llm\nSettings.embed_model = embed_model\nindex = VectorStoreIndex.from_documents(docs)","handlingStrategy":"validation","validationCode":"# before importing old code, check compatibility\nimport llama_index.core\nfrom packaging.version import parse\nassert parse(llama_index.core.__version__.split(\"+\")[0]) >= parse(\"0.10.0\"), \"need >=0.10 Settings API\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Migrate to the global Settings singleton (Settings.llm, Settings.embed_model)","Pass modules directly to constructors instead of a context object","Upgrade or replace packages that still import ServiceContext","Run the 0.10 migration guide against legacy notebooks before upgrading"],"tags":["deprecation","migration","settings","version-upgrade"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}