JA | EN

Building RAG and improving its accuracy

Generative AI already answers general knowledge at a high level.
From here on, a company's strength lies in its own know-how that is not known outside.
RAG is the mechanism that brings that know-how into generative AI's answers.

What we do

We build RAG on your company's own data and connect it to a range of IT and AI services.

Q1We want AI to answer from our internal documents. Should we choose RAG or fine-tuning?

Choose RAG. At present, fine-tuning is not cheap enough for small and medium-sized companies. Unless you stop at building RAG, the cost will not be justified by the return.

The thinking

Generative AI knows general matters well, but it does not know your company's specific information. There are two ways to let it use that information. Compared with an English exam, they look like this.

TermIn exam terms
LLMThe brain that thinks and answers
Fine-tuningReading the reference books in advance and studying them
RAGBringing the reference books into the exam, with sticky notes marking what is written where

Even if you can bring the reference books in, they are useless unless you know where the answer is written. You attach sticky notes so that the passage containing the answer can be found at once. That is RAG.

How to build it

Fine-tuning requires you to have your own LLM and train it. The cost and effort are large, and at present it does not pay for small and medium-sized companies. The aim of letting generative AI use your company's know-how can be achieved with RAG.

Q2What is the difference between attaching a PDF to ChatGPT and building our own RAG?

The difference is who prepares the searchable state; the mechanism is the same. However, if you leave it to a service, there is a limit on the volume of documents it can handle. If you build your own, that limit goes away.

The thinking

When you attach a file to a service such as ChatGPT, it answers questions about that file. This is also RAG. The service is attaching the sticky notes on your behalf.

How to build it

When a company holds its own, it prepares the mechanism that corresponds to the sticky notes itself, as a database connected to generative AI. One PDF is easy, but things change with a second PDF, then Excel files, and so on. A company's data often comes in inconsistent formats, and building a dedicated system straight away is difficult, so specialists need to be involved.

Q3What is the process for building RAG?

It is built in two phases: preparing the data and using the data.

The thinking

Being able to search quickly and being able to draw out the information an answer should be based on are two different things. When the retrieved content is passed to generative AI, does it produce the answer you want? This is the heart of RAG.

How to build it

PhaseSteps
1. Preparing the dataCollect (internal documents, PDFs, web pages and other company information that generative AI has not learned) → split into chunks of a suitable size → store in a vector database → attach an index showing what the information is about (metadata)
2. Using the dataTurn the question into a vector → search the database for likely candidates → add the search results to the prompt as additional information → generative AI answers

Chunks are stored in a vector database. The inside of generative AI is built on vectors, so searching is faster that way. However, drawing out the information an answer should be based on takes skill in how the search is done. The specific methods are explained in the next question.

Q4We built RAG, but the answers are not accurate enough. What should we fix?

Review it from seven angles. Our RAG platform incorporates our own method, PILE, for the sixth.

The thinking

What you want from the search is not a sentence that resembles the question but a sentence that answers it. And however many fragments of a document you gather, they do not add up to the whole document. In most cases, accuracy falls short because the system was built without addressing these two points.

How to build it

#AngleDetails
1Chunk sizeToo small and the right information does not fit; too large and the search becomes coarse. In our experience, a few hundred characters works well
2Structure and metadataHandle formats that differ from ordinary prose, such as tables, bullet lists and headings. Attach metadata showing which business activity the information relates to
3How to searchTurning the question straight into a vector and searching does not give the results you want. Some ingenuity is needed, such as having generative AI write a general answer first and searching with that text
4Re-selecting the search resultsTaking results in order of score includes some that do not lead to a suitable answer. Filter them and reorder them
5A dictionary of termsThe same word means different things at different companies. "Bright" means brightness at a lighting company and mood at a design company. Prepare alternative wordings to improve search accuracy
6Chunking the whole document (PILE)Individual chunks and the sentences around them cannot answer questions about the meaning of the document as a whole. We chunk the entire document hierarchically
7Repeated checking and improvementCheck in practice whether the answers are usable in the work, and keep the improvement cycle going

Points 1 and 2 belong to preparing the data, 3 to 6 to using the data, and 7 to operation.

PILE: our method for turning a whole document into chunks

PILE is a method of piling up chunks so that the whole document becomes searchable.

  1. Gather, for example, ten chunks
  2. Summarise those ten into a single summary chunk of a few hundred characters
  3. Summarise the resulting summary chunks in the same way, and repeat this many times

The summary chunks created this way keep a parent-child relationship with the original chunks, and a before-and-after relationship between parents. The details sit in the lower layers and the meaning of the whole document in the upper layers, and every layer can be searched.

Ordinary RAG only pulls in the chunks closest to the question. That is why, even with RAG in place, it cannot answer a question such as "What is the summary of this document?" With PILE, the summary chunks in the upper layers are hit by the search, so questions of this kind can be answered as well.

Q5What if documents contradict each other, and how do we check whether the AI's answer is right?

There are two ways to deal with contradictions: remove them when the documents are loaded, or instruct the generative AI in advance on how to judge when a contradiction arises.

The thinking

If nothing is done, generative AI will think for itself and answer even when the documents contradict each other. As a result, it may give an incorrect answer (hallucination). Contradictions are not something generative AI resolves on its own.

How to build it

  1. Remove them when loading: sort out contradictory statements at the stage of loading documents into RAG
  2. Give instructions on how to judge: tell the generative AI in advance how to judge when a contradiction arises

To check whether an answer is right, every answer must show its sources, that is, where the information came from. Looking at those, a person makes the final judgement.

Watch the videos (in Japanese)

Our representative, Tomoyasu Ohba, discusses these topics on the YouTube channel “システム開発のリアル:発注者向け解説” (The Reality of System Development: Explained for Clients). The videos are in Japanese.

AI that answers from internal information: what is RAG? An introduction for beginners
How RAG is built: an overview, and improving accuracy in two phases and seven points

Case studies

Supporting the work of a consulting firm

Part of the work of a consulting firm is supported by AI agents. Client issues are structured using Google Sheets as the interface. On the generative AI platform DataWisdom, complex prompt chains are processed and the consultants' accumulated know-how is incorporated as RAG to raise output quality.

Our products

DataWisdom Platform

A generative AI platform for loading your company's data and building RAG and AI agents.

  • It has a mechanism for loading your company's data easily. Once set up, it can be connected to other systems through an API
  • It includes PILE, our method of piling up chunks so that the whole document becomes searchable. It can answer questions that ordinary RAG cannot, such as "What is the summary of this document?"
  • It has a mechanism for extracting, from the question, wording suited to searching
  • It supports processing that connects multiple prompts (prompt chains)

Contact us

For questions and enquiries, please use the form below.

Contact us

Last updated: