forked from Archives/langchain
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:
parent
c9b5a30b37
commit
7e550df6d4
@ -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…
Reference in New Issue
Block a user