Last active 1730463995

cache.py Raw
1@st.cache_data
2def load_index(data_version):
3 if not os.path.exists(INDEX_DIR) or not os.listdir(INDEX_DIR):
4 documents = SimpleDirectoryReader(DATA_DIR, recursive=True).load_data()
5 index = VectorStoreIndex.from_documents(documents)
6 index.storage_context.persist(persist_dir=INDEX_DIR)
7 else:
8 storage_context = StorageContext.from_defaults(persist_dir=INDEX_DIR)
9 index = load_index_from_storage(storage_context)
10 return index