# Continuous Learning (RAG)

## Overview

When using an Extraction Model regularly, it can happen that the extraction is not satisfying on a given document or a particular template.

If you have already followed the [Data Schema Best Practices](/extraction-models/data-schema-best-practices.md), and results are still not satisfactory, all hope is not lost.

You have a way to durably improve the performance of the model for the next predictions you'll make. The solution you need is the RAG feature.

{% embed url="<http://app.supademo.com/demo/cmfb3c7166gdc39ozj39wogrz>" %}

## Basics of RAG Inner Workings

RAG stands for Retrieval-Augmented Generation, a novel approach in artificial intelligence that combines the strengths of retrieval-based models with generative LLM text production.

Essentially, RAG leverages a rich database of source documents and embeddings to augment the knowledge base from which it draws responses. This means that the system retrieves specific and context-based data snippets and then uses them to generate semantic and fine-tuned responses that are both creative and factually accurate.

### Overall Steps of RAG

1. Annotating a given sample, which means giving the model the difference between the extracted data and the expected value(s). When activated, this example will be added to the RAG Database for the future.
2. Retrieval: When a next document will be send with the RAG option activated, the model will try to search for a similar example in the existing database. The question here is : "Maybe there is an existing example where I need to follow the instructions so that I'm not doing a same mistake again". If no example found, no need to augment the prediction. If an examples is matched in the RAG Database, here comes step 3.
3. Augmented Generation: A document was matched in the RAG Database. The model will use the instructions you gave on the RAG sample to make a better prediction this time. The prediction generated is augmented with an existing context helping the model to be better this time.

<figure><img src="/files/9YLUqele5RJX9NRC7RbA" alt="RAG process overview" width="563"><figcaption></figcaption></figure>

## Activate RAG

{% hint style="warning" icon="money-check-dollar-pen" %}
This feature is not available on all plans, check the [Plans](/account-management/plans.md#feature-comparison) section for more information.
{% endhint %}

For best results, be sure to follow the [Data Schema Best Practices](/extraction-models/data-schema-best-practices.md) before activating this feature.

If the Data Schema is not optimized, this feature may not significantly improve model accuracy.

### Set Up the RAG Database

To use RAG on a given Extraction Model, you'll need to first set up the RAG database which will contain your documents and data.

Access the database by clicking on the "Continuous Learning (RAG)" link in the model's configuration section.\
\
You can then enrich your RAG database by uploading documents with an unsatisfying behavior.

You need to annotate the document, ticking the fields you want to be covered by the RAG augmentation on this template. You can also add additional guidelines using plain language.

{% hint style="success" %}
Most of the time, the annotation is sufficient to make the model understand the issue.\
We recommend using the guideline only when the annotation doesn't solve the problem.
{% endhint %}

Once this document is annotated, **be sure to validate it**, and go to the Live test tab.\
\
You should upload a document, and leave "Show RAG extraction" ticked.

Ideally, pick a document with the same template (another invoice from the same supplier for instance), but not exactly the one you used in the RAG database. You will see the before/after predictions and should be able to check that the extra instructions were taken into account to augment properly the prediction.\
\
In the future, the documents respecting the same template should be augmented, which should increase a lot the performances on this given template. For other types of documents, the behavior remain the same, which means that RAG is improving the result with no regression on other documents.

### Activate RAG on the Platform

When setting the activation state of a feature on the Platform, this will be the default.\
All API calls will use the default state unless explicitly set otherwise during the API call.

This is useful for project managers, as it allows activating or deactivating a feature across all API calls on that model.

Anyone with write access to the model can set the option's default value.

Click on "Data Schema" then "Optional Features" tab. There you can activate the "RAG Processing" feature.

### Activate RAG via API Calls

If you need finer-grained control over when the feature is used, you can activate or deactivate it when making API calls.

This allows dynamically setting the activation state using your internal business or domain logic.

Check the [Client Configuration](/integrations/client-libraries-sdk/configure-the-client.md#optional-features-configuration) section if using our [Client Libraries / SDKs](/integrations/client-libraries-sdk.md).

## Frequently Asked Questions

### Is my RAG data shared with other users or sold to 3rd parties?

No, never.

RAG data is only accessible to the users of the organization that the model belongs to.

Mindee never sells data to 3rd parties.

All storage and retrieval of RAG data is done on Mindee's dedicated servers.

### Does Mindee use my RAG data for training?

No, never.

We only use RAG data internally for debugging or testing, and with your explicit knowledge and consent.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mindee.com/extraction-models/optional-features/improving-accuracy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
