Langchain4j 文档处理
文档加载器 Document Loader
常见文档加载器
-
来自 langchain4j 模块的文件系统文档加载器(FileSystemDocumentLoader)
-
来自 langchain4j 模块的类路径文档加载器(ClassPathDocumentLoader)
-
来自 langchain4j 模块的网址文档加载器(UrlDocumentLoader)
-
来自 langchain4j-document-loader-amazon-s3 模块的亚马逊 S3 文档加载器(AmazonS3DocumentLoader)
-
来自 langchain4j-document-loader-azure-storage-blob 模块的 Azure Blob 存储文档加载器(AzureBlobStorageDocumentLoader)
-
来自 langchain4j-document-loader-github 模块的 GitHub 文档加载器(GitHubDocumentLoader)
-
来自 langchain4j-document-loader-google-cloud-storage 模块的谷歌云存储文档加载器(GoogleCloudStorageDocumentLoader)
-
来自 langchain4j-document-loader-selenium 模块的 Selenium 文档加载器(SeleniumDocumentLoader)
-
来自 langchain4j-document-loader-tencent-cos 模块的腾讯云对象存储文档加载器(TencentCosDocumentLoader)
测试文档加载
测试的文档都放在项目的resources/knowledge目录下。目前只测试前三中langchain4j自带的文档加载器。
FileSystemDocumentLoader
FileSystemDocumentLoader 不能够使用相对路径,只能够使用绝对路径.
@Test
public void testFileSystemDocumentLoader() {
// 使用FileSystemDocumentLoader读取指定目录下的知识库文档
// 并使用默认的文档解析器TextDocumentParser对文档进行解析
// 确保文件路径正确,资源位于classpath:knowledge/人工智能.md
Document document = FileSystemDocumentLoader.loadDocument("D:\\AI_Item\\ai-agent\\MyAI\\src\\main\\resources\\knowledge\\人工智能.md");
// 输出文档内容
System.out.println(document.text());
// 加载单个文档
Document documentOne = FileSystemDocumentLoader.loadDocument("D:\\AI_Item\\ai-agent\\MyAI\\src\\main\\resources\\knowledge\\科室信息.txt", new TextDocumentParser());
// 从一个目录中加载所有文档
List<Document> documents = FileSystemDocumentLoader.loadDocuments("D:\\AI_Item\\ai-agent\\MyAI\\src\\main\\resources\\knowledge", new TextDocumentParser());
// 从一个目录中加载所有的.txt文档
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:*.txt");
List<Document> documentsTxtAll= FileSystemDocumentLoader.loadDocuments("D:\\AI_Item\\ai-agent\\MyAI\\src\\main\\resources\\knowledge", pathMatcher, new TextDocumentParser());
// 从一个目录及其子目录中加载所有文档
List<Document> documentsAll = FileSystemDocumentLoader.loadDocumentsRecursively("D:\\AI_Item\\ai-agent\\MyAI\\src\\main\\resources\\knowledge", new TextDocumentParser());
}
ClassPathDocumentLoader
ClassPathDocumentLoade

最低0.47元/天 解锁文章
2285

被折叠的 条评论
为什么被折叠?



