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
^^^^^^^^^^^^^^^^^^^^^^^
* Embeddings
* OpenAIEmbedding
* HuggingFaceEmbedding
* OptimumEmbedding
* InstructorEmbedding
* LangchainEmbedding
* GoogleUnivSentEncoderEmbedding
* Node Parser
* PromptHelper
* LLMs
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[Union[str, LLM, BaseLanguageModel]] = 'default', prompt_helper: Optional[PromptHelper] = None, embed_model: Optional[Union[BaseEmbedding, Embeddings, str]] = 'default', node_parser: Optional[NodeParser] = None, llama_logger: Optional[LlamaLogger] = None, callback_manager: Optional[CallbackManager] = None, system_prompt: Optional[str] = None, query_wrapper_prompt: Optional[BasePromptTemplate] = 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 or "local" (use local model)
         * **node_parser** (*Optional**[**NodeParser**]*) --
           NodeParser
         * **llama_logger** (*Optional**[**LlamaLogger**]*) --
           LlamaLogger (deprecated)
         * **chunk_size** (*Optional**[**int**]*) -- chunk_size
         * **callback_manager** (*Optional**[**CallbackManager**]*) --
           CallbackManager
         * **system_prompt** (*Optional**[**str**]*) -- System-wide
           prompt to be prepended to all input prompts, used to guide
           system "decision making"
         * **query_wrapper_prompt**
           (*Optional**[**BasePromptTemplate**]*) -- A format to wrap
           passed-in input queries.
      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[Union[str, LLM, BaseLanguageModel]] = 'default', prompt_helper: Optional[PromptHelper] = None, embed_model: Optional[Union[BaseEmbedding, Embeddings, str]] = 'default', node_parser: Optional[NodeParser] = None, llama_logger: Optional[LlamaLogger] = None, callback_manager: Optional[CallbackManager] = None, system_prompt: Optional[str] = None, query_wrapper_prompt: Optional[BasePromptTemplate] = 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

Service Context

      Instantiate a new service context using a previous as the
      defaults.
   to_dict() -> dict
      Convert service context to dict.
llama_index.indices.service_context.set_global_service_context(service_context: Optional[ServiceContext]) -> None
   Helper function to set the global service context.


Storage Context

LlamaIndex offers core abstractions around storage of Nodes, indices,
and vectors. A key abstraction is the *StorageContext* - this contains
the underlying *BaseDocumentStore* (for nodes), *BaseIndexStore* (for
indices), and *VectorStore* (for vectors).
The Document/Node and index stores rely on a common *KVStore*
abstraction, which is also detailed below.
We show the API references for the Storage Classes, loading indices
from the Storage Context, and the Storage Context class itself below.
Storage Classes
^^^^^^^^^^^^^^^
* Document Store
* Index Store
* Vector Store
* KV Storage
Loading Indices
^^^^^^^^^^^^^^^
* Loading Indices
class llama_index.storage.storage_context.StorageContext(docstore: BaseDocumentStore, index_store: BaseIndexStore, vector_store: VectorStore, graph_store: GraphStore)
   Storage context.
   The storage context container is a utility container for storing
   nodes, indices, and vectors. It contains the following: - docstore:
   BaseDocumentStore - index_store: BaseIndexStore - vector_store:
   VectorStore - graph_store: GraphStore
   classmethod from_defaults(docstore: Optional[BaseDocumentStore] = None, index_store: Optional[BaseIndexStore] = None, vector_store: Optional[VectorStore] = None, graph_store: Optional[GraphStore] = None, persist_dir: Optional[str] = None, fs: Optional[AbstractFileSystem] = None) -> StorageContext
      Create a StorageContext from defaults.
      Parameters:
         * **docstore** (*Optional**[**BaseDocumentStore**]*) --
           document store
         * **index_store** (*Optional**[**BaseIndexStore**]*) -- index
           store
         * **vector_store** (*Optional**[**VectorStore**]*) -- vector
           store
         * **graph_store** (*Optional**[**GraphStore**]*) -- graph
           store
   classmethod from_dict(save_dict: dict) -> StorageContext
      Create a StorageContext from dict.
   persist(persist_dir: Union[str, PathLike] = './storage', docstore_fname: str = 'docstore.json', index_store_fname: str = 'index_store.json', vector_store_fname: str = 'vector_store.json', graph_store_fname: str = 'graph_store.json', fs: Optional[AbstractFileSystem] = None) -> None
      Persist the storage context.
      Parameters:
         **persist_dir** (*str*) -- directory to persist the storage
         context


Playground

Experiment with different indices, models, and more.
class llama_index.playground.base.Playground(indices: ~typing.List[~llama_index.indices.base.BaseIndex], retriever_modes: ~typing.Dict[~typing.Type[~llama_index.indices.base.BaseIndex], ~typing.List[str]] = {<class 'llama_index.indices.tree.base.TreeIndex'>: ['select_leaf', 'select_leaf_embedding', 'all_leaf', 'root'], <class 'llama_index.indices.list.base.SummaryIndex'>: ['default', 'embedding', 'llm'], <class 'llama_index.indices.vector_store.base.VectorStoreIndex'>: ['default']})
   Experiment with indices, models, embeddings, retriever_modes, and
   more.
   compare(query_text: str, to_pandas: bool | None = True) -> Union[DataFrame, List[Dict[str, Any]]]
      Compare index outputs on an input query.
      Parameters:
         * **query_text** (*str*) -- Query to run all indices on.
         * **to_pandas** (*Optional**[**bool**]*) -- Return results in
           a pandas dataframe. True by default.
      Returns:
         The output of each index along with other data, such as the
         time it took to compute. Results are stored in a Pandas
         Dataframe or a list of Dicts.
   classmethod from_docs(documents: ~typing.List[~llama_index.schema.Document], index_classes: ~typing.List[~typing.Type[~llama_index.indices.base.BaseIndex]] = [<class 'llama_index.indices.vector_store.base.VectorStoreIndex'>, <class 'llama_index.indices.tree.base.TreeIndex'>, <class 'llama_index.indices.list.base.SummaryIndex'>], retriever_modes: ~typing.Dict[~typing.Type[~llama_index.indices.base.BaseIndex], ~typing.List[str]] = {<class 'llama_index.indices.tree.base.TreeIndex'>: ['select_leaf', 'select_leaf_embedding', 'all_leaf', 'root'], <class 'llama_index.indices.list.base.SummaryIndex'>: ['default', 'embedding', 'llm'], <class 'llama_index.indices.vector_store.base.VectorStoreIndex'>: ['default']}, **kwargs: ~typing.Any) -> Playground
      Initialize with Documents using the default list of indices.
      Parameters:
         **documents** -- A List of Documents to experiment with.
   property indices: List[BaseIndex]
      Get Playground's indices.
   property retriever_modes: dict
      Get Playground's indices.


Knowledge Graph Index

Building the Knowledge Graph Index
KG-based data structures.
llama_index.indices.knowledge_graph.GPTKnowledgeGraphIndex
   alias of "KnowledgeGraphIndex"
class llama_index.indices.knowledge_graph.KGTableRetriever(index: KnowledgeGraphIndex, query_keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_query: int = 10, num_chunks_per_query: int = 10, include_text: bool = True, retriever_mode: Optional[KGRetrieverMode] = KGRetrieverMode.KEYWORD, similarity_top_k: int = 2, graph_store_query_depth: int = 2, use_global_node_triplets: bool = False, max_knowledge_sequence: int = 30, **kwargs: Any)
   KG Table Retriever.
   Arguments are shared among subclasses.
   Parameters:
      * **query_keyword_extract_template**
        (*Optional**[**QueryKGExtractPrompt**]*) -- A Query KG
        Extraction Prompt (see Prompt Templates).
      * **refine_template** (*Optional**[**BasePromptTemplate**]*) --
        A Refinement Prompt (see Prompt Templates).
      * **text_qa_template** (*Optional**[**BasePromptTemplate**]*) --
        A Question Answering Prompt (see Prompt Templates).
      * **max_keywords_per_query** (*int*) -- Maximum number of
        keywords to extract from query.
      * **num_chunks_per_query** (*int*) -- Maximum number of text
        chunks to query.
      * **include_text** (*bool*) -- Use the document text source from
        each relevant triplet during queries.
      * **retriever_mode** (*KGRetrieverMode*) -- Specifies whether to
        use keywords, embeddings, or both to find relevant triplets.
        Should be one of "keyword", "embedding", or "hybrid".
      * **similarity_top_k** (*int*) -- The number of top embeddings
        to use (if embeddings are used).
      * **graph_store_query_depth** (*int*) -- The depth of the graph
        store query.
      * **use_global_node_triplets** (*bool*) -- Whether to get more
        keywords(entities) from text chunks matched by keywords. This
        helps introduce more global knowledge. While it's more
        expensive, thus to be turned off by default.
      * **max_knowledge_sequence** (*int*) -- The maximum number of
        knowledge sequence to include in the response. By default,
        it's 30.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.knowledge_graph.KnowledgeGraphIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[KG] = None, service_context: Optional[ServiceContext] = None, storage_context: Optional[StorageContext] = None, kg_triple_extract_template: Optional[BasePromptTemplate] = None, max_triplets_per_chunk: int = 10, include_embeddings: bool = False, show_progress: bool = False, max_object_length: int = 128, kg_triplet_extract_fn: Optional[Callable] = None, **kwargs: Any)
   Knowledge Graph Index.
   Build a KG by extracting triplets, and leveraging the KG during
   query-time.
   Parameters:
      * **kg_triple_extract_template** (*BasePromptTemplate*) -- The
        prompt to use for extracting triplets.
      * **max_triplets_per_chunk** (*int*) -- The maximum number of

Knowledge Graph Index

        triplets to extract.
      * **service_context** (*Optional**[**ServiceContext**]*) -- The
        service context to use.
      * **storage_context** (*Optional**[**StorageContext**]*) -- The
        storage context to use.
      * **graph_store** (*Optional**[**GraphStore**]*) -- The graph
        store to use.
      * **show_progress** (*bool*) -- Whether to show tqdm progress
        bars. Defaults to False.
      * **include_embeddings** (*bool*) -- Whether to include
        embeddings in the index. Defaults to False.
      * **max_object_length** (*int*) -- The maximum length of the
        object in a triplet. Defaults to 128.
      * **kg_triplet_extract_fn** (*Optional**[**Callable**]*) -- The
        function to use for extracting triplets. Defaults to None.
   add_node(keywords: List[str], node: BaseNode) -> None
      Add node.
      Used for manual insertion of nodes (keyed by keywords).
      Parameters:
         * **keywords** (*List**[**str**]*) -- Keywords to index the
           node.
         * **node** (*Node*) -- Node to be indexed.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   get_networkx_graph(limit: int = 100) -> Any
      Get networkx representation of the graph structure.
      Parameters:
         **limit** (*int*) -- Number of starting nodes to be included
         in the graph.
      NOTE: This function requires networkx to be installed. NOTE:
      This is a beta feature.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.

Knowledge Graph Index

      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   upsert_triplet(triplet: Tuple[str, str, str]) -> None
      Insert triplets.
      Used for manual insertion of KG triplets (in the form of
      (subject, relationship, object)).
      Parameters:
         **triplet** (*str*) -- Knowledge triplet
   upsert_triplet_and_node(triplet: Tuple[str, str, str], node: BaseNode) -> None
      Upsert KG triplet and node.
      Calls both upsert_triplet and add_node. Behavior is idempotent;
      if Node already exists, only triplet will be added.
      Parameters:
         * **keywords** (*List**[**str**]*) -- Keywords to index the
           node.
         * **node** (*Node*) -- Node to be indexed.
class llama_index.indices.knowledge_graph.KnowledgeGraphRAGRetriever(service_context: Optional[ServiceContext] = None, storage_context: Optional[StorageContext] = None, entity_extract_fn: Optional[Callable] = None, entity_extract_template: Optional[BasePromptTemplate] = None, entity_extract_policy: Optional[str] = 'union', synonym_expand_fn: Optional[Callable] = None, synonym_expand_template: Optional[BasePromptTemplate] = None, synonym_expand_policy: Optional[str] = 'union', max_entities: int = 5, max_synonyms: int = 5, retriever_mode: Optional[str] = 'keyword', with_nl2graphquery: bool = False, graph_traversal_depth: int = 2, max_knowledge_sequence: int = 30, verbose: bool = False, **kwargs: Any)
   Knowledge Graph RAG retriever.
   Retriever that perform SubGraph RAG towards knowledge graph.
   Parameters:
      * **service_context** (*Optional**[**ServiceContext**]*) -- A
        service context to use.
      * **storage_context** (*Optional**[**StorageContext**]*) -- A
        storage context to use.
      * **entity_extract_fn** (*Optional**[**Callable**]*) -- A
        function to extract entities.
      * **Optional****[****BasePromptTemplate****]****)**
        (*entity_extract_template*) -- A Query Key Entity Extraction
        Prompt (see Prompt Templates).
      * **entity_extract_policy** (*Optional**[**str**]*) -- The
        entity extraction policy to use. default: "union" possible
        values: "union", "intersection"
      * **synonym_expand_fn** (*Optional**[**Callable**]*) -- A
        function to expand synonyms.

Knowledge Graph Index

      * **synonym_expand_template**
        (*Optional**[**QueryKeywordExpandPrompt**]*) -- A Query Key
        Entity Expansion Prompt (see Prompt Templates).
      * **synonym_expand_policy** (*Optional**[**str**]*) -- The
        synonym expansion policy to use. default: "union" possible
        values: "union", "intersection"
      * **max_entities** (*int*) -- The maximum number of entities to
        extract. default: 5
      * **max_synonyms** (*int*) -- The maximum number of synonyms to
        expand per entity. default: 5
      * **retriever_mode** (*Optional**[**str**]*) -- The retriever
        mode to use. default: "keyword" possible values: "keyword",
        "embedding", "keyword_embedding"
      * **with_nl2graphquery** (*bool*) -- Whether to combine
        NL2GraphQuery in context. default: False
      * **graph_traversal_depth** (*int*) -- The depth of graph
        traversal. default: 2
      * **max_knowledge_sequence** (*int*) -- The maximum number of
        knowledge sequence to include in the response. By default,
        it's 30.
      * **verbose** (*bool*) -- Whether to print out debug info.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.


Empty Index

Building the Empty Index
Empty Index.
class llama_index.indices.empty.EmptyIndex(index_struct: Optional[EmptyIndexStruct] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)
   Empty Index.
   An index that doesn't contain any documents. Used for pure LLM
   calls. NOTE: this exists because an empty index it allows certain
   properties, such as the ability to be composed with other indices +
   token counting + others.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)

Empty Index

           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.empty.EmptyIndexRetriever(index: EmptyIndex, input_prompt: Optional[BasePromptTemplate] = None, **kwargs: Any)
   EmptyIndex query.
   Passes the raw LLM call to the underlying LLM model.
   Parameters:
      **input_prompt** (*Optional**[**BasePromptTemplate**]*) -- A
      Simple Input Prompt (see Prompt Templates).
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
llama_index.indices.empty.GPTEmptyIndex
   alias of "EmptyIndex"


Summary Index

Building the Summary Index
List-based data structures.
llama_index.indices.list.GPTListIndex
   alias of "SummaryIndex"
llama_index.indices.list.ListIndex
   alias of "SummaryIndex"
llama_index.indices.list.ListIndexEmbeddingRetriever
   alias of "SummaryIndexEmbeddingRetriever"
llama_index.indices.list.ListIndexLLMRetriever
   alias of "SummaryIndexLLMRetriever"
llama_index.indices.list.ListIndexRetriever
   alias of "SummaryIndexRetriever"
class llama_index.indices.list.SummaryIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[IndexList] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any)
   Summary Index.
   The summary index is a simple data structure where nodes are stored
   in a sequence. During index construction, the document texts are
   chunked up, converted to nodes, and stored in a list.
   During query time, the summary index iterates through the nodes
   with some optional filter parameters, and synthesizes an answer
   from all the nodes.
   Parameters:
      * **text_qa_template** (*Optional**[**BasePromptTemplate**]*) --
        A Question-Answer Prompt (see Prompt Templates). NOTE: this is
        a deprecated field.
      * **show_progress** (*bool*) -- Whether to show tqdm progress
        bars. Defaults to False.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct

Summary Index

      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.list.SummaryIndexEmbeddingRetriever(index: SummaryIndex, similarity_top_k: Optional[int] = 1, **kwargs: Any)
   Embedding based retriever for SummaryIndex.
   Generates embeddings in a lazy fashion for all nodes that are
   traversed.
   Parameters:
      * **index** (*SummaryIndex*) -- The index to retrieve from.
      * **similarity_top_k** (*Optional**[**int**]*) -- The number of
        top nodes to return.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.list.SummaryIndexLLMRetriever(index: SummaryIndex, choice_select_prompt: Optional[PromptTemplate] = None, choice_batch_size: int = 10, format_node_batch_fn: Optional[Callable] = None, parse_choice_select_answer_fn: Optional[Callable] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)
   LLM retriever for SummaryIndex.
   Parameters:
      * **index** (*SummaryIndex*) -- The index to retrieve from.
      * **choice_select_prompt** (*Optional**[**PromptTemplate**]*) --
        A Choice-Select Prompt (see Prompt Templates).)
      * **choice_batch_size** (*int*) -- The number of nodes to query
        at a time.
      * **format_node_batch_fn** (*Optional**[**Callable**]*) -- A
        function that formats a batch of nodes.
      * **parse_choice_select_answer_fn** (*Optional**[**Callable**]*)
        -- A function that parses the choice select answer.
      * **service_context** (*Optional**[**ServiceContext**]*) -- A
        service context.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.list.SummaryIndexRetriever(index: SummaryIndex, **kwargs: Any)

Summary Index

   Simple retriever for SummaryIndex that returns all nodes.
   Parameters:
      **index** (*SummaryIndex*) -- The index to retrieve from.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.


Vector Store Index

Below we show the vector store index classes.
Each vector store index class is a combination of a base vector store
index class and a vector store, shown below.
Base vector store index.
An index that that is built on top of an existing vector store.
llama_index.indices.vector_store.base.GPTVectorStoreIndex
   alias of "VectorStoreIndex"
class llama_index.indices.vector_store.base.VectorStoreIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[IndexDict] = None, service_context: Optional[ServiceContext] = None, storage_context: Optional[StorageContext] = None, use_async: bool = False, store_nodes_override: bool = False, show_progress: bool = False, **kwargs: Any)
   Vector Store Index.
   Parameters:
      * **use_async** (*bool*) -- Whether to use asynchronous calls.
        Defaults to False.
      * **show_progress** (*bool*) -- Whether to show tqdm progress
        bars. Defaults to False.
      * **store_nodes_override** (*bool*) -- set to True to always
        store Node objects in index store and document store even if
        vector store keeps text. Defaults to False
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IndexDict
      Build the index from nodes.
      NOTE: Overrides BaseIndex.build_index_from_nodes.
         VectorStoreIndex only stores nodes in document store if
         vector store does not store text
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
      NOTE: overrides BaseIndex.insert_nodes.
         VectorStoreIndex only stores nodes in document store if
         vector store does not store text
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on

Vector Store Index

      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete


Table Index

Building the Keyword Table Index
Keyword Table Index Data Structures.
llama_index.indices.keyword_table.GPTKeywordTableIndex
   alias of "KeywordTableIndex"
llama_index.indices.keyword_table.GPTRAKEKeywordTableIndex
   alias of "RAKEKeywordTableIndex"
llama_index.indices.keyword_table.GPTSimpleKeywordTableIndex
   alias of "SimpleKeywordTableIndex"
class llama_index.indices.keyword_table.KeywordTableGPTRetriever(index: BaseKeywordTableIndex, keyword_extract_template: Optional[BasePromptTemplate] = None, query_keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_query: int = 10, num_chunks_per_query: int = 10, **kwargs: Any)
   Keyword Table Index GPT Retriever.
   Extracts keywords using GPT. Set when using
   *retriever_mode="default"*.
   See BaseGPTKeywordTableQuery for arguments.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.keyword_table.KeywordTableIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[KeywordTable] = None, service_context: Optional[ServiceContext] = None, keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_chunk: int = 10, use_async: bool = False, show_progress: bool = False, **kwargs: Any)
   Keyword Table Index.
   This index uses a GPT model to extract keywords from the text.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete(doc_id: str, **delete_kwargs: Any) -> None
      Delete a document from the index. All nodes in the index related
      to the index will be deleted.
      Parameters:
         **doc_id** (*str*) -- A doc_id of the ingested document
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   property docstore: BaseDocumentStore
      Get the docstore corresponding to the index.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   property index_struct: IS
      Get the index struct.
   index_struct_cls
      alias of "KeywordTable"
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.

Table Index

   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.keyword_table.KeywordTableRAKERetriever(index: BaseKeywordTableIndex, keyword_extract_template: Optional[BasePromptTemplate] = None, query_keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_query: int = 10, num_chunks_per_query: int = 10, **kwargs: Any)
   Keyword Table Index RAKE Retriever.
   Extracts keywords using RAKE keyword extractor. Set when
   *retriever_mode="rake"*.
   See BaseGPTKeywordTableQuery for arguments.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.keyword_table.KeywordTableSimpleRetriever(index: BaseKeywordTableIndex, keyword_extract_template: Optional[BasePromptTemplate] = None, query_keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_query: int = 10, num_chunks_per_query: int = 10, **kwargs: Any)
   Keyword Table Index Simple Retriever.
   Extracts keywords using simple regex-based keyword extractor. Set
   when *retriever_mode="simple"*.
   See BaseGPTKeywordTableQuery for arguments.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.

Table Index

   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.keyword_table.RAKEKeywordTableIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[KeywordTable] = None, service_context: Optional[ServiceContext] = None, keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_chunk: int = 10, use_async: bool = False, show_progress: bool = False, **kwargs: Any)
   RAKE Keyword Table Index.
   This index uses a RAKE keyword extractor to extract keywords from
   the text.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete(doc_id: str, **delete_kwargs: Any) -> None
      Delete a document from the index. All nodes in the index related
      to the index will be deleted.
      Parameters:
         **doc_id** (*str*) -- A doc_id of the ingested document
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   property docstore: BaseDocumentStore
      Get the docstore corresponding to the index.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   property index_struct: IS
      Get the index struct.
   index_struct_cls
      alias of "KeywordTable"
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.

Table Index

   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.keyword_table.SimpleKeywordTableIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[KeywordTable] = None, service_context: Optional[ServiceContext] = None, keyword_extract_template: Optional[BasePromptTemplate] = None, max_keywords_per_chunk: int = 10, use_async: bool = False, show_progress: bool = False, **kwargs: Any)
   Simple Keyword Table Index.
   This index uses a simple regex extractor to extract keywords from
   the text.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete(doc_id: str, **delete_kwargs: Any) -> None
      Delete a document from the index. All nodes in the index related
      to the index will be deleted.
      Parameters:
         **doc_id** (*str*) -- A doc_id of the ingested document
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   property docstore: BaseDocumentStore
      Get the docstore corresponding to the index.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   property index_struct: IS
      Get the index struct.
   index_struct_cls
      alias of "KeywordTable"
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]

Table Index


Structured Store Index

Structured store indices.
llama_index.indices.struct_store.GPTNLStructStoreQueryEngine
   alias of "NLStructStoreQueryEngine"
llama_index.indices.struct_store.GPTPandasIndex
   alias of "PandasIndex"
llama_index.indices.struct_store.GPTSQLStructStoreIndex
   alias of "SQLStructStoreIndex"
llama_index.indices.struct_store.GPTSQLStructStoreQueryEngine
   alias of "SQLStructStoreQueryEngine"
class llama_index.indices.struct_store.JSONQueryEngine(json_value: Optional[Union[Dict[str, Optional[Union[Dict[str, JSONType], List[JSONType], str, int, float, bool]]], List[Optional[Union[Dict[str, JSONType], List[JSONType], str, int, float, bool]]], str, int, float, bool]], json_schema: Optional[Union[Dict[str, Optional[Union[Dict[str, JSONType], List[JSONType], str, int, float, bool]]], List[Optional[Union[Dict[str, JSONType], List[JSONType], str, int, float, bool]]], str, int, float, bool]], service_context: ServiceContext, json_path_prompt: Optional[BasePromptTemplate] = None, output_processor: Optional[Callable] = None, output_kwargs: Optional[dict] = None, synthesize_response: bool = True, response_synthesis_prompt: Optional[BasePromptTemplate] = None, verbose: bool = False, **kwargs: Any)
   GPT JSON Query Engine.
   Converts natural language to JSON Path queries.
   Parameters:
      * **json_value** (*JSONType*) -- JSON value
      * **json_schema** (*JSONType*) -- JSON schema
      * **service_context** (*ServiceContext*) -- ServiceContext
      * **json_path_prompt** (*BasePromptTemplate*) -- The JSON Path
        prompt to use.
      * **output_processor** (*Callable*) -- The output processor that
        executes the JSON Path query.
      * **output_kwargs** (*dict*) -- Additional output processor
        kwargs for the output_processor function.
      * **verbose** (*bool*) -- Whether to print verbose output.
class llama_index.indices.struct_store.NLSQLTableQueryEngine(sql_database: SQLDatabase, text_to_sql_prompt: Optional[BasePromptTemplate] = None, context_query_kwargs: Optional[dict] = None, synthesize_response: bool = True, response_synthesis_prompt: Optional[BasePromptTemplate] = None, tables: Optional[Union[List[str], List[Table]]] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)
   Natural language SQL Table query engine.
   Read NLStructStoreQueryEngine's docstring for more info on NL SQL.
   property service_context: ServiceContext
      Get service context.
class llama_index.indices.struct_store.NLStructStoreQueryEngine(index: SQLStructStoreIndex, text_to_sql_prompt: Optional[BasePromptTemplate] = None, context_query_kwargs: Optional[dict] = None, synthesize_response: bool = True, response_synthesis_prompt: Optional[BasePromptTemplate] = None, **kwargs: Any)
   GPT natural language query engine over a structured database.
   NOTE: deprecated in favor of SQLTableRetriever, kept for backward
   compatibility.
   Given a natural language query, we will extract the query to SQL.
   Runs raw SQL over a SQLStructStoreIndex. No LLM calls are made
   during the SQL execution.
   NOTE: this query cannot work with composed indices - if the index
   contains subindices, those subindices will not be queried.
   Parameters:
      * **index** (*SQLStructStoreIndex*) -- A SQL Struct Store Index
      * **text_to_sql_prompt** (*Optional**[**BasePromptTemplate**]*)
        -- A Text to SQL BasePromptTemplate to use for the query.

Structured Store Index

        Defaults to DEFAULT_TEXT_TO_SQL_PROMPT.
      * **context_query_kwargs** (*Optional**[**dict**]*) -- Keyword
        arguments for the context query. Defaults to {}.
      * **synthesize_response** (*bool*) -- Whether to synthesize a
        response from the query results. Defaults to True.
      * **response_synthesis_prompt**
        (*Optional**[**BasePromptTemplate**]*) -- A Response Synthesis
        BasePromptTemplate to use for the query. Defaults to
        DEFAULT_RESPONSE_SYNTHESIS_PROMPT.
   property service_context: ServiceContext
      Get service context.
class llama_index.indices.struct_store.PandasIndex(df: DataFrame, nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[PandasStructTable] = None, **kwargs: Any)
   Pandas Index.
   Deprecated. Please use "PandasQueryEngine" instead.
   The PandasIndex is an index that stores a Pandas dataframe under
   the hood. Currently index "construction" is not supported.
   During query time, the user can either specify a raw SQL query or a
   natural language query to retrieve their data.
   Parameters:
      **pandas_df** (*Optional**[**pd.DataFrame**]*) -- Pandas
      dataframe to use. See Structured Index Configuration for more
      details.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:

Structured Store Index

         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.struct_store.SQLContextContainerBuilder(sql_database: SQLDatabase, context_dict: Optional[Dict[str, str]] = None, context_str: Optional[str] = None)
   SQLContextContainerBuilder.
   Build a SQLContextContainer that can be passed to the SQL index
   during index construction or during query-time.
   NOTE: if context_str is specified, that will be used as context
   instead of context_dict
   Parameters:
      * **sql_database** (*SQLDatabase*) -- SQL database
      * **context_dict** (*Optional**[**Dict**[**str**, **str**]**]*)
        -- context dict
   build_context_container(ignore_db_schema: bool = False) -> SQLContextContainer
      Build index structure.
   derive_index_from_context(index_cls: Type[BaseIndex], ignore_db_schema: bool = False, **index_kwargs: Any) -> BaseIndex
      Derive index from context.
   classmethod from_documents(documents_dict: Dict[str, List[BaseNode]], sql_database: SQLDatabase, **context_builder_kwargs: Any) -> SQLContextContainerBuilder
      Build context from documents.
   query_index_for_context(index: BaseIndex, query_str: Union[str, QueryBundle], query_tmpl: Optional[str] = 'Please return the relevant tables (including the full schema) for the following query: {orig_query_str}', store_context_str: bool = True, **index_kwargs: Any) -> str
      Query index for context.
      A simple wrapper around the index.query call which injects a
      query template to specifically fetch table information, and can
      store a context_str.
      Parameters:
         * **index** (*BaseIndex*) -- index data structure
         * **query_str** (*QueryType*) -- query string
         * **query_tmpl** (*Optional**[**str**]*) -- query template
         * **store_context_str** (*bool*) -- store context_str
class llama_index.indices.struct_store.SQLStructStoreIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[SQLStructTable] = None, service_context: Optional[ServiceContext] = None, sql_database: Optional[SQLDatabase] = None, table_name: Optional[str] = None, table: Optional[Table] = None, ref_doc_id_column: Optional[str] = None, sql_context_container: Optional[SQLContextContainer] = None, **kwargs: Any)
   SQL Struct Store Index.
   The SQLStructStoreIndex is an index that uses a SQL database under
   the hood. During index construction, the data can be inferred from
   unstructured documents given a schema extract prompt, or it can be
   pre-loaded in the database.
   During query time, the user can either specify a raw SQL query or a

Structured Store Index

   natural language query to retrieve their data.
   NOTE: this is deprecated.
   Parameters:
      * **documents**
        (*Optional**[**Sequence**[**DOCUMENTS_INPUT**]**]*) --
        Documents to index. NOTE: in the SQL index, this is an
        optional field.
      * **sql_database** (*Optional**[**SQLDatabase**]*) -- SQL
        database to use, including table names to specify. See
        Structured Index Configuration for more details.
      * **table_name** (*Optional**[**str**]*) -- Name of the table to
        use for extracting data. Either table_name or table must be
        specified.
      * **table** (*Optional**[**Table**]*) -- SQLAlchemy Table object
        to use. Specifying the Table object explicitly, instead of the
        table name, allows you to pass in a view. Either table_name or
        table must be specified.
      * **sql_context_container**
        (*Optional**[**SQLContextContainer**]*) -- SQL context
        container. an be generated from a SQLContextContainerBuilder.
        See Structured Index Configuration for more details.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType
      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.

Structured Store Index

      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.struct_store.SQLStructStoreQueryEngine(index: SQLStructStoreIndex, sql_context_container: Optional[SQLContextContainerBuilder] = None, **kwargs: Any)
   GPT SQL query engine over a structured database.
   NOTE: deprecated in favor of SQLTableRetriever, kept for backward
   compatibility.
   Runs raw SQL over a SQLStructStoreIndex. No LLM calls are made
   here. NOTE: this query cannot work with composed indices - if the
   index contains subindices, those subindices will not be queried.
class llama_index.indices.struct_store.SQLTableRetrieverQueryEngine(sql_database: SQLDatabase, table_retriever: ObjectRetriever[SQLTableSchema], text_to_sql_prompt: Optional[BasePromptTemplate] = None, context_query_kwargs: Optional[dict] = None, synthesize_response: bool = True, response_synthesis_prompt: Optional[BasePromptTemplate] = None, service_context: Optional[ServiceContext] = None, context_str_prefix: Optional[str] = None, **kwargs: Any)
   SQL Table retriever query engine.
   property service_context: ServiceContext
      Get service context.


Tree Index

Building the Tree Index
Tree-structured Index Data Structures.
llama_index.indices.tree.GPTTreeIndex
   alias of "TreeIndex"
class llama_index.indices.tree.TreeAllLeafRetriever(index: TreeIndex, **kwargs: Any)
   GPT all leaf retriever.
   This class builds a query-specific tree from leaf nodes to return a
   response. Using this query mode means that the tree index doesn't
   need to be built when initialized, since we rebuild the tree for
   each query.
   Parameters:
      **text_qa_template** (*Optional**[**BasePromptTemplate**]*) --
      Question-Answer Prompt (see Prompt Templates).
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.tree.TreeIndex(nodes: Optional[Sequence[BaseNode]] = None, index_struct: Optional[IndexGraph] = None, service_context: Optional[ServiceContext] = None, summary_template: Optional[BasePromptTemplate] = None, insert_prompt: Optional[BasePromptTemplate] = None, num_children: int = 10, build_tree: bool = True, use_async: bool = False, show_progress: bool = False, **kwargs: Any)
   Tree Index.
   The tree index is a tree-structured index, where each node is a
   summary of the children nodes. During index construction, the tree
   is constructed in a bottoms-up fashion until we end up with a set
   of root_nodes.
   There are a few different options during query time (see Querying
   an Index). The main option is to traverse down the tree from the
   root nodes. A secondary answer is to directly synthesize the answer
   from the root nodes.
   Parameters:
      * **summary_template** (*Optional**[**BasePromptTemplate**]*) --
        A Summarization Prompt (see Prompt Templates).
      * **insert_prompt** (*Optional**[**BasePromptTemplate**]*) -- An
        Tree Insertion Prompt (see Prompt Templates).
      * **num_children** (*int*) -- The number of children each node
        should have.
      * **build_tree** (*bool*) -- Whether to build the tree during
        index construction.
      * **show_progress** (*bool*) -- Whether to show progress bars.
        Defaults to False.
   build_index_from_nodes(nodes: Sequence[BaseNode]) -> IS
      Build the index from nodes.
   delete(doc_id: str, **delete_kwargs: Any) -> None
      Delete a document from the index. All nodes in the index related
      to the index will be deleted.
      Parameters:
         **doc_id** (*str*) -- A doc_id of the ingested document
   delete_nodes(node_ids: List[str], delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a list of nodes from the index.
      Parameters:
         **doc_ids** (*List**[**str**]*) -- A list of doc_ids from the
         nodes to delete
   delete_ref_doc(ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any) -> None
      Delete a document and it's nodes by using ref_doc_id.
   property docstore: BaseDocumentStore
      Get the docstore corresponding to the index.
   classmethod from_documents(documents: Sequence[Document], storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, show_progress: bool = False, **kwargs: Any) -> IndexType

Tree Index

      Create index from documents.
      Parameters:
         **documents**
         (*Optional**[**Sequence**[**BaseDocument**]**]*) -- List of
         documents to build the index from.
   property index_id: str
      Get the index struct.
   property index_struct: IS
      Get the index struct.
   index_struct_cls
      alias of "IndexGraph"
   insert(document: Document, **insert_kwargs: Any) -> None
      Insert a document.
   insert_nodes(nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None
      Insert nodes.
   property ref_doc_info: Dict[str, RefDocInfo]
      Retrieve a dict mapping of ingested documents and their
      nodes+metadata.
   refresh(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   refresh_ref_docs(documents: Sequence[Document], **update_kwargs: Any) -> List[bool]
      Refresh an index with documents that have changed.
      This allows users to save LLM and Embedding model calls, while
      only updating documents that have any changes in text or
      metadata. It will also insert any documents that previously were
      not stored.
   set_index_id(index_id: str) -> None
      Set the index id.
      NOTE: if you decide to set the index_id on the index_struct
      manually, you will need to explicitly call *add_index_struct* on
      the *index_store* to update the index store.
      Parameters:
         **index_id** (*str*) -- Index id to set.
   update(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
   update_ref_doc(document: Document, **update_kwargs: Any) -> None
      Update a document and it's corresponding nodes.
      This is equivalent to deleting the document and then inserting
      it again.
      Parameters:
         * **document** (*Union**[**BaseDocument**, **BaseIndex**]*)
           -- document to update
         * **insert_kwargs** (*Dict*) -- kwargs to pass to insert
         * **delete_kwargs** (*Dict*) -- kwargs to pass to delete
class llama_index.indices.tree.TreeRootRetriever(index: TreeIndex, **kwargs: Any)
   Tree root retriever.
   This class directly retrieves the answer from the root nodes.
   Unlike GPTTreeIndexLeafQuery, this class assumes the graph already
   stores the answer (because it was constructed with a query_str), so
   it does not attempt to parse information down the graph in order to
   synthesize an answer.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.tree.TreeSelectLeafEmbeddingRetriever(index: TreeIndex, query_template: Optional[BasePromptTemplate] = None, text_qa_template: Optional[BasePromptTemplate] = None, refine_template: Optional[BasePromptTemplate] = None, query_template_multiple: Optional[BasePromptTemplate] = None, child_branch_factor: int = 1, verbose: bool = False, **kwargs: Any)

Tree Index

   Tree select leaf embedding retriever.
   This class traverses the index graph using the embedding similarity
   between the query and the node text.
   Parameters:
      * **query_template** (*Optional**[**BasePromptTemplate**]*) --
        Tree Select Query Prompt (see Prompt Templates).
      * **query_template_multiple**
        (*Optional**[**BasePromptTemplate**]*) -- Tree Select Query
        Prompt (Multiple) (see Prompt Templates).
      * **text_qa_template** (*Optional**[**BasePromptTemplate**]*) --
        Question-Answer Prompt (see Prompt Templates).
      * **refine_template** (*Optional**[**BasePromptTemplate**]*) --
        Refinement Prompt (see Prompt Templates).
      * **child_branch_factor** (*int*) -- Number of child nodes to
        consider at each level. If child_branch_factor is 1, then the
        query will only choose one child node to traverse for any
        given parent node. If child_branch_factor is 2, then the query
        will choose two child nodes.
      * **embed_model** (*Optional**[**BaseEmbedding**]*) -- Embedding
        model to use for embedding similarity.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.
class llama_index.indices.tree.TreeSelectLeafRetriever(index: TreeIndex, query_template: Optional[BasePromptTemplate] = None, text_qa_template: Optional[BasePromptTemplate] = None, refine_template: Optional[BasePromptTemplate] = None, query_template_multiple: Optional[BasePromptTemplate] = None, child_branch_factor: int = 1, verbose: bool = False, **kwargs: Any)
   Tree select leaf retriever.
   This class traverses the index graph and searches for a leaf node
   that can best answer the query.
   Parameters:
      * **query_template** (*Optional**[**BasePromptTemplate**]*) --
        Tree Select Query Prompt (see Prompt Templates).
      * **query_template_multiple**
        (*Optional**[**BasePromptTemplate**]*) -- Tree Select Query
        Prompt (Multiple) (see Prompt Templates).
      * **child_branch_factor** (*int*) -- Number of child nodes to
        consider at each level. If child_branch_factor is 1, then the
        query will only choose one child node to traverse for any
        given parent node. If child_branch_factor is 2, then the query
        will choose two child nodes.
   get_service_context() -> Optional[ServiceContext]
      Attempts to resolve a service context. Short-circuits at
      self.service_context, self._service_context, or
      self._index.service_context.
   retrieve(str_or_query_bundle: Union[str, QueryBundle]) -> List[NodeWithScore]
      Retrieve nodes given query.
      Parameters:
         **str_or_query_bundle** (*QueryType*) -- Either a query
         string or a QueryBundle object.


PromptHelper

General prompt helper that can help deal with LLM context window token
limitations.
At its core, it calculates available context size by starting with the
context window size of an LLM and reserve token space for the prompt
template, and the output.
It provides utility for "repacking" text chunks (retrieved from index)
to maximally make use of the available context window (and thereby
reducing the number of LLM calls needed), or truncating them so that
they fit in a single LLM call.
pydantic model llama_index.indices.prompt_helper.PromptHelper
   Prompt helper.
   General prompt helper that can help deal with LLM context window
   token limitations.
   At its core, it calculates available context size by starting with
   the context window size of an LLM and reserve token space for the
   prompt template, and the output.
   It provides utility for "repacking" text chunks (retrieved from
   index) to maximally make use of the available context window (and
   thereby reducing the number of LLM calls needed), or truncating
   them so that they fit in a single LLM call.
   Parameters:
      * **context_window** (*int*) -- Context window for the LLM.
      * **num_output** (*int*) -- Number of outputs for the LLM.
      * **chunk_overlap_ratio** (*float*) -- Chunk overlap as a ratio
        of chunk size
      * **chunk_size_limit** (*Optional**[**int**]*) -- Maximum chunk
        size to use.
      * **tokenizer** (*Optional**[**Callable**[**[**str**]**,
        **List**]**]*) -- Tokenizer to use.
      * **separator** (*str*) -- Separator for text splitter
      {
         "title": "PromptHelper",
         "description": "Prompt helper.\n\nGeneral prompt helper that can help deal with LLM context window token limitations.\n\nAt its core, it calculates available context size by starting with the context\nwindow size of an LLM and reserve token space for the prompt template, and the\noutput.\n\nIt provides utility for \"repacking\" text chunks (retrieved from index) to maximally\nmake use of the available context window (and thereby reducing the number of LLM\ncalls needed), or truncating them so that they fit in a single LLM call.\n\nArgs:\n    context_window (int):                   Context window for the LLM.\n    num_output (int):                       Number of outputs for the LLM.\n    chunk_overlap_ratio (float):            Chunk overlap as a ratio of chunk size\n    chunk_size_limit (Optional[int]):         Maximum chunk size to use.\n    tokenizer (Optional[Callable[[str], List]]): Tokenizer to use.\n    separator (str):                        Separator for text splitter",
         "type": "object",
         "properties": {
            "context_window": {
               "title": "Context Window",
               "description": "The maximum context size that will get sent to the LLM.",
               "default": 3900,
               "type": "integer"
            },
            "num_output": {
               "title": "Num Output",
               "description": "The amount of token-space to leave in input for generation.",
               "default": 256,
               "type": "integer"
            },
            "chunk_overlap_ratio": {
               "title": "Chunk Overlap Ratio",
               "description": "The percentage token amount that each chunk should overlap.",
               "default": 0.1,
               "type": "number"
            },
            "chunk_size_limit": {
               "title": "Chunk Size Limit",
               "description": "The maximum size of a chunk.",
               "type": "integer"
            },
            "separator": {

PromptHelper

               "title": "Separator",
               "description": "The separator when chunking tokens.",
               "default": " ",
               "type": "string"
            }
         }
      }
   Fields:
      * "chunk_overlap_ratio (float)"
      * "chunk_size_limit (Optional[int])"
      * "context_window (int)"
      * "num_output (int)"
      * "separator (str)"
   field chunk_overlap_ratio: float = 0.1
      The percentage token amount that each chunk should overlap.
   field chunk_size_limit: Optional[int] = None
      The maximum size of a chunk.
   field context_window: int = 3900
      The maximum context size that will get sent to the LLM.
   field num_output: int = 256
      The amount of token-space to leave in input for generation.
   field separator: str = ' '
      The separator when chunking tokens.
   classmethod class_name() -> str
      Get the class name, used as a unique ID in serialization.
      This provides a key that makes serialization robust against
      actual class name changes.
   classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) -> Model
      Creates a new model setting __dict__ and __fields_set__ from
      trusted or pre-validated data. Default values are respected, but
      no other validation is performed. Behaves as if *Config.extra =
      'allow'* was set since it adds all passed values
   copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) -> Model
      Duplicate a model, optionally choose which fields to include,
      exclude and change.
      Parameters:
         * **include** -- fields to include in new model
         * **exclude** -- fields to exclude from new model, as with
           values this takes precedence over include
         * **update** -- values to change/add in the new model. Note:
           the data is not validated before creating the new model:
           you should trust this data
         * **deep** -- set to *True* to make a deep copy of the model
      Returns:
         new model instance
   dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> DictStrAny
      Generate a dictionary representation of the model, optionally
      specifying which fields to include or exclude.
   classmethod from_dict(data: Dict[str, Any], **kwargs: Any) -> Self
   classmethod from_json(data_str: str, **kwargs: Any) -> Self
   classmethod from_llm_metadata(llm_metadata: LLMMetadata, chunk_overlap_ratio: float = 0.1, chunk_size_limit: Optional[int] = None, tokenizer: Optional[Callable[[str], List]] = None, separator: str = ' ') -> PromptHelper
      Create from llm predictor.
      This will autofill values like context_window and num_output.
   classmethod from_orm(obj: Any) -> Model
   get_text_splitter_given_prompt(prompt: BasePromptTemplate, num_chunks: int = 1, padding: int = 5) -> TokenTextSplitter
      Get text splitter configured to maximally pack available context
      window, taking into account of given prompt, and desired number
      of chunks.
   json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) -> unicode

PromptHelper

      Generate a JSON representation of the model, *include* and
      *exclude* arguments as per *dict()*.
      *encoder* is an optional function to supply as *default* to
      json.dumps(), other arguments as per *json.dumps()*.
   classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) -> Model
   classmethod parse_obj(obj: Any) -> Model
   classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) -> Model
   repack(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = 5) -> List[str]
      Repack text chunks to fit available context window.
      This will combine text chunks into consolidated chunks that more
      fully "pack" the prompt template given the context_window.
   classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') -> DictStrAny
   classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) -> unicode
   to_dict(**kwargs: Any) -> Dict[str, Any]
   to_json(**kwargs: Any) -> str
   truncate(prompt: BasePromptTemplate, text_chunks: Sequence[str], padding: int = 5) -> List[str]
      Truncate text chunks to fit available context window.
   classmethod update_forward_refs(**localns: Any) -> None
      Try to update ForwardRefs on fields based on this Model,
      globalns and localns.
   classmethod validate(value: Any) -> Model