Implementation:Run llama Llama index Core Public API
| Knowledge Sources | |
|---|---|
| Domains | LLM Framework, Public API |
| Last Updated | 2026-02-11 19:00 GMT |
Overview
This module defines the top-level public API surface of the llama-index-core package, re-exporting all major classes, functions, and utilities that users import from llama_index.core.
Description
The __init__.py file serves as the central entry point for the LlamaIndex core library. It aggregates and re-exports key components from various submodules to provide a convenient single-import experience. The file is organized into several logical sections:
- Version detection: Uses importlib.metadata to read the installed package version, falling back to "0.0.0" if the package is not formally installed (e.g., during development or testing).
- Index classes: Re-exports all major index types including VectorStoreIndex, SummaryIndex, TreeIndex, KeywordTableIndex, DocumentSummaryIndex, KnowledgeGraphIndex, PropertyGraphIndex, and their legacy GPT-prefixed aliases.
- Prompt classes: Exports PromptTemplate, ChatPromptTemplate, BasePromptTemplate, SelectorPromptTemplate, and the legacy Prompt alias.
- Storage and context: Exports StorageContext and ServiceContext along with their configuration functions.
- Settings: Exports the global Settings singleton for configuring LLM, embedding model, and other defaults.
- Utilities: Exports SQLDatabase, SQLDocumentContextBuilder, SimpleDirectoryReader, MockEmbedding, tokenizer utilities, and the global callback handler.
- Legacy aliases: Maintains SQLContextBuilder as a backward-compatible alias for SQLDocumentContextBuilder, and includes global mutable variables global_handler and global_tokenizer.
The __all__ list explicitly declares the public API consisting of approximately 50 symbols.
Usage
This module is the primary import target for users of the LlamaIndex library. All top-level imports such as from llama_index.core import VectorStoreIndex, Settings resolve through this file. It should not be modified unless adding or removing a public API symbol.
Code Reference
Source Location
- Repository: Run_llama_Llama_index
- File: llama-index-core/llama_index/core/__init__.py
- Lines: 1-161
Signature
# Module-level exports (no class/function signature; this is a package __init__)
__version__: str # resolved from importlib.metadata
__all__: list # ~50 public symbols
global_handler: Optional[BaseCallbackHandler] = None
global_tokenizer: Optional[Callable[[str], list]] = None
Import
from llama_index.core import (
VectorStoreIndex,
SummaryIndex,
TreeIndex,
Settings,
StorageContext,
ServiceContext,
Document,
SimpleDirectoryReader,
load_index_from_storage,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This is a module-level init file; it does not accept direct inputs. It re-exports symbols from submodules. |
Outputs
| Name | Type | Description |
|---|---|---|
| __version__ | str | The installed version of llama-index-core, or "0.0.0" if not installed. |
| __all__ | list | List of approximately 50 public symbol names exported by this module. |
| global_handler | Optional[BaseCallbackHandler] | Global callback handler instance, initially None. |
| global_tokenizer | Optional[Callable] | Global tokenizer function, initially None. |
Usage Examples
Basic Usage
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
# Configure global settings
Settings.llm = my_llm
Settings.embed_model = my_embed_model
# Load documents and build an index
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
# Query the index
query_engine = index.as_query_engine()
response = query_engine.query("What is the main topic?")
print(response)
Loading a Persisted Index
from llama_index.core import StorageContext, load_index_from_storage
storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)