Find answers from the community

Updated 3 months ago

Hey All I am trying to use the example

Hey All, I am trying to use the example to persist StorageContext through storage_context.persist(), however when I build a TreeIndex and set index_store = tree_index it says :

Plain Text
 Attribute Error: 'TreeIndex' object has no attribute 'persist.'


Question: Should I be able to persist TreeIndex this way? I am trying to take the route of documents --> node_parsing --> index building (with TreeIndex) --> persisting
L
J
14 comments
You just be able to build your tree index and do index.storage_context.persist(...)

No need to adjust the index store
got it, let me try that out, thanks.
Worked, thanks!
I am a still getting used to storage_context and service_context and how to define them in the flow. I have seen quite a few ways to do it (explicit variables vs global definition) on the ipynb so bruteforcing at best with it.
yea that makes sense! It maybe takes a little bit to get used to πŸ™‚
How can I read the tree index back from memory? Should I instantiate StorageContext.from_defaults(index_store = TreeIndex.from_persist()) ? Another options I see is TreeIndex.from_dict but I would have to define the path.
you can do this

Plain Text
from llama_index import load_index_from_storage, StorageContext

storage_context = StorageContext.from_defaults(...)
index = load_index_from_storage(storage_context, service_context=service_context)


The service context is optional though, if you didn't customize it don't worry about it
can I pass the argument of the file name instead of index_id?
I was able to save it down and see it in llama_index_storage.storage_context.py in the persist argument but reading back only using the index_id
Guess I could create a directory per index and read it in that way
There's no singular file, it's a collection of 3 files. You can pass in the persist_dir to from defaults
but would be little extra work
storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context, service_context=service_context)
ok thanks let me test it, thanks again, promising im running code and failing in between πŸ˜›
Add a reply
Sign up and join the conversation on Discord