perfectrag 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. perfectrag-0.1.0/.gitignore +16 -0
  2. perfectrag-0.1.0/PKG-INFO +196 -0
  3. perfectrag-0.1.0/README.md +158 -0
  4. perfectrag-0.1.0/docs/mcp.md +66 -0
  5. perfectrag-0.1.0/docs/skills.md +50 -0
  6. perfectrag-0.1.0/docs/templates.md +75 -0
  7. perfectrag-0.1.0/pyproject.toml +93 -0
  8. perfectrag-0.1.0/src/perfectrag/__init__.py +3 -0
  9. perfectrag-0.1.0/src/perfectrag/cli.py +196 -0
  10. perfectrag-0.1.0/src/perfectrag/hardware.py +203 -0
  11. perfectrag-0.1.0/src/perfectrag/mcp_registry.py +101 -0
  12. perfectrag-0.1.0/src/perfectrag/recipes.py +187 -0
  13. perfectrag-0.1.0/src/perfectrag/scaffolder.py +62 -0
  14. perfectrag-0.1.0/src/perfectrag/skills.py +55 -0
  15. perfectrag-0.1.0/src/perfectrag/templates/__init__.py +0 -0
  16. perfectrag-0.1.0/src/perfectrag/templates/_shared/__init__.py +0 -0
  17. perfectrag-0.1.0/src/perfectrag/templates/_shared/skills/__init__.py +0 -0
  18. perfectrag-0.1.0/src/perfectrag/templates/_shared/skills/code-rag/SKILL.md +17 -0
  19. perfectrag-0.1.0/src/perfectrag/templates/_shared/skills/legal-rag/SKILL.md +17 -0
  20. perfectrag-0.1.0/src/perfectrag/templates/_shared/skills/medical-rag/SKILL.md +17 -0
  21. perfectrag-0.1.0/src/perfectrag/templates/_shared/skills/research-rag/SKILL.md +17 -0
  22. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/.env.jinja +19 -0
  23. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/.gitignore.jinja +4 -0
  24. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/README.md.jinja +55 -0
  25. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/__init__.py +0 -0
  26. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/app/Dockerfile.jinja +14 -0
  27. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/app/main.py.jinja +151 -0
  28. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/app/requirements.txt.jinja +12 -0
  29. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/copier.yml +14 -0
  30. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/data/.gitkeep +0 -0
  31. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/docker-compose.yml.jinja +65 -0
  32. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/mcp.yaml.jinja +5 -0
  33. perfectrag-0.1.0/src/perfectrag/templates/custom-naive-rag/skills/.gitkeep +0 -0
  34. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/.env.jinja +15 -0
  35. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/.gitignore.jinja +2 -0
  36. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/README.md.jinja +46 -0
  37. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/__init__.py +0 -0
  38. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/copier.yml +11 -0
  39. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/docker-compose.yml.jinja +128 -0
  40. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/mcp.yaml.jinja +4 -0
  41. perfectrag-0.1.0/src/perfectrag/templates/dify-stack/skills/.gitkeep +0 -0
  42. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/.env.jinja +28 -0
  43. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/.gitignore.jinja +4 -0
  44. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/README.md.jinja +58 -0
  45. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/__init__.py +0 -0
  46. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/copier.yml +11 -0
  47. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/docker-compose.yml.jinja +54 -0
  48. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/inputs/.gitkeep +0 -0
  49. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/mcp.yaml.jinja +4 -0
  50. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/rag_storage/.gitkeep +0 -0
  51. perfectrag-0.1.0/src/perfectrag/templates/lightrag-stack/skills/.gitkeep +0 -0
  52. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/.env.jinja +32 -0
  53. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/.gitignore.jinja +2 -0
  54. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/README.md.jinja +52 -0
  55. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/__init__.py +0 -0
  56. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/copier.yml +11 -0
  57. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/docker-compose.yml.jinja +90 -0
  58. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/mcp.yaml.jinja +6 -0
  59. perfectrag-0.1.0/src/perfectrag/templates/ragflow-stack/skills/.gitkeep +0 -0
  60. perfectrag-0.1.0/src/perfectrag/wizard.py +77 -0
  61. perfectrag-0.1.0/tests/__init__.py +0 -0
  62. perfectrag-0.1.0/tests/e2e/__init__.py +0 -0
  63. perfectrag-0.1.0/tests/e2e/test_scaffold.py +146 -0
  64. perfectrag-0.1.0/tests/fixtures/agent-workflow.yml +7 -0
  65. perfectrag-0.1.0/tests/fixtures/graphrag.yml +7 -0
  66. perfectrag-0.1.0/tests/fixtures/qa-cpu.yml +7 -0
  67. perfectrag-0.1.0/tests/fixtures/qa-gpu-8gb.yml +8 -0
  68. perfectrag-0.1.0/tests/unit/__init__.py +0 -0
  69. perfectrag-0.1.0/tests/unit/test_hardware.py +83 -0
  70. perfectrag-0.1.0/tests/unit/test_mcp_registry.py +40 -0
  71. perfectrag-0.1.0/tests/unit/test_recipes.py +126 -0
  72. perfectrag-0.1.0/tests/unit/test_skills.py +28 -0
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .venv/
8
+ venv/
9
+ dist/
10
+ build/
11
+ .coverage
12
+ htmlcov/
13
+ .idea/
14
+ .vscode/
15
+ *.swp
16
+ .DS_Store
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: perfectrag
3
+ Version: 0.1.0
4
+ Summary: Dynamic RAG framework scaffolder — wizard-driven, hardware-aware, docker-ready
5
+ Project-URL: Homepage, https://github.com/your-org/perfectrag
6
+ Project-URL: Issues, https://github.com/your-org/perfectrag/issues
7
+ Author: perfectRAG
8
+ License: Apache-2.0
9
+ Keywords: docker,graphrag,mcp,ollama,rag,scaffolder,wizard
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Code Generators
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: copier>=9.3
21
+ Requires-Dist: distro>=1.9
22
+ Requires-Dist: inquirerpy>=0.3.4
23
+ Requires-Dist: jinja2>=3.1
24
+ Requires-Dist: nvidia-ml-py>=12.535
25
+ Requires-Dist: psutil>=5.9
26
+ Requires-Dist: py-cpuinfo>=9.0
27
+ Requires-Dist: pydantic>=2.6
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: rich>=13.7
30
+ Requires-Dist: typer>=0.12
31
+ Provides-Extra: dev
32
+ Requires-Dist: mypy>=1.10; extra == 'dev'
33
+ Requires-Dist: pytest-mock>=3.12; extra == 'dev'
34
+ Requires-Dist: pytest>=8.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.5; extra == 'dev'
36
+ Requires-Dist: types-pyyaml; extra == 'dev'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # perfectRAG
40
+
41
+
42
+ > Dynamic RAG framework scaffolder — wizard hỏi vài câu, detect hardware, rồi sinh ra service RAG hoàn chỉnh (docker-compose + UI + API) chạy ngay.
43
+
44
+ Thay vì copy–paste docker-compose từ RAGFlow/Dify/LightRAG rồi loay hoay sửa `.env`, `perfectrag init` sẽ:
45
+
46
+ 1. Detect hardware (CPU/GPU/RAM/VRAM).
47
+ 2. Hỏi bạn 6 câu về use-case (Q&A / GraphRAG / agentic / multimodal / code RAG).
48
+ 3. Tự chọn tech stack phù hợp: LLM, embedding, reranker, vector DB, parser.
49
+ 4. Scaffold project hoàn chỉnh: `docker-compose.yml` + `.env` + `mcp.yaml` + `skills/` + README.
50
+ 5. `docker compose up -d` → có ngay UI + API chạy trên localhost.
51
+
52
+ Tất cả **free & open-source**, không vendor lock-in.
53
+
54
+ ## Install
55
+
56
+ ```bash
57
+ pip install perfectrag
58
+ # hoặc từ source: pip install -e ".[dev]"
59
+ ```
60
+
61
+ ## Quickstart
62
+
63
+ ```bash
64
+ perfectrag init my-rag
65
+ cd my-rag
66
+ docker compose up -d
67
+ ```
68
+
69
+ Mở UI theo stack đã chọn:
70
+ - `custom-naive-rag` → http://localhost:3000 (open-webui)
71
+ - `ragflow-stack` → http://localhost (RAGFlow)
72
+ - `lightrag-stack` → http://localhost:9621 (LightRAG WebUI)
73
+ - `dify-stack` → http://localhost (Dify)
74
+
75
+ ## Commands
76
+
77
+ | Command | Mô tả |
78
+ |---|---|
79
+ | `perfectrag init [DIR]` | Wizard → scaffold project |
80
+ | `perfectrag init DIR --template ragflow-stack` | Force template, skip recommendation |
81
+ | `perfectrag init DIR --answers-file a.yml` | Non-interactive (CI) |
82
+ | `perfectrag init DIR --dry-run` | Preview recipe, không ghi file |
83
+ | `perfectrag hw` | Detect hardware + show tier |
84
+ | `perfectrag list templates` | Liệt kê templates bundled |
85
+ | `perfectrag list mcp` | Liệt kê MCP servers trong registry |
86
+ | `perfectrag list skills` | Liệt kê skills bundled |
87
+ | `perfectrag add mcp <name> --project DIR` | Thêm MCP server vào project |
88
+ | `perfectrag add skill <name> --project DIR` | Thêm skill vào project |
89
+
90
+ ## Templates
91
+
92
+ | Template | Use-case | Key components | UI |
93
+ |---|---|---|---|
94
+ | `custom-naive-rag` | Q&A nhỏ, CPU-only, học | FastAPI + Qdrant + Ollama | open-webui |
95
+ | `ragflow-stack` | Q&A hybrid search, agentic, MCP-native | RAGFlow + Elasticsearch + MySQL + Redis + MinIO + Ollama | RAGFlow |
96
+ | `lightrag-stack` | GraphRAG / multi-hop reasoning | LightRAG + Ollama + open-webui | LightRAG WebUI |
97
+ | `dify-stack` | Workflow / agent / no-code team | Dify + Postgres + Qdrant + Redis + Ollama | Dify Console |
98
+
99
+ Chọn template khác? `perfectrag init DIR --template <name>`.
100
+
101
+ ## Hardware → tier mapping
102
+
103
+ | Tier | Khi nào | Default stack |
104
+ |---|---|---|
105
+ | `cpu` | Không có GPU | `custom-naive-rag` + Qwen2.5 3B (q4) + nomic-embed |
106
+ | `apple-low` | Apple Silicon ≤16 GB RAM | `ragflow-stack` + Qwen2.5 7B (q4) |
107
+ | `apple-high` | Apple Silicon ≥24 GB RAM | `ragflow-stack` + Qwen2.5 14B (q4) |
108
+ | `gpu-8gb` | NVIDIA 6–11 GB VRAM | `ragflow-stack` + Qwen2.5 7B (q5) + BGE-M3 |
109
+ | `gpu-12gb` | NVIDIA 12–23 GB VRAM | `ragflow-stack` + Qwen2.5 14B (q4) |
110
+ | `gpu-24gb` | NVIDIA ≥24 GB VRAM | `lightrag-stack`/`ragflow-stack` + Qwen2.5 32B (q4) + vLLM |
111
+
112
+ Routing override hard rules:
113
+ - `use_case=graphrag` **or** `multi_hop=true` → `lightrag-stack`
114
+ - `use_case=agent_workflow` → `dify-stack`
115
+ - `use_case=multimodal` → `ragflow-stack` (với Docling parser)
116
+
117
+ ## Extensibility
118
+
119
+ ### Add MCP tool
120
+
121
+ Drop vào `mcp.yaml` của project, hoặc dùng CLI:
122
+
123
+ ```bash
124
+ perfectrag add mcp tavily --project .
125
+ # set TAVILY_API_KEY trong .env
126
+ docker compose restart
127
+ ```
128
+
129
+ Xem `perfectrag list mcp` cho 10 MCP servers có sẵn (filesystem, fetch, tavily, brave-search, postgres, sqlite, github, memory, sequential-thinking, qdrant).
130
+
131
+ Thêm MCP tùy ý: edit `mcp.yaml` trực tiếp — format tương thích Claude Code / Cursor / Claude Desktop.
132
+
133
+ ### Add skill
134
+
135
+ ```bash
136
+ perfectrag add skill legal-rag --project .
137
+ ```
138
+
139
+ Bundled skills: `legal-rag`, `code-rag`, `medical-rag`, `research-rag`. Skill = `skills/<name>/SKILL.md` với YAML frontmatter — copy từ Claude Code skill format.
140
+
141
+ Tự viết skill? Tạo file `skills/<name>/SKILL.md`:
142
+
143
+ ```markdown
144
+ ---
145
+ name: my-skill
146
+ description: short one-liner
147
+ ---
148
+ # my skill
149
+ Retrieval / prompt instructions here...
150
+ ```
151
+
152
+ ### Contribute template
153
+
154
+ Template = một thư mục Copier trong `src/perfectrag/templates/<name>/`:
155
+
156
+ ```
157
+ <name>/
158
+ ├── copier.yml # _templates_suffix: .jinja
159
+ ├── docker-compose.yml.jinja # dùng {{ recipe.* }}, {{ hw.* }}, {{ answers.* }}
160
+ ├── .env.jinja
161
+ ├── README.md.jinja
162
+ ├── mcp.yaml.jinja
163
+ └── skills/.gitkeep
164
+ ```
165
+
166
+ Thêm vào `_DESCRIPTIONS` trong `src/perfectrag/scaffolder.py` — xong.
167
+
168
+ ## Architecture
169
+
170
+ ```
171
+ perfectrag CLI
172
+
173
+ ├─ hardware.py (psutil + nvml + sysctl)
174
+ ├─ wizard.py (InquirerPy conditional questions)
175
+ ├─ recipes.py (decision matrix: answers+hw → recipe)
176
+ ├─ scaffolder.py (copier wrapper)
177
+ └─ templates/
178
+ ├─ custom-naive-rag/
179
+ ├─ ragflow-stack/
180
+ ├─ lightrag-stack/
181
+ ├─ dify-stack/
182
+ └─ _shared/skills/
183
+ ```
184
+
185
+ ## Development
186
+
187
+ ```bash
188
+ pip install -e ".[dev]"
189
+ pytest # 49 tests
190
+ ruff check src tests
191
+ mypy src
192
+ ```
193
+
194
+ ## License
195
+
196
+ Apache-2.0
@@ -0,0 +1,158 @@
1
+ # perfectRAG
2
+
3
+
4
+ > Dynamic RAG framework scaffolder — wizard hỏi vài câu, detect hardware, rồi sinh ra service RAG hoàn chỉnh (docker-compose + UI + API) chạy ngay.
5
+
6
+ Thay vì copy–paste docker-compose từ RAGFlow/Dify/LightRAG rồi loay hoay sửa `.env`, `perfectrag init` sẽ:
7
+
8
+ 1. Detect hardware (CPU/GPU/RAM/VRAM).
9
+ 2. Hỏi bạn 6 câu về use-case (Q&A / GraphRAG / agentic / multimodal / code RAG).
10
+ 3. Tự chọn tech stack phù hợp: LLM, embedding, reranker, vector DB, parser.
11
+ 4. Scaffold project hoàn chỉnh: `docker-compose.yml` + `.env` + `mcp.yaml` + `skills/` + README.
12
+ 5. `docker compose up -d` → có ngay UI + API chạy trên localhost.
13
+
14
+ Tất cả **free & open-source**, không vendor lock-in.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install perfectrag
20
+ # hoặc từ source: pip install -e ".[dev]"
21
+ ```
22
+
23
+ ## Quickstart
24
+
25
+ ```bash
26
+ perfectrag init my-rag
27
+ cd my-rag
28
+ docker compose up -d
29
+ ```
30
+
31
+ Mở UI theo stack đã chọn:
32
+ - `custom-naive-rag` → http://localhost:3000 (open-webui)
33
+ - `ragflow-stack` → http://localhost (RAGFlow)
34
+ - `lightrag-stack` → http://localhost:9621 (LightRAG WebUI)
35
+ - `dify-stack` → http://localhost (Dify)
36
+
37
+ ## Commands
38
+
39
+ | Command | Mô tả |
40
+ |---|---|
41
+ | `perfectrag init [DIR]` | Wizard → scaffold project |
42
+ | `perfectrag init DIR --template ragflow-stack` | Force template, skip recommendation |
43
+ | `perfectrag init DIR --answers-file a.yml` | Non-interactive (CI) |
44
+ | `perfectrag init DIR --dry-run` | Preview recipe, không ghi file |
45
+ | `perfectrag hw` | Detect hardware + show tier |
46
+ | `perfectrag list templates` | Liệt kê templates bundled |
47
+ | `perfectrag list mcp` | Liệt kê MCP servers trong registry |
48
+ | `perfectrag list skills` | Liệt kê skills bundled |
49
+ | `perfectrag add mcp <name> --project DIR` | Thêm MCP server vào project |
50
+ | `perfectrag add skill <name> --project DIR` | Thêm skill vào project |
51
+
52
+ ## Templates
53
+
54
+ | Template | Use-case | Key components | UI |
55
+ |---|---|---|---|
56
+ | `custom-naive-rag` | Q&A nhỏ, CPU-only, học | FastAPI + Qdrant + Ollama | open-webui |
57
+ | `ragflow-stack` | Q&A hybrid search, agentic, MCP-native | RAGFlow + Elasticsearch + MySQL + Redis + MinIO + Ollama | RAGFlow |
58
+ | `lightrag-stack` | GraphRAG / multi-hop reasoning | LightRAG + Ollama + open-webui | LightRAG WebUI |
59
+ | `dify-stack` | Workflow / agent / no-code team | Dify + Postgres + Qdrant + Redis + Ollama | Dify Console |
60
+
61
+ Chọn template khác? `perfectrag init DIR --template <name>`.
62
+
63
+ ## Hardware → tier mapping
64
+
65
+ | Tier | Khi nào | Default stack |
66
+ |---|---|---|
67
+ | `cpu` | Không có GPU | `custom-naive-rag` + Qwen2.5 3B (q4) + nomic-embed |
68
+ | `apple-low` | Apple Silicon ≤16 GB RAM | `ragflow-stack` + Qwen2.5 7B (q4) |
69
+ | `apple-high` | Apple Silicon ≥24 GB RAM | `ragflow-stack` + Qwen2.5 14B (q4) |
70
+ | `gpu-8gb` | NVIDIA 6–11 GB VRAM | `ragflow-stack` + Qwen2.5 7B (q5) + BGE-M3 |
71
+ | `gpu-12gb` | NVIDIA 12–23 GB VRAM | `ragflow-stack` + Qwen2.5 14B (q4) |
72
+ | `gpu-24gb` | NVIDIA ≥24 GB VRAM | `lightrag-stack`/`ragflow-stack` + Qwen2.5 32B (q4) + vLLM |
73
+
74
+ Routing override hard rules:
75
+ - `use_case=graphrag` **or** `multi_hop=true` → `lightrag-stack`
76
+ - `use_case=agent_workflow` → `dify-stack`
77
+ - `use_case=multimodal` → `ragflow-stack` (với Docling parser)
78
+
79
+ ## Extensibility
80
+
81
+ ### Add MCP tool
82
+
83
+ Drop vào `mcp.yaml` của project, hoặc dùng CLI:
84
+
85
+ ```bash
86
+ perfectrag add mcp tavily --project .
87
+ # set TAVILY_API_KEY trong .env
88
+ docker compose restart
89
+ ```
90
+
91
+ Xem `perfectrag list mcp` cho 10 MCP servers có sẵn (filesystem, fetch, tavily, brave-search, postgres, sqlite, github, memory, sequential-thinking, qdrant).
92
+
93
+ Thêm MCP tùy ý: edit `mcp.yaml` trực tiếp — format tương thích Claude Code / Cursor / Claude Desktop.
94
+
95
+ ### Add skill
96
+
97
+ ```bash
98
+ perfectrag add skill legal-rag --project .
99
+ ```
100
+
101
+ Bundled skills: `legal-rag`, `code-rag`, `medical-rag`, `research-rag`. Skill = `skills/<name>/SKILL.md` với YAML frontmatter — copy từ Claude Code skill format.
102
+
103
+ Tự viết skill? Tạo file `skills/<name>/SKILL.md`:
104
+
105
+ ```markdown
106
+ ---
107
+ name: my-skill
108
+ description: short one-liner
109
+ ---
110
+ # my skill
111
+ Retrieval / prompt instructions here...
112
+ ```
113
+
114
+ ### Contribute template
115
+
116
+ Template = một thư mục Copier trong `src/perfectrag/templates/<name>/`:
117
+
118
+ ```
119
+ <name>/
120
+ ├── copier.yml # _templates_suffix: .jinja
121
+ ├── docker-compose.yml.jinja # dùng {{ recipe.* }}, {{ hw.* }}, {{ answers.* }}
122
+ ├── .env.jinja
123
+ ├── README.md.jinja
124
+ ├── mcp.yaml.jinja
125
+ └── skills/.gitkeep
126
+ ```
127
+
128
+ Thêm vào `_DESCRIPTIONS` trong `src/perfectrag/scaffolder.py` — xong.
129
+
130
+ ## Architecture
131
+
132
+ ```
133
+ perfectrag CLI
134
+
135
+ ├─ hardware.py (psutil + nvml + sysctl)
136
+ ├─ wizard.py (InquirerPy conditional questions)
137
+ ├─ recipes.py (decision matrix: answers+hw → recipe)
138
+ ├─ scaffolder.py (copier wrapper)
139
+ └─ templates/
140
+ ├─ custom-naive-rag/
141
+ ├─ ragflow-stack/
142
+ ├─ lightrag-stack/
143
+ ├─ dify-stack/
144
+ └─ _shared/skills/
145
+ ```
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ pip install -e ".[dev]"
151
+ pytest # 49 tests
152
+ ruff check src tests
153
+ mypy src
154
+ ```
155
+
156
+ ## License
157
+
158
+ Apache-2.0
@@ -0,0 +1,66 @@
1
+ # MCP (Model Context Protocol)
2
+
3
+ perfectRAG uses MCP as the standard way to attach external tools to your RAG service. Each generated project ships with an `mcp.yaml` listing MCP servers the backbone will load.
4
+
5
+ ## Format
6
+
7
+ ```yaml
8
+ servers:
9
+ <name>:
10
+ command: <binary or interpreter>
11
+ args: [...]
12
+ env: { VAR: "${VAR}" } # optional
13
+ ```
14
+
15
+ Tương thích với Claude Code / Cursor / Claude Desktop MCP config → portable.
16
+
17
+ ## Built-in registry (10 servers)
18
+
19
+ `perfectrag list mcp` để xem danh sách cập nhật.
20
+
21
+ | Name | Description | Env vars required |
22
+ |---|---|---|
23
+ | `filesystem` | Read/write files in whitelisted dir | — |
24
+ | `fetch` | Fetch URL → markdown | — |
25
+ | `tavily` | Tavily web search | `TAVILY_API_KEY` |
26
+ | `brave-search` | Brave web search | `BRAVE_API_KEY` |
27
+ | `postgres` | Read-only Postgres query | `POSTGRES_URL` |
28
+ | `sqlite` | SQLite query | — |
29
+ | `github` | GitHub repos/issues/PRs | `GITHUB_PERSONAL_ACCESS_TOKEN` |
30
+ | `memory` | KG memory for agent | — |
31
+ | `sequential-thinking` | Structured CoT | — |
32
+ | `qdrant` | Qdrant vector MCP | — |
33
+
34
+ ## Add MCP to project
35
+
36
+ ```bash
37
+ perfectrag add mcp tavily --project .
38
+ ```
39
+
40
+ Thêm entry vào `mcp.yaml`, prompt env vars nếu cần. Sau đó:
41
+
42
+ ```bash
43
+ # Nếu template có variable substitution cho env:
44
+ echo "TAVILY_API_KEY=your-key" >> .env.local
45
+
46
+ docker compose restart
47
+ ```
48
+
49
+ ## Custom MCP server
50
+
51
+ Viết MCP server bằng bất kỳ ngôn ngữ nào (Python via [FastMCP](https://github.com/jlowin/fastmcp), Node via `@modelcontextprotocol/sdk`, Rust, Go...). Add vào `mcp.yaml`:
52
+
53
+ ```yaml
54
+ servers:
55
+ my-tool:
56
+ command: python
57
+ args: ["./mcp_servers/my_tool.py"]
58
+ ```
59
+
60
+ MCP server expose `tools` (callable), `resources` (data), và `prompts` (templates). Backbone (RAGFlow / Dify) tự detect và surface trong UI.
61
+
62
+ ## Khi nào MCP có / không load được
63
+
64
+ - **RAGFlow** (≥v0.13) hỗ trợ MCP natively qua built-in gateway.
65
+ - **Dify** có plugin marketplace riêng — `mcp.yaml` là phần supplementary.
66
+ - **LightRAG** / **custom-naive-rag** hiện chưa auto-load — MCP ở đây là config-only, cần viết wire-up trong app code (ví dụ load MCP servers khi start FastAPI).
@@ -0,0 +1,50 @@
1
+ # Skills
2
+
3
+ Skills = domain-specific instructions (prompts, retrieval params) cho RAG service. Format mirror Claude Code's skill format.
4
+
5
+ ## Structure
6
+
7
+ ```
8
+ skills/
9
+ <skill-name>/
10
+ SKILL.md # YAML frontmatter + body
11
+ (optional) reference/ # supplementary docs
12
+ ```
13
+
14
+ `SKILL.md`:
15
+
16
+ ```markdown
17
+ ---
18
+ name: legal-rag
19
+ description: Retrieval prompts tuned for legal documents
20
+ ---
21
+ # Instructions body
22
+ ...
23
+ ```
24
+
25
+ ## Bundled skills
26
+
27
+ | Name | Description |
28
+ |---|---|
29
+ | `legal-rag` | Citations, § sections, no legal advice |
30
+ | `code-rag` | Symbol grounding, file:line refs, hybrid search |
31
+ | `medical-rag` | Disclaimers, evidence levels |
32
+ | `research-rag` | Multi-paper synthesis, citation-per-bullet |
33
+
34
+ ## Add to project
35
+
36
+ ```bash
37
+ perfectrag add skill legal-rag --project .
38
+ ```
39
+
40
+ Copies skeleton vào `skills/<name>/` trong project. Tự viết skill của bạn → tạo `skills/<tên>/SKILL.md` thủ công.
41
+
42
+ ## Mount point
43
+
44
+ Tất cả templates mount `./skills` read-only vào container (path tuỳ backbone):
45
+ - `ragflow-stack`: `/ragflow/skills`
46
+ - `lightrag-stack`: `/app/skills`
47
+ - `dify-stack`: `/app/skills`
48
+ - `custom-naive-rag`: `/app/skills`
49
+
50
+ Backbone/UI hiện chưa auto-discover skills từ disk — user dán nội dung `SKILL.md` vào system prompt khi tạo Agent/Assistant, hoặc customize template để đọc skills tự động.
@@ -0,0 +1,75 @@
1
+ # Templates
2
+
3
+ Mỗi template là một thư mục Copier chứa docker-compose + env + skeleton files. Được render với 3 context namespaces: `recipe`, `hw`, `answers`.
4
+
5
+ ## Available
6
+
7
+ ### custom-naive-rag
8
+
9
+ Minimal DIY stack cho CPU-only / learning.
10
+
11
+ - **Services**: Qdrant, Ollama, FastAPI app, open-webui, ollama-pull helper
12
+ - **UI**: open-webui tại `:3000`, FastAPI `/docs` tại `:8000`
13
+ - **Ingest**: `POST /ingest` (multipart file)
14
+ - **Query**: `POST /query` JSON hoặc OpenAI-compatible `/v1/chat/completions`
15
+ - **Khi nào chọn**: CPU-only + corpus nhỏ + qa_docs
16
+
17
+ ### ragflow-stack
18
+
19
+ Production-grade RAG với hybrid search, deep doc parsing, agentic, MCP-native.
20
+
21
+ - **Backbone**: [RAGFlow v0.17.2](https://github.com/infiniflow/ragflow)
22
+ - **Services**: Elasticsearch, MySQL, Redis, MinIO, Ollama, ragflow-server
23
+ - **UI**: RAGFlow Console tại `:80`
24
+ - **Khi nào chọn**: Q&A hybrid search, cần ingest PDF phức tạp, cần agent + tool-calling, team/production
25
+
26
+ ### lightrag-stack
27
+
28
+ GraphRAG cost-efficient với dual-level retrieval.
29
+
30
+ - **Backbone**: [LightRAG](https://github.com/HKUDS/LightRAG)
31
+ - **Services**: Ollama, lightrag server, open-webui chat
32
+ - **UI**: LightRAG WebUI tại `:9621` (graph visualize + ingest), open-webui tại `:3000`
33
+ - **Modes**: `naive`, `local`, `global`, `hybrid`
34
+ - **Khi nào chọn**: multi-hop reasoning, knowledge graph, cần entity/relation
35
+
36
+ ### dify-stack
37
+
38
+ Visual workflow + agent builder với marketplace.
39
+
40
+ - **Backbone**: [Dify v1.3.1](https://github.com/langgenius/dify)
41
+ - **Services**: Postgres, Redis, Qdrant, Ollama, api, worker, web, nginx
42
+ - **UI**: Dify Console tại `:80`
43
+ - **Khi nào chọn**: workflow/chatflow bằng UI kéo-thả, team không code
44
+
45
+ ## Contribute a template
46
+
47
+ 1. Tạo thư mục `src/perfectrag/templates/<name>/`
48
+ 2. Add `copier.yml`:
49
+ ```yaml
50
+ _templates_suffix: .jinja
51
+ _envops: { keep_trailing_newline: true }
52
+ _answers_file: .copier-answers.yml
53
+ _exclude: [copier.yml, __init__.py]
54
+ project_name: { type: str, default: my-rag }
55
+ ```
56
+ 3. Add template files với extension `.jinja`: `docker-compose.yml.jinja`, `.env.jinja`, `README.md.jinja`, `mcp.yaml.jinja`.
57
+ 4. Dùng variables: `{{ recipe.llm_model }}`, `{{ hw.gpu_vendor }}`, `{{ answers.use_case }}`.
58
+ 5. Add entry vào `_DESCRIPTIONS` trong `src/perfectrag/scaffolder.py`.
59
+ 6. (Optional) Update `_pick_template()` trong `src/perfectrag/recipes.py` để wizard tự gợi ý template mới cho use-case nào.
60
+ 7. Add test fixture + e2e test trong `tests/e2e/test_scaffold.py`.
61
+
62
+ ## Template variables reference
63
+
64
+ Recipe (`recipe.*`):
65
+ - `template`, `llm_model`, `llm_runtime`, `embedding_model`, `reranker`
66
+ - `vector_db`, `doc_parser`, `chunk_strategy`, `chunk_size`
67
+ - `gpu_enabled`, `vram_cap_gb`
68
+ - `extras.enable_graphrag`, `extras.enable_hybrid_search`
69
+
70
+ Hardware (`hw.*`):
71
+ - `os`, `arch`, `cpu_model`, `cpu_cores`, `ram_gb`, `disk_free_gb`
72
+ - `gpu_vendor` (`nvidia`/`amd`/`apple`/`none`), `gpu_name`, `vram_gb`, `cuda_version`
73
+
74
+ Answers (`answers.*`):
75
+ - `use_case`, `modality` (list), `privacy`, `multi_hop`, `corpus_size`, `user_scale`
@@ -0,0 +1,93 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "perfectrag"
7
+ version = "0.1.0"
8
+ description = "Dynamic RAG framework scaffolder — wizard-driven, hardware-aware, docker-ready"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "perfectRAG" }]
13
+ keywords = ["rag", "graphrag", "scaffolder", "wizard", "docker", "mcp", "ollama"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Topic :: Software Development :: Code Generators",
24
+ ]
25
+ dependencies = [
26
+ "typer>=0.12",
27
+ "InquirerPy>=0.3.4",
28
+ "copier>=9.3",
29
+ "jinja2>=3.1",
30
+ "psutil>=5.9",
31
+ "nvidia-ml-py>=12.535",
32
+ "py-cpuinfo>=9.0",
33
+ "pyyaml>=6.0",
34
+ "rich>=13.7",
35
+ "distro>=1.9",
36
+ "pydantic>=2.6",
37
+ ]
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "pytest>=8.0",
42
+ "pytest-mock>=3.12",
43
+ "ruff>=0.5",
44
+ "mypy>=1.10",
45
+ "types-PyYAML",
46
+ ]
47
+
48
+ [project.scripts]
49
+ perfectrag = "perfectrag.cli:app"
50
+
51
+ [project.urls]
52
+ Homepage = "https://github.com/your-org/perfectrag"
53
+ Issues = "https://github.com/your-org/perfectrag/issues"
54
+
55
+ [tool.hatch.build.targets.wheel]
56
+ packages = ["src/perfectrag"]
57
+ include = [
58
+ "src/perfectrag/**/*.py",
59
+ "src/perfectrag/templates/**/*",
60
+ ]
61
+ artifacts = [
62
+ "src/perfectrag/templates/**/*",
63
+ ]
64
+
65
+ [tool.hatch.build.targets.sdist]
66
+ include = [
67
+ "src/perfectrag",
68
+ "README.md",
69
+ "pyproject.toml",
70
+ "tests",
71
+ "docs",
72
+ ]
73
+
74
+ [tool.ruff]
75
+ line-length = 100
76
+ target-version = "py310"
77
+
78
+ [tool.ruff.lint]
79
+ select = ["E", "F", "W", "I", "UP", "B", "C4", "SIM", "RUF"]
80
+ # B008 — Typer uses callable defaults as its idiom
81
+ # SIM105 — try/except/pass is clearer than contextlib.suppress here
82
+ # SIM117 — nested with-statements are sometimes clearer
83
+ # C401 — generator vs set comprehension nit
84
+ ignore = ["E501", "B008", "SIM105", "SIM117", "C401", "RUF012"]
85
+
86
+ [tool.mypy]
87
+ python_version = "3.10"
88
+ strict = true
89
+ ignore_missing_imports = true
90
+
91
+ [tool.pytest.ini_options]
92
+ testpaths = ["tests"]
93
+ addopts = "-ra -q"
@@ -0,0 +1,3 @@
1
+ """perfectRAG — dynamic RAG framework scaffolder."""
2
+
3
+ __version__ = "0.1.0"