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
This commit is contained in:
Kayvane Shakerifar 2023-03-12 16:29:27 +00:00 committed by GitHub
parent c9b5a30b37
commit 7e550df6d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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