delete_ref_doc
method. This method deletes a document and its nodes using the reference document ID (ref_doc_id
). Here is an example of how to use it:index.delete_ref_doc("doc_id_0", delete_from_docstore=True)
"doc_id_0"
is the ID of the document you want to delete. The delete_from_docstore
parameter is optional and defaults to False
. If you set it to True
, it will also delete the document from the document store.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:ref_doc_id
based on the filename, you can use the SimpleDirectoryReader
from LlamaIndex. When using the SimpleDirectoryReader
, you can automatically set the document id_
to be the full path to each document, which in this case would be the filename. Here is an example of how to use it:from llama_index import SimpleDirectoryReader documents = SimpleDirectoryReader("./data", filename_as_id=True).load_data() print([x.doc_id for x in documents])
./data
is the directory where your documents are stored. The filename_as_id=True
argument sets the document id_
to be the filename. The load_data()
function loads the data from the directory. The print
statement prints out the doc_id
for each document in the documents
list, which in this case would be the filenames.doc_id
is the same as the ref_doc_id
in this context.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:get_all_documents
method from the index object. Here is an example of how to use it:documents = index.get_all_documents()
index
is your index object. The get_all_documents()
function returns a list of all documents in the index. You can then iterate over this list to access each document.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:doc_id
and ref_doc_id
are used interchangeably to refer to the unique identifier of a document in the index or document store. doc_id
or ref_doc_id
as the parameter for the delete_ref_doc
method.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:delete_ref_doc
and delete_document
methods in LlamaIndex's Document Store (docstore
) both serve to delete documents, but they operate slightly differently.delete_ref_doc(ref_doc_id: str, raise_error: bool = True)
: This method deletes a reference document (ref_doc
) and all its associated nodes from the document store. The ref_doc_id
is the unique identifier of the reference document you want to delete.delete_document(doc_id: str, raise_error: bool = True)
: This method deletes a document from the document store. The doc_id
is the unique identifier of the document you want to delete.delete_ref_doc
not only deletes the document but also all its associated nodes, while delete_document
only deletes the document.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon: