Find answers from the community

Updated 6 months ago

Is there a way to persist/store the DocumentSummaryIndex in a vector store or pg vector?

@kapa.ai Is there a way to persist/store the DocumentSummaryIndex in a vector store or pg vector?
k
2 comments
Please stand by @yiuhoward as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Yes, there is a way to persist or store the DocumentSummaryIndex in a vector store. You can use the storage_context.persist() method to persist the simple vector store to disk. This method is used in the context of LlamaIndex's storage context, which is by default in-memory.

Here is an example of how you can use it:

Plain Text
# initialize storage context (by default it's in-memory)
from llama_index.core import StorageContext
storage_context = StorageContext.from_defaults()

# add documents to the docstore
storage_context.docstore.add_documents(nodes)

# Define Summary Index and Vector Index over Same Data
from llama_index.core import SummaryIndex
from llama_index.core import VectorStoreIndex

summary_index = SummaryIndex(nodes, storage_context=storage_context)
vector_index = VectorStoreIndex(nodes, storage_context=storage_context)

# persist simple vector store to disk
storage_context.persist()


In this example, nodes is the data you want to index. The SummaryIndex and VectorStoreIndex are created with the data and the storage context. Finally, the persist() method is called on the storage context to store the vector store to disk.

Please note that the persist() method can also take a directory as an argument if you want to specify where to store the data, like so: storage_context.persist(persist_dir="./storage").

For more details, you can refer to the LlamaIndex documentation ().

As for storing the DocumentSummaryIndex in a pg vector, the provided knowledge sources do not contain any information on this.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord