> ## Documentation Index
> Fetch the complete documentation index at: https://enterprise-docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Knowledge API

> API for managing knowledge bases, documents, and chunks

Build and maintain [knowledge bases](/en/2.5.x/use/knowledge/readme) from your own code, without going through the Dify console: create a knowledge base, load documents and chunks into it, and query it directly for search or RAG.

<Note>
  A single Knowledge Base API key has access to every knowledge base visible to the workspace owner — dataset API requests execute with owner-level access, regardless of who created the key. Handle your keys carefully to avoid unintended data exposure.
</Note>

## Get Your API Endpoint and Key

In **Knowledge**, open the **API Access** tab. From here:

* Copy the **API Server** address, the base URL for every Knowledge API request.
* Click **API Key** to create and manage keys.

<Warning>
  Store your API key securely on the server side. Never expose it in client-side code or public repositories.
</Warning>

## Create and Manage Knowledge Bases

* **[Create an Empty Knowledge Base](/en/2.5.x/develop/api/knowledge-bases/create-an-empty-knowledge-base)**: create a knowledge base with no documents yet.
* **[List Knowledge Bases](/en/2.5.x/develop/api/knowledge-bases/list-knowledge-bases)**: a paginated list, filterable by keyword or tag.
* **[Delete Knowledge Base](/en/2.5.x/develop/api/knowledge-bases/delete-knowledge-base)**: permanently remove a knowledge base and every document inside it.
* **[Retrieve Chunks from a Knowledge Base / Test Retrieval](/en/2.5.x/develop/api/knowledge-bases/retrieve-chunks-from-a-knowledge-base-test-retrieval)**: search a knowledge base and return the most relevant chunks—the same endpoint serves production retrieval and retrieval testing.

## Add and Update Documents

Document creation is asynchronous. Create the document, then poll until indexing finishes:

<Steps>
  <Step title="Create a knowledge base">
    Call [Create an Empty Knowledge Base](/en/2.5.x/develop/api/knowledge-bases/create-an-empty-knowledge-base), or use an existing knowledge base.
  </Step>

  <Step title="Add a document">
    Call [Create Document by Text](/en/2.5.x/develop/api/documents/create-document-by-text) or [Create Document by File](/en/2.5.x/develop/api/documents/create-document-by-file); both return a `batch` ID.

    If you didn't set `indexing_technique` (how content is indexed for search) when creating the knowledge base, set it on this first document; later documents inherit it automatically.
  </Step>

  <Step title="Poll the indexing status">
    Poll [Get Document Indexing Status](/en/2.5.x/develop/api/documents/get-document-indexing-status) with the `batch` ID until `indexing_status` reaches `completed` or `error`; it progresses through `waiting`, `parsing`, `cleaning`, `splitting`, and `indexing` along the way.
  </Step>
</Steps>

* **[List Documents](/en/2.5.x/develop/api/documents/list-documents)**: a paginated list, filterable by keyword.
* **[Update Document by Text](/en/2.5.x/develop/api/documents/update-document-by-text)**: update a document's text content, name, or processing configuration inline; re-triggers indexing when the content changes.
* **[Update Document by File](/en/2.5.x/develop/api/documents/update-document-by-file)**: replace a document's content by uploading a new file, re-triggering indexing.
* **[Delete Document](/en/2.5.x/develop/api/documents/delete-document)**: permanently remove a document and every chunk inside it.

## Manage Chunks

* **[Create Chunks](/en/2.5.x/develop/api/chunks/create-chunks)**: add chunks to a document by hand—indexing already chunks uploaded content automatically. Each chunk requires `content`; documents in Q\&A mode also require `answer`.
* **[List Chunks](/en/2.5.x/develop/api/chunks/list-chunks)**: a list, filterable by keyword or status.
* **[Update Chunk](/en/2.5.x/develop/api/chunks/update-chunk)**: change a chunk's content, keywords, or answer; re-triggers indexing for that chunk.
* **[Delete Chunk](/en/2.5.x/develop/api/chunks/delete-chunk)**: permanently remove a chunk.
