Find answers from the community

Updated 9 months ago

πŸ‘‹ when using `StorageContext.from_

πŸ‘‹ when using StorageContext.from_defaults(persist_dir) i get a FileNotFoundError: [Errno 2] No such file or .../docstore.json. shouldn't that be created if it doesn't exist (first time) and otherwise loaded in?
L
e
4 comments
It is indeed not created until you call storage_context.persist()
hm both

Plain Text
def make_or_load_memory_storage_context():
    memory_storage_context = StorageContext.from_defaults(persist_dir="/tmp/.engi/memory/storage_context/")
    memory_storage_context.persist("/tmp/.engi/memory/storage_context/")
    return memory_storage_context


and

Plain Text
def make_or_load_memory_storage_context():
    memory_storage_context = StorageContext.from_defaults(persist_dir="/tmp/.engi/memory/storage_context/")
    memory_storage_context.persist()
    return memory_storage_context


still error
this looks to work - is this typical pattern for sharing a storage context stored to disk throughout an app?
Plain Text
def make_or_load_memory_storage_context():
    try:
        memory_storage_context = StorageContext.from_defaults(
            persist_dir="/tmp/.engi/memory/storage_context/"
        )
    except Exception as e:
        print('persisting first')
        memory_storage_context = StorageContext.from_defaults()
        memory_storage_context.persist("/tmp/.engi/memory/storage_context/")
    return memory_storage_context
That is definitely the typical pattern
Add a reply
Sign up and join the conversation on Discord