Find answers from the community

Updated 2 months ago

documents = SimpleDirectoryReader( input_files=pdf_docs , file_extractor=file_extracto

documents = SimpleDirectoryReader(
input_files=pdf_docs , file_extractor=file_extractor, recursive=True
).load_data()

how to add up a single file which was failed for parsing after the documents are parsed completely
k
2 comments
Please stand by @payload as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
If a file fails to load during the parsing process, the SimpleDirectoryReader class in LlamaIndex will report the error and skip the file, continuing with the rest of the files. If you want to add a single file that failed during the initial parsing, you can simply create a new instance of SimpleDirectoryReader with that single file as the input_files parameter and call the load_data() method. This will return a list of documents from the file which you can then extend to your original list of documents.

Here is an example of how you can do this:

Plain Text
failed_file = "path/to/failed/file"
try:
    failed_docs = SimpleDirectoryReader(
        input_files=[failed_file], 
        file_extractor=file_extractor
    ).load_data()
    documents.extend(failed_docs)
except Exception as e:
    print(f"Failed to load file {failed_file} with error: {e}.")


In this code, failed_file is the path to the file that failed during the initial parsing. The load_data() method is called on a new SimpleDirectoryReader instance with failed_file as the input. The resulting documents are then added to the original list of documents using the extend() method.

Please note that this code assumes that the error that caused the file to fail during the initial parsing has been resolved. If the same error is still present, this code will also fail to load the file.

For more information, you can refer to the SimpleDirectoryReader documentation ().
----------------------
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