Find answers from the community

Updated 4 months ago

Indexnode creation and vector store index setup

At a glance
The community member created an IndexNode and used the VectorStoreIndex to save it, but found that the obj attribute was not being saved correctly. This caused issues with the retriever. A comment suggests that the community member can just pass the IndexNode directly, without using the objects parameter of VectorStoreIndex, as that is generally for non-serializable objects. The community member acknowledged this suggestion.
I create an Indexnode as follows:

Plain Text
indexnode = IndexNode.from_text_node(node, index_id=node.id_)
indexnode.id_ = str(uuid.uuid4())
indexnode.obj = node


Then, I use the following code:

Plain Text
from llama_index.core import StorageContext
storage_context = StorageContext.from_defaults()
index = VectorStoreIndex(
    storage_context=storage_context,
    objects=index_nodes,
)
index.set_index_id("index")
index.storage_context.docstore.add_documents(nodes)
index.storage_context.persist()


However, after running the above code, index.storage_context.docstore.docs['xxxx'].obj is None and cannot be restored by assignment.
This causes my Retriever to be unable to automatically enter into the textNode.
So what is the correct way to save an IndexNode with the obj attribute?
L
Y
2 comments
you can just pass it in like any other node, no need to use objects=

VectorStoreIndex(nodes=<list of index nodes>)

objects is generally there for stuff that isn't serializable
Thanks, I just saw it.
Add a reply
Sign up and join the conversation on Discord