documents and its name #11970
Replies: 1 comment
-
Hey there, @PradiptaAtByteIQMind-Graph2023! Back for more adventures in the land of code, I see. 😄 To retrieve all the documents and their names in separate lists using the from llama_index.core import SimpleDirectoryReader
# Initialize the reader for the directory
reader = SimpleDirectoryReader(input_dir="data/")
# Load the documents
docs = reader.load_data()
# Extract documents and their names into separate lists
documents = [doc.text for doc in docs] # Assuming each doc object has a 'text' attribute for its content
document_names = [doc.id_ for doc in docs] # Assuming each doc object has an 'id_' attribute for its name
print("Documents:", documents)
print("Document Names:", document_names) This code assumes that each document object loaded by The structure of the document objects returned by the
These attributes are populated based on the file's content, its metadata, and the configuration of the For more details, you can refer to the llama-index-core/llama_index/core/readers/file/base.py and llama-index-core/llama_index/core/schema.py files in the LlamaIndex codebase. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi
How to get all the documents and its name both in different list using SimpleDirectoryReader(input_dir="data/").load_data()
Thanks
Beta Was this translation helpful? Give feedback.
All reactions