VectorStoreIndex.from_documents(,,,, storage_context=storage_context, store_nodes_override=True)
storage_context = StorageContext.from_defaults(vector_store=vector_store) # create index index = VectorStoreIndex.from_documents( documents, storage_context=storage_context, service_context=service_context, store_nodes_override=True ) # save the docstore/index store locally index.storage_context.persist(persist_dir="./storage") # load the index new_storage_context = StorageContext.from_defaults(vector_store=vector_store, persist_dir="./storage") from llama_index import load_index_from_storage # optional service context loaded_index = load_index_from_storage(new_storage_context, service_context=service_context)
client = QdrantClient( path=config.persist_directory ) vector_store = QdrantVectorStore( client=client, collection_name=config.collection ) if automerge_documents: doc_store = DocumentStore() else: doc_store = None storage_context = StorageContext.from_defaults( docstore=doc_store, vector_store=vector_store ) index = VectorStoreIndex.from_documents( documents, storage_context=storage_context, service_context=service_context, show_progress=True, store_nodes_override=automerge_documents ) if automerge_documents: chunk_sizes = config.chunk_sizes or [2048, 512, 128] node_parser = HierarchicalNodeParser.from_defaults(chunk_sizes=chunk_sizes) nodes = node_parser.get_nodes_from_documents(documents) # leaf_nodes = get_leaf_nodes(nodes) # storage_context.docstore.add_documents(nodes) index.build_index_from_nodes(nodes=nodes) # index.docstore.add_documents(nodes) doc_store.add_documents(nodes) doc_store.add_documents(documents) index.docstore.persist(persist_path=os.path.join(config.persist_directory, "docstore.json"))
if config.persist_directory: if automerge_documents: doc_store = DocumentStore.from_persist_path( persist_path=os.path.join(config.persist_directory, "docstore.json") ) else: doc_store = None # load the database logging.info(f"loading local database...") client = QdrantClient( path=config.persist_directory, ) vector_store = QdrantVectorStore( client=client, collection_name=config.collection ) index = VectorStoreIndex.from_vector_store( vector_store, doc_store=doc_store, service_context=service_context, )
index.storage_context.docstore = doc_store
from_documents()
will store the documents in the dostore, because I have store_nodes_override=True
from_vector_store
now with this method.loaded_index = load_index_from_storage(new_storage_context, service_context=service_context)
most likely