# Knowledge Base

Last Updated: 2025-11-14

## Overview

The knowledge base can be thought of as an open book exam, finding the most relevant information from the knowledge base to the question and extracting it as context for the large language model to reference when answering. Although the knowledge base can hold large amounts of data, it is still important to note whether the uploaded data is relevant to the questions the AI assistant needs to answer. If irrelevant, based on current retrieval technology, it may still result in finding irrelevant information as answer context, thus failing to answer properly.

## Knowledge Base Content Examples

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

* Product information
* FAQ common questions
* Technical documentation
* Operation manuals
* Policy specifications
* Other large volumes of data

## File List Sorting

### Sort by Creation Date

MaiAgent's knowledge base file list is displayed using **sort by creation date**, with the most recently uploaded files shown at the top of the list. This design allows you to:

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

### Sorting Logic

The knowledge base file serializer (BaseKnowledgeBaseFileSerializer) automatically sorts by creation date (created\_at) in descending order:

```python
# Technical implementation explanation
files = KnowledgeBaseFile.objects.filter(
    knowledge_base=knowledge_base_id
).order_by('-created_at')  # Newest files first
```

This sorting method applies to all file lists retrieved through API or interface, ensuring consistent user experience.

## Knowledge Base File Management Best Practices

### File Naming Recommendations

For easier identification and management of files, it's recommended to adopt meaningful naming conventions:

* **Include date**: e.g., `Product_Specs_2025-11.pdf`
* **Version marking**: e.g., `User_Manual_v2.3.pdf`
* **Topic classification**: e.g., `FAQ_Return_Policy.md`

### Regular Review and Updates

Since files are sorted by creation date, it's recommended to regularly review the list:

1. **Check recent files**: Confirm that recently uploaded file contents are correct
2. **Update outdated data**: Find older files and evaluate whether they need updating or deletion
3. **Maintain data quality**: Ensure the timeliness and accuracy of knowledge base content

### Batch Upload Strategy

When uploading multiple files at once:

* Upload in order of importance, with the most important files uploaded last (will appear at the top)
* Related files should be uploaded at similar times to cluster them in the list
* Immediately check the list order after uploading to confirm file arrangement meets expectations

## Technical Explanation

### API Response Format

The knowledge base file API returns a file list 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                               | MaiAgent Usage |
| -------------------- | --------------------------------- | ------------------------------------------- | -------------- |
| By creation date     | Easy to track new content         | Older but important files may be overlooked | ✅ Yes          |
| By filename          | Easy to search for specific files | Requires good naming conventions            | ❌ No           |
| By file size         | Identify large files              | Unrelated to content importance             | ❌ No           |
| By modification date | Reflects latest updates           | Initial creation time information lost      | ❌ No           |

MaiAgent chooses to sort by creation date to provide the most intuitive timeline perspective, allowing users to clearly understand the knowledge base's growth process.

## Related Features

* [How to Create a Knowledge Base: Basic Setup](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/km/km-basic-settings.md)
* [Document Management: Tags and Metadata](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/km/tags-and-metadata.md)
* [Search Testing](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/km/test-search-result.md)
