from llama_index import VectorStoreIndex, Document, StorageContext
from llama_index.vector_stores import ChromaVectorStore
import chromadb
client = chromadb.PersistentClient(path="./chroma_db")
collection = client.get_or_create_collection("new")
vector_store = ChromaVectorStore(chroma_collection=collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents([Document.example()], storage_context=storage_context, store_nodes_override=True)
index.storage_context.docstore.persist(persist_path="./chroma_db/docstore.json")
index.storage_context.index_store.persist(persist_path="./chroma_db/index_store.json")
print(index.ref_doc_info)
from llama_index.storage.docstore import SimpleDocumentStore
from llama_index.storage.index_store import SimpleIndexStore
new_storage_context = StorageContext.from_defaults(
docstore=SimpleDocumentStore.from_persist_path("./chroma_db/docstore.json"),
index_store=SimpleIndexStore.from_persist_path("./chroma_db/index_store.json"),
vector_store=ChromaVectorStore(chroma_collection=collection),
)
from llama_index import load_index_from_storage
new_index = load_index_from_storage(new_storage_context, store_nodes_override=True)
print(new_index.ref_doc_info)