Find answers from the community

Updated 3 months ago

while trying to create index from nodes

while trying to create index from nodes

running into this error when no of documents is more

TypeError Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 index = VectorStoreIndex(nodes, service_context=service_context)
2 index.storagecontext.persist("./storageall"+str(len(documents)))

File ~/anaconda3/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py:52, in VectorStoreIndex.init(self, nodes, index_struct, service_context, storage_context, use_async, store_nodes_override, insert_batch_size, show_progress, kwargs) 50 self._store_nodes_override = store_nodes_override 51 self._insert_batch_size = insert_batch_size---> 52 super().init( 53 nodes=nodes, 54 index_struct=index_struct, 55 service_context=service_context, 56 storage_context=storage_context, 57 show_progress=show_progress, 58 kwargs,
59 )

File ~/anaconda3/lib/python3.9/site-packages/llama_index/indices/base.py:51, in BaseIndex.init(self, nodes, index_struct, storage_context, service_context, show_progress, **kwargs)
49 raise ValueError("Only one of nodes or index_struct can be provided.")
50 # This is to explicitly make sure that the old UX is not used
---> 51 if nodes is not None and len(nodes) >= 1 and not isinstance(nodes[0], BaseNode):
52 if isinstance(nodes[0], Document):
53 raise ValueError(
54 "The constructor now takes in a list of Node objects. "
55 "Since you are passing in a list of Document objects, "
56 "please use from_documents instead."
57 )

TypeError: 'dict_values' object is not subscriptable
L
a
15 comments
whoops, should be list(index.docstore.docs.values)
classic python being silly
anything that i need to do at my end?
It's complaining that nodes is not a list
so you probably need to do list(nodes)
but this error is not thrown when no of docs is lower
It's unrelated to the number of docs
this is merely a type issue
and related to how you are getting the nodes
but i dont see this error when no of nodes is lower, i mean i dont have to typecast it to list
hard to say without seeing your code, but I can say almost 100% its not related to the number of nodes.

The error is on this line
if nodes is not None and len(nodes) >= 1 and not isinstance(nodes[0], BaseNode):

And the error is
TypeError: 'dict_values' object is not subscriptable

This would only happen if the nodes passed in has type dict_values instead of list
index = VectorStoreIndex(list(nodes), service_context=service_context)
Make the change above, it will work
no problem..i will keep it list(nodes) going forward
Add a reply
Sign up and join the conversation on Discord