📕 Contents
PAI-RAG is an easy-to-use opensource framework for modular RAG (Retrieval-Augmented Generation). It combines LLM (Large Language Model) to provide truthful question-answering capabilities, supports flexible configuration and custom development of each module of the RAG system. It offers a production-level RAG workflow for businesses of any scale based on Alibaba Cloud's Platform of Artificial Intelligence (PAI).
- Modular design, flexible and configurable
- Powerful RAG capability: multi-modal rag, agentic-rag and nl2sql support
- Built on community open source components, low customization threshold
- Multi-dimensional automatic evaluation system, easy to grasp the performance quality of each module
- Integrated llm-based-application tracing and evaluation visualization tools
- Interactive UI/API calls, convenient iterative tuning experience
- Alibaba Cloud fast scenario deployment/image custom deployment/open source private deployment
You can run PAI-RAG locally using either a Docker environment or directly from the source code.
-
Set up the environmental variables.
git clone git@github.com:aigc-apps/PAI-RAG.git cd PAI-RAG/docker cp .env.example .env
Edit
.env
file if you are using dashscope api or oss store. See .env.example for more details. Note you can also configure these settings from our console ui, but it's more safe to configure from environmental variables. -
Start the Docker containers with the following command
docker compose up -d
-
Open your web browser and navigate to http://localhost:8000 to verify that the service is running. The service will need to download the model weights, which may take around 20 minutes.
If you prefer to run or develop PAI-RAG locally, please refer to local development guide
- Open http://localhost:8000 in your web browser. Adjust the index and LLM settings to your preferred models
- Go to the "Upload" tab and upload the test data: ./example_data/paul_graham/paul_graham_essay.txt.
- Once the upload is complete, switch to the "Chat" tab.
-
Open http://localhost:8000 in your web browser. Adjust the index and LLM settings to your preferred models
-
Upload data via API: Go to the PAI-RAG base directory
cd PAI-RAG
Request
curl -X 'POST' http://localhost:8000/api/v1/upload_data \ -H 'Content-Type: multipart/form-data' \ -F 'files=@example_data/paul_graham/paul_graham_essay.txt'
Response
{ "task_id": "1bcea36a1db740d28194df8af40c7226" }
-
Check the status of the upload job:
Request
curl 'http://localhost:8000/api/v1/get_upload_state?task_id=1bcea36a1db740d28194df8af40c7226'
Response
{ "task_id": "1bcea36a1db740d28194df8af40c7226", "status": "completed", "detail": null }
-
Perform a RAG query:
Request
curl -X 'POST' http://localhost:8000/api/v1/query \ -H "Content-Type: application/json" \ -d '{"question":"What did the author do growing up?"}'
Response
{ "answer":"Growing up, the author worked on writing and programming outside of school. Specifically, he wrote short stories, which he now considers to be awful due to their lack of plot and focus on characters with strong feelings. In terms of programming, he first tried writing programs on an IBM 1401 in 9th grade, using an early version of Fortran. The experience was limited because the only form of input for programs was data stored on punched cards, and he didn't have much data to work with. Later, after getting a TRS-80 microcomputer around 1980, he really started programming by creating simple games, a program to predict the flight height of model rockets, and even a word processor that his father used to write at least one book.", "session_id":"ba245d630f4d44a295514345a05c24a3", "docs":[ ... ] }
You can access and integrate our RAG service according to our API specification.
You can use agent with function calling api-tools in PAI-RAG, please refer to the documentation: Agentic RAG
You can use data analysis based on database or sheet file in PAI-RAG, please refer to the documentation: Data Analysis
文件类型 | 文件格式 |
---|---|
Unstructured | .txt, .docx, .pdf, .html,.pptx,.md |
Images | .gif, .jpg,.png,.jpeg, .webp |
Structured | .csv,.xls, .xlsx,.jsonl |
Others | .epub,.mbox,.ipynb |
- .doc files need to be converted to .docx files.
- .ppt and .pptm files need to be converted to .pptx files.