Skip to content
Snippets Groups Projects
Unverified Commit 72cf9578 authored by Ming's avatar Ming Committed by GitHub
Browse files

Clarify that one needs to explicitly pass custom `persist_dir` to `storage_context.persist` (#9694)

parent 9e73564c
No related branches found
No related tags found
No related merge requests found
...@@ -95,15 +95,16 @@ from llama_index import ( ...@@ -95,15 +95,16 @@ from llama_index import (
) )
# check if storage already exists # check if storage already exists
if not os.path.exists("./storage"): PERSIST_DIR = "./storage"
if not os.path.exists(PERSIST_DIR):
# load the documents and create the index # load the documents and create the index
documents = SimpleDirectoryReader("data").load_data() documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents) index = VectorStoreIndex.from_documents(documents)
# store it for later # store it for later
index.storage_context.persist() index.storage_context.persist(persist_dir=PERSIST_DIR)
else: else:
# load the existing index # load the existing index
storage_context = StorageContext.from_defaults(persist_dir="./storage") storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
index = load_index_from_storage(storage_context) index = load_index_from_storage(storage_context)
# either way we can now query the index # either way we can now query the index
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment