from pathlib import Path
from typing import Dict
def make_meta_func(department: str, upload_user: str):
"""工厂:返回一个符合签名的 metadata 函数"""
def rich_meta(fp: Path) -> Dict[str, str]:
stat = fp.stat()
return {
"file_name": fp.name,
"department": department, # 外部绑进来的
"upload_user": upload_user, # 外部绑进来的
"create_time": datetime.fromtimestamp(stat.st_ctime).isoformat(),
"confidential": "internal",
}
return rich_meta
# 使用
documents = SimpleDirectoryReader(
"data",
file_metadata=make_meta_func(department="ABC", upload_user="sam")
).load_data()
文档添加多个metadata数据
发表评论