ragforge-ml 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 (55) hide show
  1. ragforge_ml-0.1.0/.github/workflows/ci.yml +57 -0
  2. ragforge_ml-0.1.0/.github/workflows/docs.yml +46 -0
  3. ragforge_ml-0.1.0/.gitignore +57 -0
  4. ragforge_ml-0.1.0/.pre-commit-config.yaml +16 -0
  5. ragforge_ml-0.1.0/CHANGELOG.md +26 -0
  6. ragforge_ml-0.1.0/LICENSE +21 -0
  7. ragforge_ml-0.1.0/PKG-INFO +229 -0
  8. ragforge_ml-0.1.0/README.md +163 -0
  9. ragforge_ml-0.1.0/benchmarks/results/.gitkeep +0 -0
  10. ragforge_ml-0.1.0/data/sample/company-policy.md +28 -0
  11. ragforge_ml-0.1.0/data/sample/qa.jsonl +5 -0
  12. ragforge_ml-0.1.0/docs/CONTRIBUTING.md +33 -0
  13. ragforge_ml-0.1.0/docs/evaluation.md +87 -0
  14. ragforge_ml-0.1.0/docs/index.md +55 -0
  15. ragforge_ml-0.1.0/docs/ingestion.md +53 -0
  16. ragforge_ml-0.1.0/docs/llm.md +60 -0
  17. ragforge_ml-0.1.0/docs/retrieval.md +82 -0
  18. ragforge_ml-0.1.0/examples/ask_pdf.py +48 -0
  19. ragforge_ml-0.1.0/examples/eval_benchmark.py +83 -0
  20. ragforge_ml-0.1.0/mkdocs.yml +47 -0
  21. ragforge_ml-0.1.0/pyproject.toml +102 -0
  22. ragforge_ml-0.1.0/src/ragforge/__init__.py +12 -0
  23. ragforge_ml-0.1.0/src/ragforge/cli.py +205 -0
  24. ragforge_ml-0.1.0/src/ragforge/embed/__init__.py +5 -0
  25. ragforge_ml-0.1.0/src/ragforge/embed/encoder.py +62 -0
  26. ragforge_ml-0.1.0/src/ragforge/eval/__init__.py +17 -0
  27. ragforge_ml-0.1.0/src/ragforge/eval/metrics.py +178 -0
  28. ragforge_ml-0.1.0/src/ragforge/eval/report.py +57 -0
  29. ragforge_ml-0.1.0/src/ragforge/ingest/__init__.py +41 -0
  30. ragforge_ml-0.1.0/src/ragforge/ingest/chunking.py +102 -0
  31. ragforge_ml-0.1.0/src/ragforge/ingest/markdown.py +55 -0
  32. ragforge_ml-0.1.0/src/ragforge/ingest/pdf.py +24 -0
  33. ragforge_ml-0.1.0/src/ragforge/llm/__init__.py +7 -0
  34. ragforge_ml-0.1.0/src/ragforge/llm/base.py +16 -0
  35. ragforge_ml-0.1.0/src/ragforge/llm/hf.py +84 -0
  36. ragforge_ml-0.1.0/src/ragforge/llm/quantized.py +45 -0
  37. ragforge_ml-0.1.0/src/ragforge/pipeline.py +209 -0
  38. ragforge_ml-0.1.0/src/ragforge/rerank/__init__.py +5 -0
  39. ragforge_ml-0.1.0/src/ragforge/rerank/bge.py +57 -0
  40. ragforge_ml-0.1.0/src/ragforge/serve/__init__.py +5 -0
  41. ragforge_ml-0.1.0/src/ragforge/serve/app.py +79 -0
  42. ragforge_ml-0.1.0/src/ragforge/utils.py +32 -0
  43. ragforge_ml-0.1.0/src/ragforge/vectorstore/__init__.py +7 -0
  44. ragforge_ml-0.1.0/src/ragforge/vectorstore/base.py +34 -0
  45. ragforge_ml-0.1.0/src/ragforge/vectorstore/memory.py +65 -0
  46. ragforge_ml-0.1.0/src/ragforge/vectorstore/qdrant.py +102 -0
  47. ragforge_ml-0.1.0/tests/__init__.py +0 -0
  48. ragforge_ml-0.1.0/tests/conftest.py +63 -0
  49. ragforge_ml-0.1.0/tests/test_chunking.py +33 -0
  50. ragforge_ml-0.1.0/tests/test_cli.py +16 -0
  51. ragforge_ml-0.1.0/tests/test_eval.py +53 -0
  52. ragforge_ml-0.1.0/tests/test_ingest.py +27 -0
  53. ragforge_ml-0.1.0/tests/test_pipeline.py +59 -0
  54. ragforge_ml-0.1.0/tests/test_serve.py +46 -0
  55. ragforge_ml-0.1.0/tests/test_vectorstore.py +35 -0
@@ -0,0 +1,57 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.11"
17
+ cache: pip
18
+ - run: |
19
+ python -m pip install --upgrade pip
20
+ pip install ruff
21
+ - run: ruff check src tests
22
+ - run: ruff format --check src tests
23
+
24
+ test:
25
+ runs-on: ubuntu-latest
26
+ strategy:
27
+ fail-fast: false
28
+ matrix:
29
+ python-version: ["3.10", "3.11", "3.12"]
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: ${{ matrix.python-version }}
35
+ cache: pip
36
+ - name: Install
37
+ run: |
38
+ python -m pip install --upgrade pip
39
+ pip install -e ".[dev,serve,eval]"
40
+ - name: Run tests
41
+ run: pytest -m "not slow and not gpu and not network" --cov=ragforge --cov-report=xml
42
+
43
+ build:
44
+ runs-on: ubuntu-latest
45
+ needs: [lint, test]
46
+ steps:
47
+ - uses: actions/checkout@v4
48
+ - uses: actions/setup-python@v5
49
+ with:
50
+ python-version: "3.11"
51
+ - run: |
52
+ python -m pip install --upgrade pip build
53
+ python -m build
54
+ - uses: actions/upload-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
@@ -0,0 +1,46 @@
1
+ name: docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - docs/**
8
+ - mkdocs.yml
9
+ - .github/workflows/docs.yml
10
+ workflow_dispatch:
11
+
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ concurrency:
18
+ group: pages
19
+ cancel-in-progress: false
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: "3.11"
29
+ cache: pip
30
+ - run: |
31
+ python -m pip install --upgrade pip
32
+ pip install mkdocs-material pymdown-extensions
33
+ - run: mkdocs build --strict
34
+ - uses: actions/upload-pages-artifact@v3
35
+ with:
36
+ path: site
37
+
38
+ deploy:
39
+ needs: build
40
+ runs-on: ubuntu-latest
41
+ environment:
42
+ name: github-pages
43
+ url: ${{ steps.deployment.outputs.page_url }}
44
+ steps:
45
+ - id: deployment
46
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,57 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+
6
+ .Python
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ *.egg
11
+ wheels/
12
+
13
+ .venv/
14
+ venv/
15
+ env/
16
+ ENV/
17
+
18
+ .vscode/
19
+ .idea/
20
+ *.swp
21
+ .DS_Store
22
+
23
+ .pytest_cache/
24
+ .mypy_cache/
25
+ .ruff_cache/
26
+ .coverage
27
+ htmlcov/
28
+
29
+ .ipynb_checkpoints/
30
+
31
+ # Indexes and caches
32
+ qdrant_storage/
33
+ .qdrant/
34
+ .cache/
35
+ hf_cache/
36
+ models_cache/
37
+
38
+ # Eval results
39
+ benchmarks/results/*.json
40
+ benchmarks/results/*.csv
41
+ !benchmarks/results/.gitkeep
42
+
43
+ # MkDocs build output
44
+ site/
45
+
46
+ *.log
47
+ logs/
48
+
49
+ .env
50
+ .env.local
51
+
52
+ # Large model files
53
+ *.safetensors
54
+ *.bin
55
+ *.gguf
56
+ *.pt
57
+ *.pth
@@ -0,0 +1,16 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.6.9
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
8
+ - repo: https://github.com/pre-commit/pre-commit-hooks
9
+ rev: v4.6.0
10
+ hooks:
11
+ - id: trailing-whitespace
12
+ - id: end-of-file-fixer
13
+ - id: check-yaml
14
+ - id: check-toml
15
+ - id: check-added-large-files
16
+ args: [--maxkb=512]
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. Format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and adheres to
5
+ [Semantic Versioning](https://semver.org).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] — 2026-06-18 — first release
10
+
11
+ ### Added
12
+ - `Pipeline` orchestrator wiring encoder → store → reranker → LLM.
13
+ - Ingestion: PDF (pypdf), Markdown (heading-aware), txt/rst loaders.
14
+ - Recursive char chunker with configurable size + overlap.
15
+ - `SentenceTransformerEncoder` defaulting to `BAAI/bge-small-en-v1.5`.
16
+ - Vector stores: `QdrantStore` (embedded + remote), `InMemoryStore`.
17
+ - `BGEReranker` cross-encoder for top-k reranking.
18
+ - LLM backends: `HFLLM` (HuggingFace causal LM) and `QuantizedHFLLM`
19
+ (via [turboquant-ml](https://github.com/Ademo93/turboquant)).
20
+ - Pure-Python eval metrics: `context_recall`, `answer_relevance`,
21
+ `faithfulness` + an orchestrator `evaluate()`.
22
+ - FastAPI server: `/health`, `/ingest`, `/ask`.
23
+ - Typer CLI: `rf ingest / ask / eval / serve / info`.
24
+ - pytest suite with a deterministic hash encoder for offline tests.
25
+ - GitHub Actions CI (lint + tests on Python 3.10-3.12 + wheel build).
26
+ - MkDocs Material documentation site.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RAGforge Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: ragforge-ml
3
+ Version: 0.1.0
4
+ Summary: Local-first RAG pipeline — PDF/Markdown ingestion, Qdrant retrieval, bge reranking, and an answer-quality eval harness. Pairs with turboquant-ml for quantized LLM serving.
5
+ Project-URL: Homepage, https://github.com/Ademo93/ragforge
6
+ Project-URL: Repository, https://github.com/Ademo93/ragforge
7
+ Project-URL: Issues, https://github.com/Ademo93/ragforge/issues
8
+ Project-URL: Documentation, https://Ademo93.github.io/ragforge/
9
+ Author: RAGforge Contributors
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: bge,evaluation,fastapi,llm,qdrant,rag,reranker,retrieval-augmented-generation,sentence-transformers,vector-search
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Text Processing :: Indexing
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: markdown-it-py>=3.0
25
+ Requires-Dist: numpy>=1.24
26
+ Requires-Dist: pydantic>=2.7
27
+ Requires-Dist: pypdf>=4.2
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: qdrant-client>=1.9
30
+ Requires-Dist: rich>=13.7
31
+ Requires-Dist: sentence-transformers>=3.0
32
+ Requires-Dist: torch>=2.2
33
+ Requires-Dist: tqdm>=4.66
34
+ Requires-Dist: transformers>=4.40
35
+ Requires-Dist: typer>=0.12
36
+ Provides-Extra: all
37
+ Requires-Dist: accelerate>=0.30; extra == 'all'
38
+ Requires-Dist: fastapi>=0.111; extra == 'all'
39
+ Requires-Dist: matplotlib>=3.8; extra == 'all'
40
+ Requires-Dist: pandas>=2.2; extra == 'all'
41
+ Requires-Dist: python-multipart>=0.0.9; extra == 'all'
42
+ Requires-Dist: scikit-learn>=1.4; extra == 'all'
43
+ Requires-Dist: turboquant-ml>=0.1; extra == 'all'
44
+ Requires-Dist: uvicorn>=0.30; extra == 'all'
45
+ Provides-Extra: dev
46
+ Requires-Dist: httpx>=0.27; extra == 'dev'
47
+ Requires-Dist: mypy>=1.10; extra == 'dev'
48
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
49
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
50
+ Requires-Dist: pytest>=8.0; extra == 'dev'
51
+ Requires-Dist: ruff>=0.5; extra == 'dev'
52
+ Provides-Extra: eval
53
+ Requires-Dist: pandas>=2.2; extra == 'eval'
54
+ Requires-Dist: scikit-learn>=1.4; extra == 'eval'
55
+ Provides-Extra: quantized
56
+ Requires-Dist: accelerate>=0.30; extra == 'quantized'
57
+ Requires-Dist: turboquant-ml>=0.1; extra == 'quantized'
58
+ Provides-Extra: serve
59
+ Requires-Dist: fastapi>=0.111; extra == 'serve'
60
+ Requires-Dist: python-multipart>=0.0.9; extra == 'serve'
61
+ Requires-Dist: uvicorn>=0.30; extra == 'serve'
62
+ Provides-Extra: viz
63
+ Requires-Dist: matplotlib>=3.8; extra == 'viz'
64
+ Requires-Dist: pandas>=2.2; extra == 'viz'
65
+ Description-Content-Type: text/markdown
66
+
67
+ <h1 align="center">RAGforge</h1>
68
+
69
+ <p align="center">
70
+ <strong>Local-first RAG pipeline — PDF & Markdown ingestion, Qdrant retrieval, bge reranking, and an answer-quality eval harness.</strong>
71
+ <br>
72
+ Pairs with <a href="https://github.com/Ademo93/turboquant">turboquant-ml</a> for quantized LLM serving.
73
+ </p>
74
+
75
+ <p align="center">
76
+ <a href="https://pypi.org/project/ragforge-ml/"><img alt="PyPI" src="https://img.shields.io/badge/pypi-ragforge--ml-blue"></a>
77
+ <a href="#"><img alt="Python" src="https://img.shields.io/badge/python-3.10%2B-blue"></a>
78
+ <a href="#"><img alt="PyTorch" src="https://img.shields.io/badge/pytorch-2.2%2B-ee4c2c"></a>
79
+ <a href="#"><img alt="License" src="https://img.shields.io/badge/license-MIT-green"></a>
80
+ <a href="https://Ademo93.github.io/ragforge/"><img alt="Docs" src="https://img.shields.io/badge/docs-mkdocs--material-blue"></a>
81
+ </p>
82
+
83
+ ---
84
+
85
+ ## Why RAGforge?
86
+
87
+ Most "RAG starter" repos are a 30-line glue between LangChain and OpenAI that nobody can reproduce because it hides retrieval quality, reranking, latency, and cost behind a single `.invoke()` call. **RAGforge is the opposite**: a small, readable, **local-first** pipeline that you can run end-to-end on your own laptop with open-source models, and that ships with an **answer-quality eval harness** so you can actually measure what changing a knob does.
88
+
89
+ Three opinions:
90
+
91
+ 1. **Local-first.** Default everywhere is open-source: BAAI/bge-small-en-v1.5 for embeddings, BAAI/bge-reranker-base for reranking, Qdrant in **embedded mode** (no Docker required), and any HuggingFace causal LM for generation. No OpenAI key required to try the project.
92
+ 2. **Measurable.** Every change should answer the question "did the answer get better?". RAGforge ships `ragforge eval` with built-in `context_recall`, `answer_relevance`, and `faithfulness` metrics — no RAGAS dependency required, but RAGAS-compatible.
93
+ 3. **Composable, not framework-y.** Each stage (ingest, embed, retrieve, rerank, generate, evaluate) is one short module behind a small interface. Swap the encoder, swap the vector store, swap the LLM — no `Runnable.invoke()` magic to debug.
94
+
95
+ ## Features
96
+
97
+ | Stage | Default | Swappable for |
98
+ |---|---|---|
99
+ | **Ingest** | PDF (pypdf), Markdown (markdown-it-py) | Anything that yields `(text, metadata)` |
100
+ | **Chunk** | Recursive char splitter, ~512 tokens, 64 overlap | Token-aware splitter, sentence splitter |
101
+ | **Embed** | `BAAI/bge-small-en-v1.5` (sentence-transformers) | Any sentence-transformers model |
102
+ | **Vector store** | Qdrant (embedded, no server required) | Qdrant remote, in-memory NumPy backend |
103
+ | **Rerank** | `BAAI/bge-reranker-base` | Any cross-encoder |
104
+ | **LLM** | Any HF causal LM | Same model, NF4-quantized via `turboquant-ml` |
105
+ | **Eval** | `context_recall`, `answer_relevance`, `faithfulness` | RAGAS, hand-rolled |
106
+ | **Serve** | FastAPI `/ingest`, `/ask`, `/eval` | — |
107
+ | **CLI** | `ragforge ingest / ask / eval / serve` | — |
108
+
109
+ ## Installation
110
+
111
+ The PyPI distribution is named **`ragforge-ml`** (the unsuffixed `ragforge`
112
+ name was taken by an unrelated project). Python import and CLI are just
113
+ `ragforge` / `rf`:
114
+
115
+ ```bash
116
+ pip install ragforge-ml # core
117
+ pip install "ragforge-ml[serve]" # + FastAPI
118
+ pip install "ragforge-ml[quantized]" # + turboquant-ml NF4 path
119
+ pip install "ragforge-ml[all]" # everything
120
+ ```
121
+
122
+ ## 60-second tour
123
+
124
+ ```python
125
+ from ragforge import Pipeline
126
+
127
+ rag = Pipeline.from_defaults(model_id="Qwen/Qwen2.5-3B-Instruct")
128
+ rag.ingest(["docs/policy.pdf", "notes/onboarding.md"])
129
+
130
+ answer = rag.ask("What is the maximum reimbursable amount for client lunches?")
131
+ print(answer.text)
132
+ for src in answer.sources:
133
+ print(f" {src.score:.3f} {src.metadata['path']}#chunk{src.metadata['chunk']}")
134
+ ```
135
+
136
+ ### CLI
137
+
138
+ ```bash
139
+ rf ingest docs/ --collection company
140
+ rf ask "How do I rotate an API key?" --collection company --k 5
141
+ rf eval datasets/qa.jsonl --collection company --metrics context_recall,faithfulness
142
+ rf serve --collection company --host 0.0.0.0 --port 8080
143
+ ```
144
+
145
+ ### Quantized LLM via TurboQuant
146
+
147
+ ```python
148
+ from ragforge import Pipeline
149
+ from ragforge.llm import QuantizedHFLLM
150
+
151
+ llm = QuantizedHFLLM("meta-llama/Llama-3.2-3B-Instruct", method="bnb-nf4")
152
+ rag = Pipeline.from_defaults(llm=llm)
153
+ ```
154
+
155
+ ## Architecture
156
+
157
+ ```
158
+ ragforge/
159
+ ├── ingest/ # PDF + Markdown loaders, chunking
160
+ ├── embed/ # sentence-transformers wrapper
161
+ ├── vectorstore/ # Qdrant embedded + remote
162
+ ├── rerank/ # bge-reranker-base
163
+ ├── llm/ # HF causal LM + turboquant-ml integration
164
+ ├── pipeline.py # The end-to-end orchestrator
165
+ ├── eval/ # context_recall, answer_relevance, faithfulness
166
+ ├── serve/ # FastAPI app
167
+ └── cli.py # ragforge / rf
168
+ ```
169
+
170
+ Each module is short, readable, and replaceable through a small interface
171
+ (`Encoder`, `VectorStore`, `Reranker`, `LLM`). The pipeline calls them in
172
+ order — no DAG, no runnables, no callbacks.
173
+
174
+ ## Eval harness
175
+
176
+ The reason RAGforge exists. Most RAG projects ship without measuring whether
177
+ their retrieval is any good. RAGforge ships three metrics in pure Python
178
+ (no external API), all RAGAS-compatible:
179
+
180
+ | Metric | What it measures |
181
+ |---|---|
182
+ | **`context_recall`** | Of the gold-context tokens, what fraction were retrieved? |
183
+ | **`answer_relevance`** | Cosine similarity between the answer and synthetic questions back-generated from the answer (RAGAS recipe) |
184
+ | **`faithfulness`** | Fraction of answer claims that are entailed by the retrieved context (NLI-based, can fall back to embedding overlap) |
185
+
186
+ ```bash
187
+ rf eval datasets/qa.jsonl --collection company
188
+ ```
189
+
190
+ ```text
191
+ +---------------+--------+
192
+ | metric | mean |
193
+ +---------------+--------+
194
+ | context_recall| 0.84 |
195
+ | answer_rel | 0.78 |
196
+ | faithfulness | 0.91 |
197
+ +---------------+--------+
198
+ n=120 · latency_p50=620ms · latency_p95=1.4s
199
+ ```
200
+
201
+ ## Roadmap
202
+
203
+ - [x] PDF + Markdown ingestion
204
+ - [x] Recursive char chunker with overlap
205
+ - [x] BGE embeddings + BGE reranker
206
+ - [x] Qdrant embedded + remote
207
+ - [x] FastAPI serve
208
+ - [x] CLI: ingest, ask, eval, serve
209
+ - [x] Eval: context_recall, answer_relevance, faithfulness
210
+ - [x] `turboquant-ml` integration for NF4 LLM serving
211
+ - [ ] Hybrid retrieval (BM25 + dense)
212
+ - [ ] Streaming generation in `/ask`
213
+ - [ ] Notion / Confluence loaders (community PRs welcome)
214
+ - [ ] SQL agent for structured-data questions
215
+
216
+ ## Contributing
217
+
218
+ See [`docs/CONTRIBUTING.md`](docs/CONTRIBUTING.md).
219
+
220
+ ```bash
221
+ git clone https://github.com/Ademo93/ragforge
222
+ cd ragforge
223
+ pip install -e ".[dev,serve,eval]"
224
+ pytest
225
+ ```
226
+
227
+ ## License
228
+
229
+ [MIT](LICENSE).
@@ -0,0 +1,163 @@
1
+ <h1 align="center">RAGforge</h1>
2
+
3
+ <p align="center">
4
+ <strong>Local-first RAG pipeline — PDF & Markdown ingestion, Qdrant retrieval, bge reranking, and an answer-quality eval harness.</strong>
5
+ <br>
6
+ Pairs with <a href="https://github.com/Ademo93/turboquant">turboquant-ml</a> for quantized LLM serving.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://pypi.org/project/ragforge-ml/"><img alt="PyPI" src="https://img.shields.io/badge/pypi-ragforge--ml-blue"></a>
11
+ <a href="#"><img alt="Python" src="https://img.shields.io/badge/python-3.10%2B-blue"></a>
12
+ <a href="#"><img alt="PyTorch" src="https://img.shields.io/badge/pytorch-2.2%2B-ee4c2c"></a>
13
+ <a href="#"><img alt="License" src="https://img.shields.io/badge/license-MIT-green"></a>
14
+ <a href="https://Ademo93.github.io/ragforge/"><img alt="Docs" src="https://img.shields.io/badge/docs-mkdocs--material-blue"></a>
15
+ </p>
16
+
17
+ ---
18
+
19
+ ## Why RAGforge?
20
+
21
+ Most "RAG starter" repos are a 30-line glue between LangChain and OpenAI that nobody can reproduce because it hides retrieval quality, reranking, latency, and cost behind a single `.invoke()` call. **RAGforge is the opposite**: a small, readable, **local-first** pipeline that you can run end-to-end on your own laptop with open-source models, and that ships with an **answer-quality eval harness** so you can actually measure what changing a knob does.
22
+
23
+ Three opinions:
24
+
25
+ 1. **Local-first.** Default everywhere is open-source: BAAI/bge-small-en-v1.5 for embeddings, BAAI/bge-reranker-base for reranking, Qdrant in **embedded mode** (no Docker required), and any HuggingFace causal LM for generation. No OpenAI key required to try the project.
26
+ 2. **Measurable.** Every change should answer the question "did the answer get better?". RAGforge ships `ragforge eval` with built-in `context_recall`, `answer_relevance`, and `faithfulness` metrics — no RAGAS dependency required, but RAGAS-compatible.
27
+ 3. **Composable, not framework-y.** Each stage (ingest, embed, retrieve, rerank, generate, evaluate) is one short module behind a small interface. Swap the encoder, swap the vector store, swap the LLM — no `Runnable.invoke()` magic to debug.
28
+
29
+ ## Features
30
+
31
+ | Stage | Default | Swappable for |
32
+ |---|---|---|
33
+ | **Ingest** | PDF (pypdf), Markdown (markdown-it-py) | Anything that yields `(text, metadata)` |
34
+ | **Chunk** | Recursive char splitter, ~512 tokens, 64 overlap | Token-aware splitter, sentence splitter |
35
+ | **Embed** | `BAAI/bge-small-en-v1.5` (sentence-transformers) | Any sentence-transformers model |
36
+ | **Vector store** | Qdrant (embedded, no server required) | Qdrant remote, in-memory NumPy backend |
37
+ | **Rerank** | `BAAI/bge-reranker-base` | Any cross-encoder |
38
+ | **LLM** | Any HF causal LM | Same model, NF4-quantized via `turboquant-ml` |
39
+ | **Eval** | `context_recall`, `answer_relevance`, `faithfulness` | RAGAS, hand-rolled |
40
+ | **Serve** | FastAPI `/ingest`, `/ask`, `/eval` | — |
41
+ | **CLI** | `ragforge ingest / ask / eval / serve` | — |
42
+
43
+ ## Installation
44
+
45
+ The PyPI distribution is named **`ragforge-ml`** (the unsuffixed `ragforge`
46
+ name was taken by an unrelated project). Python import and CLI are just
47
+ `ragforge` / `rf`:
48
+
49
+ ```bash
50
+ pip install ragforge-ml # core
51
+ pip install "ragforge-ml[serve]" # + FastAPI
52
+ pip install "ragforge-ml[quantized]" # + turboquant-ml NF4 path
53
+ pip install "ragforge-ml[all]" # everything
54
+ ```
55
+
56
+ ## 60-second tour
57
+
58
+ ```python
59
+ from ragforge import Pipeline
60
+
61
+ rag = Pipeline.from_defaults(model_id="Qwen/Qwen2.5-3B-Instruct")
62
+ rag.ingest(["docs/policy.pdf", "notes/onboarding.md"])
63
+
64
+ answer = rag.ask("What is the maximum reimbursable amount for client lunches?")
65
+ print(answer.text)
66
+ for src in answer.sources:
67
+ print(f" {src.score:.3f} {src.metadata['path']}#chunk{src.metadata['chunk']}")
68
+ ```
69
+
70
+ ### CLI
71
+
72
+ ```bash
73
+ rf ingest docs/ --collection company
74
+ rf ask "How do I rotate an API key?" --collection company --k 5
75
+ rf eval datasets/qa.jsonl --collection company --metrics context_recall,faithfulness
76
+ rf serve --collection company --host 0.0.0.0 --port 8080
77
+ ```
78
+
79
+ ### Quantized LLM via TurboQuant
80
+
81
+ ```python
82
+ from ragforge import Pipeline
83
+ from ragforge.llm import QuantizedHFLLM
84
+
85
+ llm = QuantizedHFLLM("meta-llama/Llama-3.2-3B-Instruct", method="bnb-nf4")
86
+ rag = Pipeline.from_defaults(llm=llm)
87
+ ```
88
+
89
+ ## Architecture
90
+
91
+ ```
92
+ ragforge/
93
+ ├── ingest/ # PDF + Markdown loaders, chunking
94
+ ├── embed/ # sentence-transformers wrapper
95
+ ├── vectorstore/ # Qdrant embedded + remote
96
+ ├── rerank/ # bge-reranker-base
97
+ ├── llm/ # HF causal LM + turboquant-ml integration
98
+ ├── pipeline.py # The end-to-end orchestrator
99
+ ├── eval/ # context_recall, answer_relevance, faithfulness
100
+ ├── serve/ # FastAPI app
101
+ └── cli.py # ragforge / rf
102
+ ```
103
+
104
+ Each module is short, readable, and replaceable through a small interface
105
+ (`Encoder`, `VectorStore`, `Reranker`, `LLM`). The pipeline calls them in
106
+ order — no DAG, no runnables, no callbacks.
107
+
108
+ ## Eval harness
109
+
110
+ The reason RAGforge exists. Most RAG projects ship without measuring whether
111
+ their retrieval is any good. RAGforge ships three metrics in pure Python
112
+ (no external API), all RAGAS-compatible:
113
+
114
+ | Metric | What it measures |
115
+ |---|---|
116
+ | **`context_recall`** | Of the gold-context tokens, what fraction were retrieved? |
117
+ | **`answer_relevance`** | Cosine similarity between the answer and synthetic questions back-generated from the answer (RAGAS recipe) |
118
+ | **`faithfulness`** | Fraction of answer claims that are entailed by the retrieved context (NLI-based, can fall back to embedding overlap) |
119
+
120
+ ```bash
121
+ rf eval datasets/qa.jsonl --collection company
122
+ ```
123
+
124
+ ```text
125
+ +---------------+--------+
126
+ | metric | mean |
127
+ +---------------+--------+
128
+ | context_recall| 0.84 |
129
+ | answer_rel | 0.78 |
130
+ | faithfulness | 0.91 |
131
+ +---------------+--------+
132
+ n=120 · latency_p50=620ms · latency_p95=1.4s
133
+ ```
134
+
135
+ ## Roadmap
136
+
137
+ - [x] PDF + Markdown ingestion
138
+ - [x] Recursive char chunker with overlap
139
+ - [x] BGE embeddings + BGE reranker
140
+ - [x] Qdrant embedded + remote
141
+ - [x] FastAPI serve
142
+ - [x] CLI: ingest, ask, eval, serve
143
+ - [x] Eval: context_recall, answer_relevance, faithfulness
144
+ - [x] `turboquant-ml` integration for NF4 LLM serving
145
+ - [ ] Hybrid retrieval (BM25 + dense)
146
+ - [ ] Streaming generation in `/ask`
147
+ - [ ] Notion / Confluence loaders (community PRs welcome)
148
+ - [ ] SQL agent for structured-data questions
149
+
150
+ ## Contributing
151
+
152
+ See [`docs/CONTRIBUTING.md`](docs/CONTRIBUTING.md).
153
+
154
+ ```bash
155
+ git clone https://github.com/Ademo93/ragforge
156
+ cd ragforge
157
+ pip install -e ".[dev,serve,eval]"
158
+ pytest
159
+ ```
160
+
161
+ ## License
162
+
163
+ [MIT](LICENSE).
File without changes
@@ -0,0 +1,28 @@
1
+ # Refund policy
2
+
3
+ Refunds are processed within 14 days of the original purchase date for any
4
+ reason, no questions asked. Refunds are issued to the original payment method.
5
+
6
+ # Returns
7
+
8
+ Returns are accepted within 30 days of delivery. Items must be returned in
9
+ their original packaging with proof of purchase. Shipping costs for returns
10
+ are borne by the customer unless the item is defective.
11
+
12
+ # Shipping
13
+
14
+ Standard shipping takes 3-5 business days. Express shipping is available for
15
+ an additional 12 EUR and ships within 1 business day. Orders above 50 EUR
16
+ qualify for free standard shipping.
17
+
18
+ # Account & API keys
19
+
20
+ To rotate an API key, log in to your account, navigate to Settings > API
21
+ Keys, and click "Rotate". The old key remains valid for 24 hours to ease
22
+ transitions. API keys must be kept secret and never committed to source
23
+ control.
24
+
25
+ # Support
26
+
27
+ Reach support at support@example.com. Median response time is 4 hours during
28
+ business days (Monday-Friday, 9am-6pm CET).
@@ -0,0 +1,5 @@
1
+ {"question": "How long is the refund window?", "ground_truth": "14 days"}
2
+ {"question": "Within how many days can I return an item?", "ground_truth": "30 days"}
3
+ {"question": "When do I get free shipping?", "ground_truth": "above 50 EUR"}
4
+ {"question": "How do I rotate an API key?", "ground_truth": "go to Settings > API Keys and click Rotate"}
5
+ {"question": "What is the support response time?", "ground_truth": "4 hours median during business days"}