Building a quick RAG prototype
A developer or a small digital team may be asked to get a chat assistant working soon, one that answers from the organisation's own documents.
GOV.UK Chat, the government's own test of one, shows how a team built such a prototype and checked it before anyone outside saw it.
The two parts
A 2020 research paper introduced retrieval-augmented generation (RAG) models, which "combine pre-trained parametric and non-parametric memory for language generation".
One part is a language model. The other is a store of text it can search. In the paper, that store was "a dense vector index of Wikipedia, accessed with a pre-trained neural retriever".
In a prototype built for an organisation, its own documents take the place of Wikipedia. The authors found their RAG models wrote "more specific, diverse and factual language" than a comparable model with no store to search.
Start with one subject, in short rounds
The GOV.UK Chat team began with a single topic. It chose business "because it's complex for a user, involving many different departments' policies and content."
The team says the project was "managed through a series of phased experiments, each lasting a couple of weeks and focusing on iterative development and evaluation".
Checking the answers
Subject experts rated the prototype's answers first. They read typical questions and answers without being told which answers came from the language model and which came from a person.
Internal testers from the content design community then tried the chat screen before any business users did. The team says this let it develop the system safely first.
The aim was a limited public pilot, "provided that accuracy thresholds could be met". Looking back, the team called its first checks "highly manual and not practical to scale". It believes the answer is a knowledge base of quality-assessed questions, so that checking can become semi-automated.
Before it leaves the prototype stage
The GOV.UK Chat team removed personal data from the GOV.UK pages its language model could reach. It also worked with cyber security experts on 'red teaming', to identify weaknesses in the system and mitigate them.
Guidelines from the NCSC on building AI systems securely cover four key areas, starting with design and development, and moving on through deployment to operation and maintenance once the system is live. NCSC stands for National Cyber Security Centre.
OWASP's Gen AI Security Project keeps a top 10 list of risks for language model applications. One entry covers vectors and embeddings, which RAG systems use to search their store. It warns that where several groups of users share one vector database, "there's a risk of context leakage between users or queries."
Useful links
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv)
- Artificial Intelligence Playbook for the UK Government (GOV.UK)
- Guidelines for secure AI system development (NCSC)
- Top 10 risks for LLMs and Gen AI apps (OWASP Gen AI Security Project)
- LLM08: Vector and Embedding Weaknesses (OWASP Gen AI Security Project)