> ## Documentation Index
> Fetch the complete documentation index at: https://datagen.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 3. Build a knowledge base

> Turn the uploaded documents into a curated, versioned knowledge base for your agent

Raw uploads are not the best input for an agent: they repeat each other, mix formats and bury the facts that matter. A **knowledge base** (Context) is a curated file tree an AI builder makes from your sources. Each publish creates a version, and agents read that published snapshot instead of the raw files.

In this part you build a knowledge base from the folder you uploaded in part 2 and publish it.

## Before you start

* You completed [2. Upload files](/tutorial/02-upload-files).

<Note>
  A knowledge base is built from files: workspace files, personal files, agent outputs, an agent's own files, or an external source. Published analytic models are not a knowledge-base source. You connect the model from part 1 to the agent directly in [part 4](/tutorial/04-build-agent), and the agent uses both side by side.
</Note>

## 1. Create the knowledge base

<Steps>
  <Step title="Open Context">
    Click **Files** on the left navigation rail. In the **Files & context** panel beside the list, click **All contexts** under **Context**, then click **New context**.
  </Step>

  <Step title="Name it">
    | Field | Value |
    | - | - |
    | Name | A name agents and people will recognize. |
    | Slug | Lowercase. Agents find the knowledge base's files under this name. It cannot be changed later. |
    | Description | What the knowledge base covers. |
  </Step>

  <Step title="Pick the sources">
    Under **Raw data**, select the folder you uploaded in part 2. Selecting a folder keeps tracking it, so a later rebuild picks up files added since.
  </Step>

  <Step title="Create">
    Click **Create**. The context builder opens.
  </Step>
</Steps>

## 2. Build it with the AI builder

The builder works in its own sandbox. The selected files are copied in read-only as inputs; nothing you build is saved until you publish.

<Steps>
  <Step title="Explore the sources">
    Start with the suggested prompt **What is in the sources?** The builder summarizes the documents it found.
  </Step>

  <Step title="Describe the knowledge base">
    Tell the builder how to organize the content for the agent.

    ```text Example prompt theme={null}
    Build a knowledge base an analyst agent can rely on:
    - one file per topic, with short headings
    - a glossary of business terms and how each metric is defined
    - the policies and rules that affect how numbers are interpreted
    - an index.md that says what is in each file
    Leave out duplicates and anything outdated.
    ```
  </Step>

  <Step title="Review the result">
    Check the generated file tree and ask for changes until it reads well.&#x20;
  </Step>
</Steps>

## 3. Publish

1. Click **Publish context** in the header. The button shows how many changes you are publishing.
2. In **Publish this context**, add **Release notes (optional)**, for example `First version from the reference documents`.
3. Click **Publish**.

The knowledge base now has a live version. Open its detail page and go to the **Versions** tab: the live version carries the **Live** badge.

<Tip>
  A knowledge base is a snapshot, not a live link. When the documents change, open the builder and publish again. To roll back, click **Roll back to this version** on an earlier version; it is published again as the newest version.
</Tip>

<Accordion title="Optional: keep it up to date with an automation">
  On the knowledge base's **Automations** tab, click **New automation**. Enter a **Name**, describe the job in **What should it do?**, add a **Scheduled** trigger, and click **Save automation**. Scheduled runs only update the draft; they never publish, so you review and publish the result yourself.
</Accordion>

## What you built

* A published knowledge base built from your documents, with version history.

You attach it to an agent in the next part. Learn more in [Build a knowledge base](/context/build) and [Use a knowledge base](/context/use).

<CardGroup cols={2}>
  <Card title="Previous: Upload files" icon="arrow-left" href="/tutorial/02-upload-files">
    Upload the reference documents.
  </Card>

  <Card title="Next: Build an agent" icon="arrow-right" href="/tutorial/04-build-agent">
    Put the model and the knowledge base to work.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.