Retrieval Augmented Generation (RAG) with Spring, ReactJS, and PGVector

Gaetano Piazzolla
9 min readMay 23, 2024

1. Introduction

In this tutorial, we’ll build a Retrieval Augmented Generation (RAG) Tool using Spring Boot, ReactJS, and PGVector.

We’ll handle AI as a “magic box” that we can use to build cool stuff, without going too much into the details of the AI algorithms.

We’ll name it Smart Document Assistant, and it will be able to answer questions in a more specific way, based on the documents we provide.

We will build a simple interface to interact with the tool, feed it with documents and questions, and see the answers it provides.

Basic Architecture diagram, made with Drawio

2. RAG and Vector Databases

Simply put, the Retrieval Augmented Generation is a way in which we can specialize Large Language Models to our needs, without spending money and resources on training a specific model for our needs.

Don’t be scared by the high-sounding naming: implementing a basic version of a RAG is trivial.

  • We instruct the Model to answer following a template with placeholders for the documents
  • We fill the template searching for relevant documents in the database

--

--