Find answers from the community

Updated 3 months ago

Recreate the storage context

I ran across a problem with the following code: llama_index import StorageContext, load_index_from_storage

Recreate the storage context

StorageContext.from_defaults(persist_dir='./storage') storage_context
index load = load_index_from_storage(storage_context)

When I load a new document to generate a vector index, it creates a new vector index file, but I want to build a vector index in append mode, which stores my vector from the previous file as well as creates a vector index for the new file.

can some body help me with it
W
1 comment
You can append new files by adding Document object to the existing Index.

Code structure would look something like this
Plain Text
service_context = ServiceContext.from_defaults()
doc = Document(text="this is a document lol!")
new_index = GPTVectorStoreIndex.from_documents([doc], service_context=service_context)
new_index.as_query_engine().query("hello world")
new_index.storage_context.persist()

# creating a new doc 
doc = Document(text="this is awesome news")
# appending the new doc to the existing index
new_index.insert(doc)
# persisting the new changes into the storage folder
new_index.storage_context.persist()
Add a reply
Sign up and join the conversation on Discord