admin管理员组

文章数量:1036112

GraphRAG失效?快用Prompt Tune适配文档的领域和语言

我最近在arXiv上下载RAG相关的论文,几百篇的论文,肉眼去一一观看实在是太难了。因此打算通过强大的GraphRAG索引这些文章的摘要,我希望GraphRAG能够根据实体提取和社群分区,能够告知我RAG的研究脉络和大概的研究领域。然而效果并不理想,提取出的实体和问答实在难以恭维,是GraphRAG失效了吗?今天让我们通过实验测试默认prompt索引与查询,并使用Prompt Tune对输入文档领域进行适配后的索引与查询,但是否会更好呢,让我们一探究竟。本文分为5小结,如何下载论文摘要、默认prompt索引查询与可视化,使用prompt tune进行领域适配索引查询和可视化,总结全文与不足。

1. 下载论文摘要

构建使用arXiv的高级检索,然后使用arXiv的pip包逐一获取摘要、作者、发表时间和下载链接等信息。

安装arXiv包

代码语言:javascript代码运行次数:0运行复制
pip install arxiv

通过arxiv的高级检索链接,获取按照时间排序的该领域的论文网页。然后通过BeautifulSoap提取出论文id后,我们使用arxiv包分别去获取论文的具体信息并保存为txt。

代码语言:javascript代码运行次数:0运行复制
def fetch_and_save_paper_info(paper_ids, txtfile, save_dir='pdfs'):
    # Create directory if it doesn't exist
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    for paper_id in paper_ids:
        # Fetch paper information using arxiv package
        paper = next(arxiv.Search(id_list=[paper_id]).results())
        title = paper.title.replace('/', '_')
        authors = ', '.join([author.name for author in paper.authors])
        abstract = paper.summary
        pdf_link = paper.pdf_url
        published = paper.published.date()

        # paper.download_pdf(save_dir, filename=f"[{published.strftime('%Y-%m')}]-{title}.pdf")
        # Write to TXT
        with open(f'abstracts/{title}.txt', 'w', encoding='utf-8') as txtfile:
            txtfile.write(f"Title: {title}\n")
            txtfile.write(f"Authors: {authors}\n")
            txtfile.write(f"Published: {published}\n")
            txtfile.write(f"Abstract: {abstract}\n")
            txtfile.write(f"PDF Link: {pdf_link}\n")

获取的文件大概如下所示,总共大约获取了261个论文。

代码语言:javascript代码运行次数:0运行复制
Title: A Method for Parsing and Vectorization of Semi-structured Data used in Retrieval Augmented Generation
Authors: Hang Yang, Jing Guo, Jianchuan Qi, Jinliang Xie, Si Zhang, Siqi Yang, Nan Li, Ming Xu
Published: 2024-05-07
Abstract: This paper presents a novel method for parsing and vectorizing
semi-structured data to enhance the functionality of Retrieval-Augmented
...
is available at .git.
PDF Link: .03989v2

2. GraphRAG索引和检索

2.1 索引构建

将获取的论文摘要等信息文本放入输入文件夹input,使用默认的Prompt开始索引。

代码语言:javascript代码运行次数:0运行复制
poetry run poe index --root .

经过漫长索引时间后,最终索引完成,由于每个文件都只有300多的Token导致实体提取时间变得异常的久,成本也成倍增加,我的DeepSeeker又被消耗了200万Token(

GraphRAG失效?快用Prompt Tune适配文档的领域和语言

我最近在arXiv上下载RAG相关的论文,几百篇的论文,肉眼去一一观看实在是太难了。因此打算通过强大的GraphRAG索引这些文章的摘要,我希望GraphRAG能够根据实体提取和社群分区,能够告知我RAG的研究脉络和大概的研究领域。然而效果并不理想,提取出的实体和问答实在难以恭维,是GraphRAG失效了吗?今天让我们通过实验测试默认prompt索引与查询,并使用Prompt Tune对输入文档领域进行适配后的索引与查询,但是否会更好呢,让我们一探究竟。本文分为5小结,如何下载论文摘要、默认prompt索引查询与可视化,使用prompt tune进行领域适配索引查询和可视化,总结全文与不足。

1. 下载论文摘要

构建使用arXiv的高级检索,然后使用arXiv的pip包逐一获取摘要、作者、发表时间和下载链接等信息。

安装arXiv包

代码语言:javascript代码运行次数:0运行复制
pip install arxiv

通过arxiv的高级检索链接,获取按照时间排序的该领域的论文网页。然后通过BeautifulSoap提取出论文id后,我们使用arxiv包分别去获取论文的具体信息并保存为txt。

代码语言:javascript代码运行次数:0运行复制
def fetch_and_save_paper_info(paper_ids, txtfile, save_dir='pdfs'):
    # Create directory if it doesn't exist
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    for paper_id in paper_ids:
        # Fetch paper information using arxiv package
        paper = next(arxiv.Search(id_list=[paper_id]).results())
        title = paper.title.replace('/', '_')
        authors = ', '.join([author.name for author in paper.authors])
        abstract = paper.summary
        pdf_link = paper.pdf_url
        published = paper.published.date()

        # paper.download_pdf(save_dir, filename=f"[{published.strftime('%Y-%m')}]-{title}.pdf")
        # Write to TXT
        with open(f'abstracts/{title}.txt', 'w', encoding='utf-8') as txtfile:
            txtfile.write(f"Title: {title}\n")
            txtfile.write(f"Authors: {authors}\n")
            txtfile.write(f"Published: {published}\n")
            txtfile.write(f"Abstract: {abstract}\n")
            txtfile.write(f"PDF Link: {pdf_link}\n")

获取的文件大概如下所示,总共大约获取了261个论文。

代码语言:javascript代码运行次数:0运行复制
Title: A Method for Parsing and Vectorization of Semi-structured Data used in Retrieval Augmented Generation
Authors: Hang Yang, Jing Guo, Jianchuan Qi, Jinliang Xie, Si Zhang, Siqi Yang, Nan Li, Ming Xu
Published: 2024-05-07
Abstract: This paper presents a novel method for parsing and vectorizing
semi-structured data to enhance the functionality of Retrieval-Augmented
...
is available at .git.
PDF Link: .03989v2

2. GraphRAG索引和检索

2.1 索引构建

将获取的论文摘要等信息文本放入输入文件夹input,使用默认的Prompt开始索引。

代码语言:javascript代码运行次数:0运行复制
poetry run poe index --root .

经过漫长索引时间后,最终索引完成,由于每个文件都只有300多的Token导致实体提取时间变得异常的久,成本也成倍增加,我的DeepSeeker又被消耗了200万Token(

本文标签: GraphRAG失效快用Prompt Tune适配文档的领域和语言