feat: add lookup index to csv loader to make retrieving the original … (#1612)

feat: add lookup index to csv loader to make retrieving the original csv
information easier using theDocument properties
tool-patch
Kayvane Shakerifar 1 year ago committed by GitHub
parent c9b5a30b37
commit 7e550df6d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,13 +34,13 @@ class CSVLoader(BaseLoader):
with open(self.file_path, newline="") as csvfile: with open(self.file_path, newline="") as csvfile:
csv = DictReader(csvfile, **self.csv_args) # type: ignore csv = DictReader(csvfile, **self.csv_args) # type: ignore
for row in csv: for i, row in enumerate(csv):
docs.append( docs.append(
Document( Document(
page_content="\n".join( page_content="\n".join(
f"{k.strip()}: {v.strip()}" for k, v in row.items() f"{k.strip()}: {v.strip()}" for k, v in row.items()
), ),
metadata={"source": self.file_path}, metadata={"source": self.file_path, "row": i},
) )
) )

Loading…
Cancel
Save