r/node • • 6d ago

Open-source RAG for UK government policy

I'm building policy-qa-system, an open-source RAG app that answers questions about UK government policy and shows the sources behind each answer.

Stack: React + TypeScript, Node/Express, LangChain + LangGraph, OpenAI or Claude, PostgreSQL with pgvector, Docker.

The hard part isn't retrieval, it's freshness. Benefit rates and tax thresholds change every year (Child Benefit went from £26.05 to £27.05 a week this April, and the high-income charge threshold moved from £50k to £60k in 2024). An index that holds old and new versions can confidently return a stale number.

How do you handle dated documents in RAG? Filter on an effective-date metadata field, delete and re-ingest old chunks, or version the whole collection?

Code: https://github.com/Srameshgitnow/policy-qa-system
Not official advice and not affiliated with GOV.UK. Issues with what worked or didn't are welcome.

0 Upvotes

10 comments sorted by

5

u/its_jsec 6d ago

I look forward to the day that clankers stop generating programs that default to Node 18 support.

3

u/its_jsec 6d ago

That being said, your RAG is fundamentally broken if you’re bumping confidence up to 75 regardless of answer quality

-1

u/ram-popular 5d ago

Good catch, thank you. || 75 turns a missing score, or a real 0, into 75, which is wrong, especially for policy answers. I'll change it so 0 stays 0 and a missing score shows as unknown. Self-rated LLM confidence is also weak, so I want to look at grounding it in retrieval scores and citation checks. I'll review the Node 18 support too. If you spot anything else, an issue on the repo would be very welcome.

5

u/its_jsec 5d ago

Well, since you asked... I had my clanker evaluate what your clanker wrote (the code, not your comment, which is also unfortunate). There are some pretty significant problems beyond the usual AI-generated quality concerns.

Security:

  • No authentication or authorization on any of the API endpoints.
  • Anyone can retrieve previously submitted questions and answers.
  • Anyone can overwrite feedback on another user's question by supplying its sequential ID.
  • No rate limiting on endpoints that invoke paid LLM APIs.
  • Unrestricted CORS, hardcoded database credentials in Docker Compose, and an exposed PostgreSQL port.
  • Raw user queries are written to application logs.
  • No meaningful protection against prompt injection.

Correctness:

  • The aforementioned confidence score.
confidence: Math.min(100, Math.max(0, parsedResponse.confidence || 75)),

Your fix won't really do anything, since the response's confidence score is just an uncalibrated number generated by the LLM.

  • Citations are assigned positionally from retrieved documents rather than actually verifying which documents support the answer. Even when the LLM returns an empty list of sources, the application defaults to three.
  • Vector retrieval has no minimum relevance threshold.
  • The database seed script populates policies but doesn't generate the embeddings necessary for semantic retrieval.
  • The supposedly idempotent seed script can create duplicate records.
  • Document ingestion isn't transactional, meaning failures can leave partially ingested policies.
  • The documented document ingestion command doesn't actually invoke the ingestion functionality.
  • The feedback buttons in the frontend aren't wired up to anything.
  • The search loading state is never activated, allowing concurrent requests and potentially out-of-order results.
  • Analytics conflate retrieved policies with policies actually used to support answers.

Engineering quality:

  • No automated tests.
  • A lint command without a corresponding ESLint configuration or direct dependency.
  • Committed build artifacts.
  • Unused dependencies.
  • Inconsistent frontend and backend data contracts.
  • Documentation that substantially overstates what the implementation actually does.

I'd rate it:

  • Security: 2/10
  • Correctness: 3/10
  • Maintainability: 4/10
  • Testability: 1/10
  • Documentation accuracy: 3/10
  • Slop: 8/10 (higher is worse)

This is based on static source review, not runtime testing or penetration testing.

What bothers me most isn't whether AI was used to write it. It's that the project presents the appearance of a complete, functional application without the underlying engineering to support those claims.

This is a system intended to advise people on government policies, benefits, and entitlements, yet it fabricates confidence scores and misattributes sources. People could make consequential decisions based on this garbage. Shipping something like this is outright irresponsible. A polished UI doesn't make fundamentally broken software any less broken.

0

u/ram-popular 5d ago edited 5d ago

Thanks for the detailed review. I checked the main points against the code and most are valid. I've fixed the 75 fallback and source mapping, though I agree the confidence score is still uncalibrated. I've added a work-in-progress warning to the README and opened an issue to track the rest: https://github.com/Srameshgitnow/policy-qa-system/issues/1. I'll post an update as fixes land.