-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathcustom_loader.py
More file actions
27 lines (22 loc) · 868 Bytes
/
custom_loader.py
File metadata and controls
27 lines (22 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Create a custom data loader to transform content into text."""
from pathlib import Path
from typing import Dict, Optional, Union
from fsspec import AbstractFileSystem
from neo4j_graphrag.experimental.components.data_loader import DataLoader
from neo4j_graphrag.experimental.components.types import DocumentInfo, LoadedDocument
class MyLoader(DataLoader):
async def run(
self,
filepath: Union[str, Path],
metadata: Optional[Dict[str, str]] = None,
fs: Optional[Union[AbstractFileSystem, str]] = None,
) -> LoadedDocument:
# Implement logic here; use ``fs`` when reading from non-local storage.
_ = fs
return LoadedDocument(
text="<extracted text>",
document_info=DocumentInfo(
path=str(filepath),
metadata=metadata,
),
)