> 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/ai-agents/knowledge-base.md).

# Knowledge Base

Last updated: 2025-11-14

## Overview

A knowledge base is like an open-book exam. It finds the information most relevant to a question and retrieves it as context for the large language model when generating an answer. Although a knowledge base can store large amounts of data, you should ensure that the uploaded data is relevant to the questions your AI assistant needs to answer. With current retrieval technology, irrelevant data may still cause unrelated information to be retrieved as answer context, preventing the assistant from answering correctly.

## Examples of Knowledge Base Content

A knowledge base is suitable for storing various types of structured or unstructured information:

* Product information
* Frequently asked questions (FAQ)
* Technical documentation
* User manuals
* Policies and regulations
* Other large datasets

## File List Sorting

### Sort by Creation Date

MaiAgent displays knowledge base files **sorted by creation date**, with the most recently uploaded files at the top of the list. This design allows you to:

* **Quickly find new files**: Newly uploaded files appear at the top immediately
* **Track the update timeline**: Understand the knowledge base's update history from the file order
* **Simplify management and maintenance**: Prioritize the most recently added data

### Sorting Logic

The system automatically sorts files by creation date in descending order, with the newest files first. This sorting method applies to all file lists retrieved through the API or user interface, ensuring a consistent user experience.

## Best Practices for Managing Knowledge Base Files

### File Naming Recommendations

Use meaningful names to make files easier to identify and manage:

* **Include the date**: For example, `Product_Specifications_2025-11.pdf`
* **Add a version label**: For example, `User_Manual_v2.3.pdf`
* **Indicate the topic category**: For example, `FAQ_Return_and_Exchange_Policy.md`

### Regular Review and Updates

Because files are sorted by creation date, review the list regularly:

1. **Check the latest files**: Confirm that recently uploaded files contain the correct content
2. **Update outdated data**: Identify older files and determine whether they need to be updated or deleted
3. **Maintain data quality**: Ensure that knowledge base content remains current and accurate

### Batch Upload Strategy

When uploading multiple files at once:

* Upload files in order of importance, with the most important files uploaded last so they appear first
* Upload related files around the same time so they appear together in the list
* Check the list order immediately after uploading to confirm that the files are arranged as expected

## Technical Details

### API Response Format

The knowledge base file API returns a list of files sorted by creation date:

```json
{
  "files": [
    {
      "id": "file_123",
      "name": "Latest_Product_Catalog.pdf",
      "created_at": "2025-11-14T10:30:00Z",
      "size": 2048576
    },
    {
      "id": "file_122",
      "name": "FAQ_Update.md",
      "created_at": "2025-11-13T15:20:00Z",
      "size": 10240
    }
  ]
}
```

### Comparison with Other Sorting Methods

| Sorting method       | Advantages                        | Disadvantages                               | Used by MaiAgent |
| -------------------- | --------------------------------- | ------------------------------------------- | ---------------- |
| By creation date     | Makes new content easy to track   | Older but important files may be overlooked | ✅ Yes            |
| By file name         | Makes specific files easy to find | Requires good naming conventions            | ❌ No             |
| By file size         | Identifies large files            | Unrelated to content importance             | ❌ No             |
| By modification date | Reflects the latest updates       | Original creation-time information is lost  | ❌ No             |

MaiAgent sorts by creation date to provide the most intuitive timeline view, allowing users to clearly understand how the knowledge base has grown.

## Related Features

* [How to Create a Knowledge Base: Basic Setup](https://docs.maiagent.ai/km/km-basic-settings)
* [Document Management: Tags and Metadata](https://docs.maiagent.ai/km/tags-and-metadata)
* [Search Testing](https://docs.maiagent.ai/km/test-search-result)


---

# 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/ai-agents/knowledge-base.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.
