Indexing our PITS study materials – hands-on
With a solid understanding of how indexing works in LlamaIndex, we’re now ready to implement the indexing logic in our tutoring application.
Let’s create the index_builder.py
module. This module takes care of Index creation. In the current implementation, it creates two Indexes: a VectorStoreIndex
and a TreeIndex
. As you can see, this is a very basic implementation and there is definitely room for improvement. Let’s handle the imports first:
from llama_index.core import ( VectorStoreIndex, TreeIndex, load_index_from_storage) from llama_index.core import StorageContext from global_settings import INDEX_STORAGE from document_uploader import ingest_documents
Next, we’ll implement our Index building function:
def build_indexes(nodes): try: storage_context = StorageContext.from_defaults( ...