Find answers from the community

Updated 2 months ago

How to update documents extra_info of an exists GPTSimpleVectorIndex?

How to update documents extra_info of an exists GPTSimpleVectorIndex?
k
2 comments
Please stand by @Quentin as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
To update a document's extra_info in an existing GPTSimpleVectorIndex, you can use the update method. First, you need to create a new document with the updated extra_info and then call the update method with the new document as an argument. Here's an example based on the information provided in the extracts:

Plain Text
from gpt_index import GPTSimpleVectorIndex, Document

# Assuming you have an existing GPTSimpleVectorIndex called 'index'

# Create a new Document with the updated extra_info
updated_document = Document(
    id="document_id",  # Replace with the ID of the document you want to update
    text="document_text",  # Replace with the text of the document you want to update
    extra_info={"new_key": "new_value"}  # Replace with the updated extra_info
)

# Update the document in the index
index.update(updated_document)


Keep in mind that the update method is equivalent to deleting the document and then inserting it again. So, it will use the insert and delete methods internally. You can also pass additional keyword arguments to these methods using insert_kwargs and delete_kwargs if needed.

Source: (https://gpt-index.readthedocs.io/en/latest/reference/indices/vector_store.html)
----------------------
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