# Manage data sources and documents

Add, preview, query, or delete data sources in an existing knowledge base, and view related documents and processed artifacts. This page does not create knowledge bases or modify segment content.

## Prerequisites

Prepare credentials that can access the target workspace and the target knowledge base ID. For service endpoints, authentication, and general request formats, see [Prepare to call an API](../../api-call-basics.md).

If data comes from a local file, select the upload action that matches when you are creating the knowledge base. A successful upload does not mean the data source has been added to the knowledge base.

## Call sequence

1. First [list data sources](../../../../reference/api/ai-studio/resource-center/knowledge-bases/list-data-sources.md) to confirm existing data sources in the target knowledge base.
2. To upload a local file, choose the upload action based on whether it is before knowledge-base creation, and retain file or data-source information returned by that action page.
3. Preview data sources to add before adding them. After confirming the preview, [add data](../../../../reference/api/ai-studio/resource-center/knowledge-bases/add-data-sources.md).
4. After adding, query data sources, documents, or processed artifacts to confirm observable results. To remove data, delete it with the target data-source ID.

## API operations

### Upload, preview, and add data sources

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| Upload local files before creation | [Upload local files before creating a knowledge base](../../../../reference/api/ai-studio/resource-center/knowledge-bases/upload-local-file-before-creation.md) | Prepare local files before creating a knowledge base. |
| Upload local files | [Upload local files to a knowledge base](../../../../reference/api/ai-studio/resource-center/knowledge-bases/upload-local-file.md) | Prepare local files for an existing knowledge base. |
| Preview data sources to add | [Preview data to add](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-data-sources.md) | Check input before adding data sources to an existing knowledge base. |
| Preview data sources at creation | [Preview data before creating a knowledge base](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-initial-data-sources.md) | Check input before providing data sources at knowledge-base creation. |
| Add data sources | [Add data](../../../../reference/api/ai-studio/resource-center/knowledge-bases/add-data-sources.md) | Add data sources to the target knowledge base after confirming the preview. |
| Backfill historical data-source relationships | [Backfill data records for a knowledge base](../../../../reference/api/ai-studio/resource-center/knowledge-bases/backfill-legacy-data-sources.md) | Complete historical data-source relationships. |

### Query, preview, and maintain data sources

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| Check whether a data source is added | [Check whether data has been added](../../../../reference/api/ai-studio/resource-center/knowledge-bases/check-data-sources-exist.md) | Confirm the relationship for a specified data source before or after adding it. |
| Query data sources | [List data sources](../../../../reference/api/ai-studio/resource-center/knowledge-bases/list-data-sources.md) | Obtain data sources and their IDs in the target knowledge base. |
| Query document details | [Get document details](../../../../reference/api/ai-studio/resource-center/knowledge-bases/get-document.md) | You have a document ID and need to view the document. |
| Preview a source file | [Preview a source file](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-source-file.md) | Inspect a data source's original file. |
| Preview a processed artifact | [Preview a processed artifact image](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-processed-artifact.md) | Inspect a data source's processing result. |
| Update data-source governance settings | [Update data settings](../../../../reference/api/ai-studio/resource-center/knowledge-bases/update-data-source-governance.md) | You identified a target data source and need to adjust governance settings. |
| Delete a data source | [Delete data](../../../../reference/api/ai-studio/resource-center/knowledge-bases/delete-data-source.md) | Confirm impact and conditions on the action page before deletion. |

## Confirm the result

After adding or updating, use [List data sources](../../../../reference/api/ai-studio/resource-center/knowledge-bases/list-data-sources.md) to confirm data-source relationships. To verify content, use [Get document details](../../../../reference/api/ai-studio/resource-center/knowledge-bases/get-document.md), [Preview a source file](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-source-file.md), or [Preview a processed artifact image](../../../../reference/api/ai-studio/resource-center/knowledge-bases/preview-processed-artifact.md).

## Limitations and notes

Deleting a data source affects that source in the target knowledge base. Confirm conditions and results in [Delete data](../../../../reference/api/ai-studio/resource-center/knowledge-bases/delete-data-source.md) before proceeding.

## Next steps

- [Manage knowledge bases](knowledge-bases.md)
- [Manage segments and processing tasks](segments-processing.md)
