Service Context
The service context container is a utility container for LlamaIndex index and query classes. The container contains the following objects that are commonly used for configuring every index and query, such as the LLMPredictor (for configuring the LLM), the PromptHelper (for configuring input size/chunk size), the BaseEmbedding (for configuring the embedding model), and more.
Service Context Classes
- class llama_index.indices.service_context.ServiceContext(llm_predictor: BaseLLMPredictor, prompt_helper: PromptHelper, embed_model: BaseEmbedding, node_parser: NodeParser, llama_logger: LlamaLogger, callback_manager: CallbackManager)
Service Context container.
The service context container is a utility container for LlamaIndex index and query classes. It contains the following: - llm_predictor: BaseLLMPredictor - prompt_helper: PromptHelper - embed_model: BaseEmbedding - node_parser: NodeParser - llama_logger: LlamaLogger (deprecated) - callback_manager: CallbackManager
- classmethod from_defaults(llm_predictor: Optional[BaseLLMPredictor] = None, llm: Optional[BaseLanguageModel] = None, prompt_helper: Optional[PromptHelper] = None, embed_model: Optional[BaseEmbedding] = None, node_parser: Optional[NodeParser] = None, llama_logger: Optional[LlamaLogger] = None, callback_manager: Optional[CallbackManager] = None, chunk_size: Optional[int] = None, chunk_overlap: Optional[int] = None, context_window: Optional[int] = None, num_output: Optional[int] = None, chunk_size_limit: Optional[int] = None) ServiceContext
Create a ServiceContext from defaults. If an argument is specified, then use the argument value provided for that parameter. If an argument is not specified, then use the default value.
You can change the base defaults by setting llama_index.global_service_context to a ServiceContext object with your desired settings.
- Parameters
llm_predictor (Optional[BaseLLMPredictor]) – LLMPredictor
prompt_helper (Optional[PromptHelper]) – PromptHelper
embed_model (Optional[BaseEmbedding]) – BaseEmbedding
node_parser (Optional[NodeParser]) – NodeParser
llama_logger (Optional[LlamaLogger]) – LlamaLogger (deprecated)
chunk_size (Optional[int]) – chunk_size
callback_manager (Optional[CallbackManager]) – CallbackManager
- Deprecated Args:
chunk_size_limit (Optional[int]): renamed to chunk_size
- classmethod from_service_context(service_context: ServiceContext, llm_predictor: Optional[BaseLLMPredictor] = None, llm: Optional[BaseLanguageModel] = None, prompt_helper: Optional[PromptHelper] = None, embed_model: Optional[BaseEmbedding] = None, node_parser: Optional[NodeParser] = None, llama_logger: Optional[LlamaLogger] = None, callback_manager: Optional[CallbackManager] = None, chunk_size: Optional[int] = None, chunk_overlap: Optional[int] = None, context_window: Optional[int] = None, num_output: Optional[int] = None, chunk_size_limit: Optional[int] = None) ServiceContext
Instantiate a new service context using a previous as the defaults.
- llama_index.indices.service_context.set_global_service_context(service_context: Optional[ServiceContext]) None
Helper function to set the global service context.