Indices

This doc shows both the overarching class used to represent an index. These classes allow for index creation, insertion, and also querying. We first show the different index subclasses. We then show the base class that all indices inherit from, which contains parameters and methods common to all indices.


Base Index Class

Base index classes.

class llama_index.indices.base.BaseGPTIndex(nodes: Optional[Sequence[Node]] = None, index_struct: Optional[IS] = None, storage_context: Optional[StorageContext] = None, service_context: Optional[ServiceContext] = None, **kwargs: Any)

Base LlamaIndex.

Parameters
  • nodes (List[Node]) – List of nodes to index

  • service_context (ServiceContext) – Service context container (contains components like LLMPredictor, PromptHelper, etc.).

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) – document 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, **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.

insert(document: Document, **insert_kwargs: Any) None

Insert a document.

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 extra_info. 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.

This is equivalent to deleting the document and then inserting it again.

Parameters
  • document (Union[BaseDocument, BaseGPTIndex]) – document to update

  • insert_kwargs (Dict) – kwargs to pass to insert

  • delete_kwargs (Dict) – kwargs to pass to delete