What It Actually Costs to Run a RAG Pipeline: a Mac, Cloud CPUs and an H100
A case study on a RAG ingest over 18,000 drug leaflets, measured on an M4 Mac, two cloud CPU VMs and an H100 provisioned with Terraform on Chameleon Cloud. Where each phase should run, what it costs across four providers, and where my sample lied.
I built a RAG system over the Italian drug leaflets because I wanted a fast way to read drug information from a source I could trust, instead of piecing it together from forums. The first version worked: 25,198 PDFs requested from AIFA, about 18,000 converted to Markdown, 805,000 chunks embedded on an H100 that I had reserved and configured by hand.
Then I asked the question that version couldn’t answer. If I wanted to run the whole thing again, the way I had designed it, what would it cost in money and in time? And should every step really run on the same expensive GPU box?
So I measured it. Same pipeline on an Apple M4 Mac mini, on two CPU-only cloud VMs and on an H100 VM, provisioned with Terraform on Chameleon Cloud and priced against the list prices of four commercial providers.
- Provisioning as code took the VM from about 7 minutes of clicking to 71 seconds, and one command tore everything down in 21 seconds, including the public IP I had forgotten the first time.
- The H100 embeds about 30 times faster than the M4’s CPU. In a single-VM setup it still sat idle for 54% of the run, waiting for downloads and PDF conversion.
- Full corpus, conversion plus embedding: €11.77 on the cheapest H100 provider, €33.10 on the most expensive. Same GPU, same work.
- The Mac is cheaper at every corpus size. Here the cloud doesn’t save money, it sells time, at 8 to 33 cents per hour saved.
The pipeline, and what was wrong with the first run
Five phases, each limited by something different:
| Phase | What it does | Bound by |
|---|---|---|
| s1 | loads three AIFA CSVs into SQLite | nothing, it takes seconds |
| s2 | downloads the PDFs, 6 requests at a time | the network, and not hammering AIFA |
| s3 | PDF to Markdown with PyMuPDF4LLM, OCR on scanned pages, one process per core | CPU |
| s4 | section-aware chunking, bge-m3 embeddings, ChromaDB | GPU |
| s5 | retrieves 30 chunks, reranks to 6, answers with an LLM | latency |
The build log covers how each phase works. This post is about where they should run.
The first full run, which I’ll call v0, happened in July on a Chameleon VM with one H100 and 48 vCPUs. I created the reservation and the instance in the dashboard, configured the box over SSH with a script and copied the results back with rsync. Conversion took 37 minutes on 48 processes. Embedding took about 2.5 hours, a number I read off a progress bar rather than measured.
It worked, but it left me with a single configuration and nothing to compare it to, no idea of the cost, provisioning steps that lived only in my head, and a suspicion that the H100 was doing nothing for most of the run.
Measuring without downloading 25,000 PDFs every time
Re-running the full corpus for every configuration was out of the question. On the Mac the embedding alone would take more than 80 hours, and every run would hit AIFA’s servers with another 25,000 requests.
I froze a sample instead: the first 500 drugs by code, which gave 972 valid PDFs and 31,365 chunks. It ships to every machine as one 294 MB tarball, and every run gets its own folder with a copy of the database and a read-only link to the PDFs, so runs never step on each other.
# one phase, one configuration, 16 workers
CONFIG=cloud-cpu-l WORKERS=16 bench/run.sh samples/n500 s3
run.sh writes the start, end and duration of each phase to a CSV, together with the commit, host, worker count, device and batch size. On Linux it also samples CPU and GPU usage every second with vmstat and nvidia-smi. Every measurement ran three times and I report the median, except for a few runs that took hours.
| ID | Machine |
|---|---|
local | Mac mini M4, 10 cores (4 performance, 6 efficiency), 16 GB |
cloud-cpu-s | Chameleon m1.xlarge, 8 vCPU Intel Haswell |
cloud-cpu-l | Chameleon m1.xxlarge, 16 vCPU Intel Haswell |
cloud-gpu | Chameleon g1.h100.pci.1, 1× H100 94 GB, 48 vCPU Sapphire Rapids |
Chameleon is free for research, so it gave me the hardware but not the prices. I’ll get to those.
From seven minutes of clicking to seventy seconds of Terraform
On Chameleon’s KVM site every instance needs a lease from Blazar, OpenStack’s reservation service. When the lease becomes active, Chameleon creates a flavor called reservation:<id>, and its id is the reservation id. By hand that meant lease, wait, instance, floating IP, SSH: about 7 minutes to a reachable VM and 11 before it was ready to measure.
The manual version also leaked. After the GPU run, the floating IP and a 50 GB volume outlived the lease and sat in the project until I noticed them.
The automated version is a Makefile plus one Terraform file. Terraform’s OpenStack provider covers compute, networking and volumes, but not Blazar, so the lease goes through the OpenStack CLI and Terraform only receives its id:
# trimmed: the real recipe also times itself and checks the lease exists
up:
RES=$$($(OPENSTACK) reservation lease show $(LEASE_NAME) -f json -c reservations \
| jq -r '.reservations | fromjson | .id') && \
terraform -chdir=infra apply -auto-approve -var reservation_id=$$RES
The fromjson is there because the CLI returns the reservations field as a JSON string inside the JSON. On the Terraform side the reservation id goes straight into flavor_id, and the floating IP is attached to an explicit port, so terraform destroy releases it:
resource "openstack_compute_instance_v2" "vm" {
name = var.name
image_name = "CC-Ubuntu24.04"
flavor_id = var.reservation_id # on KVM@TACC the reserved flavor id is the reservation id
key_pair = "farmaci-h100"
network { port = openstack_networking_port_v2.vm.id }
}
resource "openstack_networking_floatingip_v2" "ip" {
pool = "public"
port_id = openstack_networking_port_v2.vm.id
}
The code reaches the VM as a git bundle of the current commit piped over SSH, so the VM needs no GitHub credentials and runs exactly the commit that ends up next to the results. I skipped cloud-init. It would only have installed system packages, which the bootstrap script already does in about 20 seconds.
| Step | By hand | With make |
|---|---|---|
| lease active | 1 to 4 min | 27 s |
| VM reachable over SSH | 6.5 to 7 min | 71 s from the start |
| ready to measure (code, sample, Python env, model) | about 11 min | 5 min 17 s |
| teardown | by hand, IP and volume forgotten | 21 s, nothing left behind |
Provisioning shrank about six times. Configuration didn’t shrink at all: 246 seconds, most of it pip installing PyTorch. A prebuilt image would fix that, and it’s the first thing I’d change.
Where my assumptions broke
The Mac stops scaling at two workers
Conversion is embarrassingly parallel, since every PDF is independent, and on the cloud VMs it behaves that way. Sixteen workers on 16 vCPUs ran 13.75 times faster than one, and the three cloud machines sit almost on top of each other up to 16. On the 48-vCPU box the curve bends after that: 22.7 times faster with 32 workers, 27.2 with 48.

The Mac did something else. Two workers were 1.38 times faster than one. Four, eight and ten workers were all slower than two, and with ten it was almost back to serial speed (1,144 s against 1,215 s). Amdahl’s law can’t draw that curve, because it never predicts a slowdown from adding cores, so something shared is saturating. My candidates are the libraries’ own threads fighting the worker processes, the six efficiency cores dragging the pool down, and memory bandwidth shared with the GPU. I haven’t proved which one it is.
Per core, the M4 is the fastest machine in this test: one worker converts the sample in 1,215 s, against 2,478 s on Sapphire Rapids and 4,369 s on Haswell. It just can’t use its cores. An 8-vCPU Haswell VM, with cores 3.6 times slower, still finished in 595 s against the Mac’s best of 879 s.
These runs also gave me a reproducibility check for free. cloud-cpu-s was created by hand and cloud-cpu-l by Terraform three days later. With 1, 4 and 8 workers their times match within 0.4%.
Smaller batches were faster on the GPU
v0 embedded with a batch size of 256, on the reasoning everyone uses: a bigger batch keeps the GPU busier. On the sample the opposite happened.
| Batch size | 32 | 64 | 128 | 256 |
|---|---|---|---|---|
| s4 on the H100 (s) | 262 | 281 | 315 | 410 |
| faster than 256 | 1.56× | 1.46× | 1.30× | 1.00× |

The reason is padding. The indexer hands the model blocks of 256 texts, sentence-transformers sorts each block by length and splits it into sub-batches of the requested size, and every sub-batch is padded to its longest text. Small sub-batches hold texts of similar length, so they carry less padding. I used 64 for everything after this, as a middle ground.
The sample lied by a quarter to a third
The full run was also the check on the sample. Scaling the sample’s times linearly predicted 1,684 s for conversion and 7,234 s for embedding. The real numbers were 2,109 s and 9,833 s, 25% and 36% higher.
The cause was in the data. The first 500 drugs by code are the oldest ones, and their documents are shorter:
| Avg chunk length | Chunks ≥ 1,400 chars | Chunks per document | |
|---|---|---|---|
| the sample | 1,074 chars | 46% | 32.2 |
| the rest of the corpus | 1,304 chars | 62% | 45.6 |
A longer chunk costs more to embed. And when most chunks are long they’re also similar in length, so the small batch has little padding left to save. On the full corpus batch 64 managed 82 chunks per second, close to what batch 256 did on the sample (77) and nowhere near batch 64 on the sample (112). ChromaDB wasn’t the bottleneck: every block of 256 chunks took about 3 seconds from the start of the run to the end.
I still think the sample was the right call. It made dozens of runs affordable, and the ratios between machines held. But I chose the batch size on it, and I wouldn’t do that again without checking against the real load.
Two smaller cuts
- My conversion logs grew to 19 MB per run, and the growth wasn’t linear. I blamed tqdm at first. It was PyMuPDF printing a growing buffer of NUL bytes before every parser message, and
tr -d '\000'in the runner fixed it. - The H100 VM’s 40 GB root disk had about 9 GB free after CUDA and PyTorch, and the full run needed about 19. A 50 GB Cinder volume mounted at
/mnt/voltook two minutes. It’s also the volume I later forgot to delete.
The H100 sat idle for more than half the run
The full run, on the single H100 VM with batch 64:
| Phase | Time |
|---|---|
| download (s2) | 2 h 40 min |
| conversion (s3) | 35 min |
| embedding (s4) | 2 h 44 min |
| total | 5 h 59 min |
The usage samples tell the rest. During conversion the 48 vCPUs were 96% busy and the GPU sat at 0%. During embedding it flipped: the GPU averaged 83% and the CPUs 3%. Download and conversion together took 54% of the run, and I was renting an H100 for all of it.
The obvious fix is two VMs: a cheap CPU-only one for conversion, and the GPU only for embedding. I didn’t run this split. I composed it from the per-phase timings, with each VM paying its own provisioning overhead. On the full corpus it costs 10 to 12% less than the single VM for conversion plus embedding, and takes 46% longer, because 16 Haswell vCPUs need about two hours for what 48 Sapphire Rapids cores do in 35 minutes.
The saving that matters is the download, which spends 2 h 40 min waiting on the network. Moving it to the CPU VM as well brings the full-corpus cost on Azure from €59.05 to €31.39, 47% less, for an extra hour and a half.
What it costs
Chameleon doesn’t bill in euros, so I priced each configuration with the on-demand list prices of equivalent machines, VAT included: Azure, AWS, Lambda and RunPod for the H100, and Azure, AWS and GCP for the CPU VMs. A cloud configuration pays for its run time plus the 290 seconds of provisioning and setup I measured above. The Mac pays for electricity at its 65 W maximum plus its purchase price spread over four years of round-the-clock use, €0.052 per hour in total.
cloud = Σ over VMs (hours of work + 0.0806 h of overhead) × hourly price
local = hours × (amortization per hour + 0.065 kW × €0.4343/kWh)

Full corpus, conversion plus embedding:
| Configuration | Hours billed | Cost |
|---|---|---|
| H100, RunPod | 3.4 | €11.77 |
| H100, Lambda | 3.4 | €12.14 |
| 16 vCPU VM + H100, AWS | 4.9 | €24.37 |
| H100, AWS | 3.4 | €27.16 |
| 16 vCPU VM + H100, Azure | 4.9 | €29.17 |
| H100, Azure | 3.4 | €33.10 |
| Mac, estimated | about 90 | €4.70 |
The spread between providers for the same GPU is 2.8 times. The split saves 10 to 12% at best. Whatever cleverness I put into the architecture, choosing where to rent mattered more.
A few smaller results came out of the same table. The GPU VM was cheaper than the CPU VMs even for the whole pipeline on the sample (€0.64 to €1.79 against €2.96 to €4.21), because embedding on a CPU takes hours and the lower hourly price doesn’t make up for it. The bigger CPU VM wasn’t worth it for the whole pipeline either: twice the hourly price, but embedding only 1.72 times faster. And the fixed overhead adds 78% to the cost of a sample run on the H100, against 2.4% on the full corpus.
When does the cloud beat the Mac?
On time, almost immediately. The Mac needs 9.89 s per document for conversion plus embedding, the H100 needs 290 s of setup plus 0.38 s per document. They cross at about 30 documents.
On money, never. Even ignoring the setup, a document costs 2.6 (RunPod) to 7.2 (Azure) times more on the H100 than on the Mac. That rests on how I amortize the Mac: if it worked less than about 5.4 hours a day on average over its four years, each hour would carry more of its price and RunPod would come out cheaper.
I didn’t run the full corpus on the Mac. Scaling the sample with the corpus-to-sample ratios measured on the H100, it would need about 90 hours, three days and eighteen hours of continuous work, for €4.70. The H100 does it in 3.4 hours for €11.77 to €33.10. So the cloud buys back about 86 hours for €7 to €28 extra, between 8 and 33 cents per hour saved.
What I’d do next time
For a one-off ingest like this one, rent the GPU, and spend your optimization effort on the invoice rather than on the architecture. A 2.8× spread between providers is worth more than any split I could design.
If I had to run this corpus again tomorrow, I’d download on a cheap CPU box, embed on the cheapest H100 I can find for about three hours, and tear everything down with one command. I’m less sure about moving the conversion off the GPU box too. It saves so little that on a one-off job I’m not convinced it’s worth an extra hour and a half; on a recurring ingest it probably would be. And I’d check any batch size or throughput figure against the real corpus before trusting it.
What I haven’t measured yet is the query side. Answering a question takes about 4.5 seconds on the Mac, most of it in the reranker. A cloud GPU would be faster, but it would have to stay on all day to serve those queries, and that is a different cost model from a three-hour batch job.
The code, the Terraform, every raw timing and the cost model are on GitHub, together with the full report (in Italian) that this post is based on. If you build things like this, I write more of them under RAG and AI × Backend.
References
- aifa-rag-cloud: code, Terraform, raw timings and cost model (GitHub)
- Chameleon Cloud — NSF experimental testbed
- OpenStack Blazar — resource reservation service
- Terraform OpenStack provider
- BGE-M3: multilingual embedding model (BAAI)
- PyMuPDF4LLM — PDF to Markdown for LLMs
- Azure retail prices API
- Amazon EC2 on-demand pricing
- Lambda GPU cloud pricing
- RunPod pricing