What is semantic search and its role in creating a custom ChatGPT for business

What is semantic search

Semantic search means searching for content based on the “meaning” of the question. For example, if I ask who has visited France, I also want to find all people who have written about visiting the Eiffel Tower. In this article, I will describe in more detail how this works.

Large language models (GPT-4, Llama, etc.) are trained on millions of documents to find associations between words in different contexts. To find connections between words, every text is represented as a number sequence or vector that shows how that specific text relates to “everything else”. You can think of each number as a point in space. If we represented each text as three numbers, we would have a three-dimensional space (see the figure below). However, if we represent text as a thousand numbers (approximately the vector length used in GPT models), we have a thousand-dimensional space. True, I cannot draw a thousand-dimensional image, but the principle remains the same.

At first glance, it might seem that cryptic numbers for every text are not much better than unstructured text. But artificial intelligence and machines like numbers. In unstructured form, all our texts have different lengths. After vectorization, however, all number sequences are of the same length, and we can start doing calculations.

Semantic search in the workflow of a custom ChatGPT for business

Let’s look step by step at how semantic search works:

  1. The user asks the chatbot a question;
  2. Using semantic search, documents most likely related to the question are found;
    • The user’s question is sent to a pre-trained language model that converts it into a number sequence (vector);
    • The question vector is mathematically compared with the vectors of all source documents (which are pre-saved), and the mathematically most similar documents are found.
  3. Relevant documents along with the question and answering instructions are sent to the GPT model;
  4. The answer provided by the GPT model is sent to the user.

The workflow described in the figure helps to effectively find answers among thousands of documents. The result is an AI assistant that answers questions from employees or clients and makes information accessible and easy to read.

Latest articles