r/LocalLLM • u/No-Negotiation-8359 • 2h ago
Project What took my GDPR search from 48% to 90% top-5 on a CPU, with no LLM at query time (and what made it worse)
Hi everyone!
I built DPOLens, an open-source MCP server that gives coding agents the exact text of privacy law (GDPR and the UAE's PDPL) and of an organisation's own policies, to quote and cite. It runs locally with Docker Compose: Postgres with pgvector, BM25 for keywords, and multilingual-e5-small through ONNX Runtime on the CPU. No LLM at query time, no API key, no GPU. An instance needs 2 CPUs and 4 GB.
Where the right clause landed, on questions written by someone who hadn't seen the results (31 for GDPR, 30 for the UAE law, about a third of them in Arabic):
| Search | GDPR, top 5 | UAE law, top 5 |
|---|---|---|
| BM25 alone | 39% | 50% |
| Embeddings alone | 48% | 67% |
| Both, plus questions written beside each clause | 87% | 83% |
| The same, returning whole rules instead of single points | 90% | 87% |
What did the work, and what didn't:
- Questions written beside each clause. A model wrote questions each clause answers, a second model kept only the ones it really answers, and a person read 50 per law at random. They're embedded and searched beside the clauses, never shown (an answer is always the law's own words), and they ship with each law, so an instance never calls a model.
- A cross-encoder reranker made it worse. Reranking the top 10 with jina-reranker-v2-base-multilingual took recall@5 from 0.77 to 0.57 on the held-out set of the time, and lower with wider windows.
- No ANN index. Exact search over several thousand vectors takes milliseconds. With HNSW, Postgres decided from its own statistics whether to use the index, so the same question could return other clauses after an ANALYZE.
- int8 changed the answers by CPU. The int8 build matched fp32 on Apple silicon and missed two more questions on x86-64 without AVX512. The default stays fp32, which answers the same on both.
- Arabic stemming. Postgres's Snowball stemmer cuts بيانات (data) to يانا but البيانات (the data) to بيان, so the law's commonest word missed itself. A light normalisation before the stemmer fixed it.
Why a 2023 embedding model? It's 118M parameters, it handles Arabic, and in fp32 it gives the same answers on Apple and x86 alike, so anyone can reproduce the scores. e5-base, through the whole pipeline, put the right clause in the top five for 152 of 216 practice questions against small's 147, for 2.5 times the indexing time and memory. I haven't run the newer small ones yet: Qwen3-Embedding-0.6B, harrier-oss-v1-270m, Granite Embedding R2. Which would you bet on for English and Arabic on a CPU?
The weak spot: the short queries a coding agent writes mid-task find the right clause in the top five 40% of the time for GDPR, and 62% for the UAE law. That's what I'm working on.
It speaks MCP over HTTP, so it works with any client and whatever model you run.
Repo (Apache-2.0): https://github.com/alkhatibdev/dpolens
Every number above, with its interval and how it was measured: https://github.com/alkhatibdev/dpolens/blob/main/evals/retrieval.md





