Langchain4j 文档处理(7)

该文章已生成可运行项目,

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

本文章已经生成可运行项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值