Find answers from the community

Updated 2 months ago

I want to persist an index to storage

I want to persist an index to storage (directory). I also want to be able to load that index from storage when I rerun my script.

But what happens on the first run, when no index has been created? what will load_index_from_storage(storage_context) return?

In other words, I want to:

Plain Text
    index = load_index_from_storage(storage_context)
    if(#WHEN INDEX IS NOT TRUTHY / ON FIRST RUN#):
      index = ListIndex.from_defaults(...)
      index.persist()


so I can load the index, or create it on first run.

Suggestions?
L
1 comment
You can check if the directory exists that you are loading from? Otherwise, it will probably throw some exception, so you can do a try/catch
Add a reply
Sign up and join the conversation on Discord