Bootstrap

AI实战:深度构建基于RAGFlow本地知识库与定制化大模型的私有化应用实战

背景

随着信息量的指数级增长,传统搜索和问答系统面临无法满足实时、复杂需求的困境。为解决这一难题,RAGFlow 提供了一种结合检索与生成的新思路,通过深入理解文档和知识库,构建更精准的内容生成。

My实验环境:

1. 架构概述:结合检索和生成的协作系统

在 RAGFlow 中,检索模块和生成模块协同工作。首先,通过检索模块从知识库中挑选出与问题高度相关的内容,形成上下文,然后由生成模块处理这些内容并生成富有逻辑和背景的回答。此结构结合了多任务学习、深度学习等技术,通过复杂架构实现内容的自动化生成。

2. 知识库与数据处理:深度优化提升准确率

构建有效的知识库是 RAGFlow 系统的核心。数据清理、语义索引优化等预处理步骤,能有效提高检索模块效率。合理的知识库还需要对长文档内容进行精细分块处理,从而确保检索结果的相关性,提升最终生成内容的准确性。

3. 检索技术的创新实践

在检索模块中,RAGFlow 提出了多层级检索算法,比如将 Dense Passage Retrieval 与其他算法相结合,确保每一轮检索结果都高度相关。Top-K 策略、查询扩展等技术也在 RAGFlow 中得到应用,从而在大规模知识库中实现更加高效的检索。

4. 生成模块:深度生成与精准回答

生成模块借助 GPT 类模型和深度学习方法,使用动态模板和上下文处理技术生成内容,确保输出的逻辑性和准确度。通过实时反馈机制,系统还能在短时间内针对不同主题进行高效学习,使生成模块的输出逐步优化,贴近真实用户需求。

5. 反馈与持续优化机制

RAGFlow 支持基于用户反馈的持续改进。自动化反馈收集系统会监测生成内容的相关性和质量,并通过 BLEU、ROUGE 等多项指标进行评价。系统利用反馈进行算法调整,形成自动学习闭环,从而实现更加精准的回答生成。

6. 安全与合规性设计

信息安全是 RAGFlow 的另一大关注点。系统采用细粒度访问控制,确保私有数据和敏感信息的隔离存储。此外,通过严格的隐私保护和访问日志记录机制,RAGFlow 确保了生成内容在安全性和合规性上的高标准,避免敏感数据泄露风险。

针对所有自学遇到困难的同学们,我帮大家系统梳理大模型学习脉络,将这份 LLM大模型资料 分享出来:包括LLM大模型书籍、640套大模型行业报告、LLM大模型学习视频、LLM大模型学习路线、开源大模型学习教程等, 😝有需要的小伙伴,可以 扫描下方二维码领取🆓↓↓↓

👉[CSDN大礼包🎁:全网最全《LLM大模型入门+进阶学习资源包》免费分享(安全链接,放心点击)]()👈

总结

RAGFlow 在信息密集型生成任务中展现了前所未有的优势,成功地将检索与生成相结合,成为下一代智能信息检索的解决方案。这一最佳实践提供了面向未来的内容生成模型,对于复杂业务场景具有广泛的应用潜力。

English | 简体中文 | 日本語 | 한국어

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
在这里插入图片描述

Document | Roadmap | Twitter | Discord | Demo

📕 Table of Contents

  • 💡 What is RAGFlow?

  • 🎮 Demo

  • 📌 Latest Updates

  • 🌟 Key Features

  • 🔎 System Architecture

  • 🎬 Get Started

  • 🔧 Configurations

  • 🔧 Build a docker image without embedding models

  • 🔧 Build a docker image including embedding models

  • 🔨 Launch service from source for development

  • 📚 Documentation

  • 📜 Roadmap

  • 🏄 Community

  • 🙌 Contributing

💡 What is RAGFlow?

RAGFlow is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding. It offers a streamlined RAG workflow for businesses of any scale, combining LLM (Large Language Models) to provide truthful question-answering capabilities, backed by well-founded citations from various complex formatted data.

🎮 Demo

Try our demo at https://demo.ragflow.io.

🔥 Latest Updates

  • 2024-11-01 Adds keyword extraction and related question generation to the parsed chunk to improve the accuracy of retrieval.

  • 2024-09-13 Adds search mode for knowledge base Q&A.

  • 2024-09-09 Adds a medical consultant agent template.

  • 2024-08-22 Support text to SQL statements through RAG.

  • 2024-08-02 Supports GraphRAG inspired by graphrag and mind map.

🎉 Stay Tuned

⭐️ Star our repository to stay up-to-date with exciting new features and improvements! Get instant notifications for new releases! 🌟

🌟 Key Features

🍭 “Quality in, quality out”

  • Deep document understanding-based knowledge extraction from unstructured data with complicated formats.

  • Finds “needle in a data haystack” of literally unlimited tokens.

🍱 Template-based chunking

  • Intelligent and explainable.

  • Plenty of template options to choose from.

🌱 Grounded citations with reduced hallucinations

  • Visualization of text chunking to allow human intervention.

  • Quick view of the key references and traceable citations to support grounded answers.

🍔 Compatibility with heterogeneous data sources

  • Supports Word, slides, excel, txt, images, scanned copies, structured data, web pages, and more.

🛀 Automated and effortless RAG workflow

  • Streamlined RAG orchestration catered to both personal and large businesses.

  • Configurable LLMs as well as embedding models.

  • Multiple recall paired with fused re-ranking.

  • Intuitive APIs for seamless integration with business.

🔎 System Architecture

🎬 Get Started

📝 Prerequisites

  • CPU >= 4 cores

  • RAM >= 16 GB

  • Disk >= 50 GB

  • Docker >= 24.0.0 & Docker Compose >= v2.26.1

    If you have not installed Docker on your local machine (Windows, Mac, or Linux), see Install Docker Engine.

🚀 Start up the server

  1. Ensure vm.max_map_count >= 262144:

    To check the value of vm.max_map_count:

    $ sysctl vm.max\_map\_count
    
  2. Reset vm.max_map_count to a value at least 262144 if it is not.

    # In this case, we set it to 262144:  
    $ sudo sysctl -w vm.max\_map\_count=262144
    

    This change will be reset after a system reboot. To ensure your change remains permanent, add or update the vm.max_map_count value in /etc/sysctl.conf accordingly:

    vm.max\_map\_count=262144
    
  3. Clone the repo:

    $ git clone https://github.com/infiniflow/ragflow.git
    
  4. Build the pre-built Docker images and start up the server:

    The command below downloads the dev version Docker image for RAGFlow slim (dev-slim). Note that RAGFlow slim Docker images do not include embedding models or Python libraries and hence are approximately 1GB in size.

    $ cd ragflow/docker  
    $ docker compose -f docker-compose.yml up -d
    
  5. NOTE: A RAGFlow Docker image that includes embedding models and Python libraries is approximately 9GB in size and may take significantly longer time to load.

  • To download a RAGFlow slim Docker image of a specific version, update the RAGFlow_IMAGE variable in * docker/.env* to your desired version. For example, RAGFLOW_IMAGE=infiniflow/ragflow:v0.13.0-slim. After making this change, rerun the command above to initiate the download.

  • To download the dev version of RAGFlow Docker image including embedding models and Python libraries, update the RAGFlow_IMAGE variable in docker/.env to RAGFLOW_IMAGE=infiniflow/ragflow:dev. After making this change, rerun the command above to initiate the download.

  • To download a specific version of RAGFlow Docker image including embedding models and Python libraries, update the RAGFlow_IMAGE variable in docker/.env to your desired version. For example, RAGFLOW_IMAGE=infiniflow/ragflow:v0.13.0. After making this change, rerun the command above to initiate the download.

  1. Check the server status after having the server up and running:

    $ docker logs -f ragflow-server
    

    The following output confirms a successful launch of the system:

          \_\_\_\_   \_\_\_    \_\_\_\_\_\_ \_\_\_\_\_\_ \_\_                 
         / \_\_ \\ /   |  / \_\_\_\_// \_\_\_\_// /\_\_\_\_  \_      \_\_  
        / /\_/ // /| | / / \_\_ / /\_   / // \_\_ \\| | /| / /  
       / \_, \_// \_\_\_ |/ /\_/ // \_\_/  / // /\_/ /| |/ |/ /   
      /\_/ |\_|/\_/  |\_|\\\_\_\_\_//\_/    /\_/ \\\_\_\_\_/ |\_\_/|\_\_/   
      
     \* Running on all addresses (0.0.0.0)  
     \* Running on http://127.0.0.1:9380  
     \* Running on http://x.x.x.x:9380  
     INFO:werkzeug:Press CTRL+C to quit
    

    If you skip this confirmation step and directly log in to RAGFlow, your browser may prompt a network abnormal error because, at that moment, your RAGFlow may not be fully initialized.

  2. In your web browser, enter the IP address of your server and log in to RAGFlow.

    With the default settings, you only need to enter http://IP_OF_YOUR_MACHINE (sans port number) as the default HTTP serving port 80 can be omitted when using the default configurations.

  3. In service_conf.yaml, select the desired LLM factory in user_default_llm and update the API_KEY field with the corresponding API key.

    See llm_api_key_setup for more information.

    _The show is on!

    _

🔧 Configurations

When it comes to system configurations, you will need to manage the following files:

  • .env: Keeps the fundamental setups for the system, such as SVR_HTTP_PORT, MYSQL_PASSWORD, and MINIO_PASSWORD.

  • service_conf.yaml: Configures the back-end services.

  • docker-compose.yml: The system relies on docker-compose.yml to start up.

You must ensure that changes to the .env file are in line with what are in the service_conf.yaml file.

The ./docker/README file provides a detailed description of the environment settings and service configurations, and you are REQUIRED to ensure that all environment settings listed in the ./docker/README file are aligned with the corresponding configurations in the service_conf.yaml file.

To update the default HTTP serving port (80), go to docker-compose.yml and change 80:80 to <YOUR_SERVING_PORT>:80.

Updates to the above configurations require a reboot of all containers to take effect:

$ docker compose -f docker/docker-compose.yml up -d

🔧 Build a Docker image without embedding models

This image is approximately 1 GB in size and relies on external LLM and embedding services.

git clone https://github.com/infiniflow/ragflow.git  
cd ragflow/  
pip3 install huggingface-hub nltk  
python3 download\_deps.py  

docker build -f Dockerfile.slim -t infiniflow/ragflow:dev-slim .


🔧 Build a Docker image including embedding models

This image is approximately 9 GB in size. As it includes embedding models, it relies on external LLM services only.

git clone https://github.com/infiniflow/ragflow.git  
cd ragflow/  
pip3 install huggingface-hub nltk  
python3 download\_deps.py  

docker build -f Dockerfile -t infiniflow/ragflow:dev .


🔨 Launch service from source for development

  1. Install Poetry, or skip this step if it is already installed:

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Clone the source code and install Python dependencies:

  3. git clone https://github.com/infiniflow/ragflow.git  
    cd ragflow/  
    export POETRY\_VIRTUALENVS\_CREATE=true POETRY\_VIRTUALENVS\_IN\_PROJECT=true  
    ~/.local/bin/poetry install --sync --no-root # install RAGFlow dependent python modules
    
  4. Launch the dependent services (MinIO, Elasticsearch, Redis, and MySQL) using Docker Compose:

    docker compose -f docker/docker-compose-base.yml up -d
    

    Add the following line to /etc/hosts to resolve all hosts specified in docker/service_conf.yaml to 127.0.0.1:

    127.0.0.1       es01 mysql minio redis  
    
    

    In docker/service_conf.yaml, update mysql port to 5455 and es port to 1200, as specified in docker/.env.

  5. If you cannot access HuggingFace, set the HF_ENDPOINT environment variable to use a mirror site:

    export HF\_ENDPOINT=https://hf-mirror.com
    
  6. Launch backend service:

    source .venv/bin/activate  
    export PYTHONPATH=$(pwd)  
    bash docker/launch\_backend\_service.sh
    
  7. Install frontend dependencies:

    cd web  
    npm install --force
    
  8. Configure frontend to update proxy.target in .umirc.ts to http://127.0.0.1:9380:

  9. Launch frontend service:

    npm run dev_The following output confirms a successful launch of the system:_
    

📚 Documentation


  • Quickstart

  • User guide

  • References

  • FAQ

📜 Roadmap

See the RAGFlow Roadmap 2024

🏄 Community

  • Discord

  • Twitter

  • GitHub Discussions

🙌 Contributing

RAGFlow flourishes via open-source collaboration. In this spirit, we embrace diverse contributions from the community. If you would like to be a part, review our Contribution Guidelines first.

读者福利:如果大家对大模型感兴趣,这套大模型学习资料一定对你有用

对于0基础小白入门:

如果你是零基础小白,想快速入门大模型是可以考虑的。

一方面是学习时间相对较短,学习内容更全面更集中。
二方面是可以根据这些资料规划好学习计划和方向。

包括:大模型学习线路汇总、学习阶段,大模型实战案例,大模型学习视频,人工智能、机器学习、大模型书籍PDF。带你从零基础系统性的学好大模型!

😝有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓
在这里插入图片描述

👉AI大模型学习路线汇总👈

大模型学习路线图,整体分为7个大的阶段:(全套教程文末领取哈)

第一阶段: 从大模型系统设计入手,讲解大模型的主要方法;

第二阶段: 在通过大模型提示词工程从Prompts角度入手更好发挥模型的作用;

第三阶段: 大模型平台应用开发借助阿里云PAI平台构建电商领域虚拟试衣系统;

第四阶段: 大模型知识库应用开发以LangChain框架为例,构建物流行业咨询智能问答系统;

第五阶段: 大模型微调开发借助以大健康、新零售、新媒体领域构建适合当前领域大模型;

第六阶段: 以SD多模态大模型为主,搭建了文生图小程序案例;

第七阶段: 以大模型平台应用与开发为主,通过星火大模型,文心大模型等成熟大模型构建大模型行业应用。

👉大模型实战案例👈

光学理论是没用的,要学会跟着一起做,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

在这里插入图片描述

👉大模型视频和PDF合集👈

观看零基础学习书籍和视频,看书籍和视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
在这里插入图片描述
在这里插入图片描述

👉学会后的收获:👈

• 基于大模型全栈工程实现(前端、后端、产品经理、设计、数据分析等),通过这门课可获得不同能力;

• 能够利用大模型解决相关实际项目需求: 大数据时代,越来越多的企业和机构需要处理海量数据,利用大模型技术可以更好地处理这些数据,提高数据分析和决策的准确性。因此,掌握大模型应用开发技能,可以让程序员更好地应对实际项目需求;

• 基于大模型和企业数据AI应用开发,实现大模型理论、掌握GPU算力、硬件、LangChain开发框架和项目实战技能, 学会Fine-tuning垂直训练大模型(数据准备、数据蒸馏、大模型部署)一站式掌握;

• 能够完成时下热门大模型垂直领域模型训练能力,提高程序员的编码能力: 大模型应用开发需要掌握机器学习算法、深度学习框架等技术,这些技术的掌握可以提高程序员的编码能力和分析能力,让程序员更加熟练地编写高质量的代码。

👉获取方式:

😝有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓
在这里插入图片描述

;