adelete_document
to delete the nodes from the docstore. I use the returned nodes node_id
field to delete, but I am getting this error message:list.remove(x): x not in list
node_id
?ag:dev: await mongo_storage_context.docstore.adelete_document( rag:dev: File "/opt/homebrew/lib/python3.11/site-packages/llama_index/core/storage/docstore/keyval_docstore.py", line 459, in adelete_document rag:dev: await self._aremove_ref_doc_node(doc_id) rag:dev: File "/opt/homebrew/lib/python3.11/site-packages/llama_index/core/storage/docstore/keyval_docstore.py", line 427, in _aremove_ref_doc_node rag:dev: ref_doc_obj.node_ids.remove(doc_id) rag:dev: ValueError: list.remove(x): x not in list
ref_doc_id
is not being set properly for nodes when insertingstorage_context.docstore.async_add_documents( nodes=batch, batch_size=len(batch), allow_update=True)
docs = storage_context.docstore.docs.values()
storage_context.docstore.async_add_documents( nodes=batch, batch_size=len(batch), allow_update=True)
docs = storage_context.docstore.docs.values()
await storage_context.docstore.adelete_document( doc_id=node_id)
list.remove(x): x not in list
.from llama_index.core.schema import Document from llama_index.core.node_parser import TokenTextSplitter from llama_index.storage.docstore.mongodb import MongoDocumentStore async def main(): docstore = MongoDocumentStore.from_host_and_port("localhost", 27017) document = Document.example() document.metadata = {} nodes = TokenTextSplitter(chunk_size=25, chunk_overlap=0)([document]) print(f"Adding {len(nodes)} nodes to the docstore.") await docstore.async_add_documents(nodes, batch_size=len(nodes), allow_update=True) nodes_dict = docstore.docs print(f"Retrieved {len(nodes_dict)} nodes from the docstore. Now deleting them.") for id_, node in nodes_dict.items(): await docstore.adelete_document(id_) if __name__ == "__main__": import asyncio asyncio.run(main())
if doc_id in ref_doc_obj.node_ids: # sanity check ref_doc_obj.node_ids.remove(doc_id)