Retrieval-augmented generation (RAG) and natural language processing

· Thomas Wood
Retrieval-augmented generation (RAG) and natural language processing

Natural language processing (NLP) is revolutionising how businesses interact with information. But large language models, or LLMs (also known as generative models or GenAI) can sometimes struggle with factual accuracy and keeping up with real-time information.

If ChatGPT was trained on data until a certain year, how can it answer questions about events that happened after the cutoff point?

Retrieval-augmented generation (RAG) allows LLMs such as ChatGPT to stay up to date in their responses.

Natural language processing

Want to learn more?

Liked what you’ve just read? Get in touch for an NLP consulting session.

What is retrieval-augmented generation (RAG)?

Remember the old mobile phones which completed a sentence by taking into account the previous words? That’s all the LLMs are doing.

An LLM is a super-powered autocomplete. It excels at understanding language patterns but can lack domain-specific knowledge. LLMs are notorious for hallucinating when they don’t know the answer.

We can mitigate the problem of hallucinations and inaccuracies by taking the user prompt, and leveraging an external knowledge base and prepending or appending some useful information which we think the LLM should know, before we pass the prompt to the LLM. For example, if the user has a query about English insolvency law, we can send the user’s original question, together with some relevant information retrieved from a database.

Modifying the prompt sent to an LLM is also called prompt engineering.

With RAG, we augment the request by retrieving relevant documents from the knowledge base and feeding them to the LLM along with the original prompt. This empowers the LLM to generate more accurate and up-to-date responses.

A demonstration of the Insolvency Bot, a use case of RAG (retrieval augmented generation) in the legal domain.

How retrieval augmented generation can saving money and time

Here’s how RAG and prompt engineering can benefit businesses:

  • Reduced Costs: Training and maintaining LLMs can be expensive. RAG allows businesses to leverage existing LLM models and enhance their capabilities with targeted knowledge bases. This eliminates the need for costly retraining on ever-growing datasets.
  • Improved Accuracy: Although RAG doesn’t eliminate LLM hallucinations and inaccuracies, it can be shown to improve the performance by grounding responses in reliable sources. An LLM can be prompted to give relevant citations. This builds trust with customers and reduces the risk of disseminating misinformation. We found that RAG gave a significant improvement in accuracy of GPT-3.5 and GPT-4 in the legal domain (Ribary, M., Krause, P., Orban, M., Vaccari, E., Wood, T.A., Prompt Engineering and Provision of Context in Domain Specific Use of GPT, Frontiers in Artificial Intelligence and Applications 379: Legal Knowledge and Information Systems, 2023. https://doi.org/10.3233/FAIA230979, see our writeup here).
  • Faster Information Retrieval: RAG allows businesses to tap into the power of external knowledge bases, making information retrieval faster and more efficient. This frees up employees’ time for more strategic tasks.

Real-world applications of retrieval augmented generation

  • Domain-specific question answering Try our Insolvency Bot, which uses RAG to retrieve legal precedents and English statute law in order to answer questions about English insolvency procedures. It is not legal advice but it’s a demo which we developed in conjunction with a team at Royal Holloway and presented at the JURIX legal tech conference in 2023.
  • Customer Service: RAG-powered chatbots can answer customer queries with higher accuracy, reducing the need for human intervention and saving on support costs. For example, Fast Data Science are using RAG for our chatbot on fastdatascience.com. Try it out!
  • Market Research: Analyze vast amounts of customer reviews and social media data using RAG to gain deeper insights into customer preferences.
  • Internal Knowledge Management: RAG can streamline access to internal documents and resources, improving employee productivity.

The Future of NLP

RAG represents a significant step forward in NLP. By combining the power of LLMs with external knowledge, businesses can unlock new levels of efficiency, accuracy, and cost-effectiveness in information retrieval. As technology evolves, RAG is poised to play a central role in the future of human-computer interaction.

Elevate Your Team with NLP Specialists

Unleash the potential of your NLP projects with the right talent. Post your job with us and attract candidates who are as passionate about natural language processing.

Hire NLP Experts

Clinical AI Interest Group at Alan Turing Institute

Clinical AI Interest Group at Alan Turing Institute

Thomas Wood presents the Clinical Trial Risk Tool before the November meeting of the Clinical AI Interest Group at Alan Turing Institute The Clinical AI Interest group is a community of health professionals from a broad range of backgrounds with an interest in Clinical AI, organised by the Alan Turing Institute.

Fast Data Science at Ireland's Expert Witness Conference on 20 May 2026
Legal aiGenerative ai

Fast Data Science at Ireland's Expert Witness Conference on 20 May 2026

Fast Data Science will appear at Ireland’s Expert Witness Conference on 20 May 2026 in Dublin On 20 May 2026, La Touche Training is running the Expert Witness Conference 2026, at the Radisson Blu Hotel, Golden Lane, Dublin 8, Ireland. This is a full-day event combining practical workshops and interactive sessions, aimed at expert witnesses and legal professionals who want to enhance their expertise. The agenda covers critical topics like recent developments in case law, guidance on report writing, and techniques for handling cross-examination.

Using Natural Language Processing (NLP) to predict the future
Ai for businessNatural language processing

Using Natural Language Processing (NLP) to predict the future

Guest post by Alex Nikic In the past few years, Generative AI technology has advanced rapidly, and businesses are increasingly adopting it for a variety of tasks. While GenAI excels at tasks such as document summarisation, question answering, and content generation, it lacks the ability to provide reliable forecasts for future events. GenAI models are not designed for forecasting, and along with the tendancy to hallucinate information, the output of these models should not be trusted when planning key business decisions. For more details, a previous article on our blog explores in-depth the trade-offs of GenAI vs Traditional Machine Learning approaches.

What we can do for you

Transform Unstructured Data into Actionable Insights

Contact us