> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/tech/en/quickstart/rag.md).

# RAG Knowledge Base Retrieval System

RAG (Retrieval-Augmented Generation) is a generative AI architecture that combines retrieval and generation technologies

It retrieves information from an external database or knowledge base and combines the results with a large language model to generate more accurate and contextually relevant responses.

At its core, RAG combines the language capabilities of generative AI with knowledge retrieval. When answering questions, the model does not rely solely on its internal training data. It can also dynamically retrieve the latest, more specialized information from external databases and incorporate it into generated responses.

<figure><img src="https://3415477754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNBTi475lqozGpB7xObpE%2Fuploads%2Fgit-blob-0ce05108866ecded0daa5a9fb3cd8b9137ffef26%2F2%20(1).png?alt=media" alt=""><figcaption><p>RAG workflow</p></figcaption></figure>

## High-Accuracy RAG Systems

{% hint style="info" %}
Although a basic RAG knowledge base retrieval system can be quickly implemented with Vector Search, further improving response accuracy is challenging. Response accuracy is critical to the user experience because it directly affects users' trust in and satisfaction with the system's responses. If response accuracy is insufficient, users may question the system's answers and become less willing to use it.
{% endhint %}

According to information presented at OpenAI DevDay 2023, a RAG system that uses only basic Vector Search with the correct Embedding Model can achieve 45% response accuracy. Adding HyDE Retrieval, FT Embeddings, and Chunk/Embedding Experiments can increase response accuracy to 65%.

In addition to the RAG techniques presented at OpenAI DevDay, MaiAgent RAG combines various classic NLP algorithms with proprietary retrieval technologies. On internal datasets, both MaiAgent RAG and OpenAI RAG achieve 95% response accuracy.

<figure><img src="https://3415477754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNBTi475lqozGpB7xObpE%2Fuploads%2Fgit-blob-6fd9eacb0dfc5dd2c1245505296717d272468f11%2Fimage%20(19).png?alt=media" alt="" width="561"><figcaption><p>MaiAgent RAG response accuracy</p></figcaption></figure>

The MaiAgent platform provides two RAG options: MaiAgent RAG and OpenAI RAG. The following table compares them across several dimensions:

|                                     | MaiAgent RAG                                                                                   | OpenAI RAG                                                                                                             |
| ----------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Model support                       | Supports all models 👍                                                                         | Supports only OpenAI models                                                                                            |
| Environment support                 | Supports cloud and on-premises environments 👍                                                 | Supports only the cloud; data must be sent to OpenAI                                                                   |
| Response accuracy                   | Extremely high 👍                                                                              | Extremely high 👍                                                                                                      |
| Supported file formats              | Supports all common formats 👍 doc, docx, xls, xlsx, csv, ppt, pptx, pdf, txt, json, jsonl, md | <p>Does not support xlsx or csv<br>Does not support jsonl<br>Does not support legacy Office files (doc, xlsx, ppt)</p> |
| Images in documents                 | Supported (currently experimental) 👍                                                          | Not supported                                                                                                          |
| Tables in documents                 | Supported (currently experimental) 👍                                                          | Not supported                                                                                                          |
| Attachment uploads in conversations | Supported 👍                                                                                   | Supported 👍                                                                                                           |
| Data chunking transparency          | Visualized 👍                                                                                  | Black box                                                                                                              |
| Debugging difficulty                | Moderate 👍                                                                                    | Black box; cannot be debugged                                                                                          |
| Top K adjustment                    | Enterprise customization feature 👍                                                            | Not supported                                                                                                          |
| Switching Embedding Models          | Enterprise customization feature 👍                                                            | Not supported                                                                                                          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/tech/en/quickstart/rag.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
