Jeevant10 commited on
Commit
9adf25b
·
1 Parent(s): c95a8f6

Add: filter out invalid documents in load_all_documents function

Browse files
Files changed (1) hide show
  1. src/data_loader.py +16 -1
src/data_loader.py CHANGED
@@ -118,7 +118,22 @@ def load_all_documents(data_dir: str) -> List[Any] :
118
 
119
 
120
  print(f"[DEBUG] Total Loaded Documents : {len(document)}")
121
- return document
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
 
124
  if __name__ == '__main__':
 
118
 
119
 
120
  print(f"[DEBUG] Total Loaded Documents : {len(document)}")
121
+
122
+ # Filter out documents with None or non-string page_content
123
+ valid_documents = []
124
+ invalid_count = 0
125
+ for doc in document:
126
+ content = getattr(doc, 'page_content', None)
127
+ if content is not None and isinstance(content, str):
128
+ valid_documents.append(doc)
129
+ else:
130
+ invalid_count += 1
131
+
132
+ if invalid_count > 0:
133
+ print(f"[WARNING] Filtered out {invalid_count} documents with invalid page_content (None or non-string)")
134
+
135
+ print(f"[DEBUG] Valid Documents after filtering : {len(valid_documents)}")
136
+ return valid_documents
137
 
138
 
139
  if __name__ == '__main__':