On the shoulders of a giant: Building a domain-specific chatbot using GPT-3

Lars Baunwall
4 min readFeb 6, 2023

--

Photo by Jonathan Kemper on Unsplash

As a practitioner new to the field, I set out to discover how popular Natural Language Processing (NLP) frameworks like Haystack and Langchain make it easy to create my own ChatGPT clone. One that can answer questions from your own domain.

How hard can it actually be? And do you need to be an AI whiz kid to pull it of?

TLDR; It’s not hard, and yes: You can definitely pull it off! (I did!)

In this blog post, I’ll show you how I quickly built a chatbot from zero to hero built on the basic principles of NLP and retrieval-augmented generation (RAG).

Remember Clippy? Meet Bricky!

By now, we have all gotten to know ChatGPT from OpenAI. It’s a revolutionary technology and the first of a new generation of disruption. So how do I use it in my own product?

Is there any better way to learn than to apply your learning to a real breathing codebase? I set out to add a pinch of intelligence to our engineering handbook, a collection of guiding articles, how-to’s, and standards and principles. I wanted to transform the experience from simply browsing information into a conversation, similar to how you talk to a colleague.

Meet Bricky, a very simple built conversation bot with custom domain knowledge:

What is this magic, you say?

Bricky is built on two concepts:

Natural Language Processing (NLP), which is concerned with processing and understanding sentences. NLP takes the form of rules, training data, or models that learn from data to understand language.

Retrieval-Augmented Generation (RAG), which takes existing text data and embeds it into a language generator to enable conversation-like interactions.

By combining these two fields, we can create chatbots.

Natural Language Processing

NLP is a field of AI that deals with computers understanding human language. NLP relies heavily on its ability to process natural language data using various techniques such as machine learning algorithms and semantic analysis. With large language models (LLM) like GPT-3 (what ChatGPT is based on), machines can now process more complex sentences with greater accuracy than ever. This means that you can create more intelligent experiences that can better understand user queries and provide more accurate answers tailored to their specific needs. It’s not really magic per say, but let’s call it magical statistics.

Retrieval-Augmented Generation (RAG)

RAG is a term used to describe an approach to natural language processing where a system uses both retrieval-based methods and generative methods like LLMs for answering questions. RAG combines both approaches to output answers based on knowledge from the questioner’s request and a large database of existing information, such as documents or FAQs. This improves accuracy by providing more contextually relevant answers than traditional generative systems alone can produce.

Get started easily

Now to the silent revolution: You don’t have to deeply understand these concepts to get started.

NLP frameworks like haystack and AI ecosystems like HuggingFace are quickly democratizing and commoditizing the field of advanced AI. Allowing you to integrate models into your own pipeline — and even hosting them in the cloud.

To get familiar with these concepts in action, I created Bricky. Bricky is built on a retrieval-augmented generation architecture that allows a sophisticated LLM as GPT-3 to generate natural-sounding answers from a closed domain — our engineering handbook in this case.

The flow looks like this:

The app first searches our engineering handbook for semantically relevant content when a user asks a question. This is accomplished using embeddings — a vectorized representation of the semantical meaning of the query and the information in the source.

Bricky will then query GPT-3 and generate a response using its natural language understanding capabilities with the top results from the search as context.

This improves accuracy by providing more contextually relevant answers than GPT-3’s open-domain approach. It almost feels like Bricky understand the context — which is somewhat true. It also enables us to focus our writing on documenting specific concepts instead of writing general answers for frequently asked questions.

Grab the source on GitHub, and go build your own!

It’s for you too!

By leveraging large language models like GPT, you can create incredibly powerful AI applications without having deep technical expertise or expensive resources at your disposal.

Popular frameworks like haystack make it easier than ever before for anyone interested in creating their own intelligent systems — no matter their level of experience — by providing access to powerful tools that are easy to use yet highly effective when implemented correctly!

My chatbot Bricky is one example of how these technologies can be applied successfully in real-life scenarios — all it takes is some creativity and dedication!

Hopefully, this blog post has provided you with some useful insights into how you can start building your very own intelligent app today! You don’t have to be an expert anymore — stand on the should of a giant instead. Good luck!

P.S. Naturally, this blog article was written with a pinch of help from a clever AI too ;)

--

--

Lars Baunwall

Software Architect and entrepreneur with a pinch of dreamer. Principal Software Engineer @ the LEGO Group. My viewpoints are my own.