> For the complete documentation index, see [llms.txt](https://docs.snackprompt.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snackprompt.com/bring-your-data-into-ai/tutorials/ingesting-data-into-the-knowledge-base.md).

# Ingesting Data into the Knowledge Base

In this tutorial, you'll learn how to send data to the SnackPrompt AI Engine Knowledge Base.

### What is an Elemental?

An **elemental** is the basic unit of data in SnackPrompt. It can be:

* A **table** with columns and items
* A **document** with sections
* A **file** with structured content

When you send an elemental, the API:

1. Processes the content
2. Generates embeddings (vector representations)
3. Stores in the Knowledge Base
4. Makes the data searchable

### Prerequisites

* A valid `tenant_id`  [(See how to find it)](https://docs.snackprompt.com/how-to/how-to-obtain-your-user-id-tenant-id)&#x20;
* The `elemental_id` of the data you want to ingest (obtained from the SnackPrompt platform)

### Step 1: Send an Elemental

To ingest an elemental, make a POST request:

```bash
curl -X POST https://api-integrations.snackprompt.com/v1/kb/elemental \
  -H "Content-Type: application/json" \
  -d '{
    "elemental_id": "YOUR_ELEMENTAL_ID",
    "trace_id": "my-trace-001"
  }'
```

#### Parameters

| Parameter      | Type   | Required | Description                            |
| -------------- | ------ | -------- | -------------------------------------- |
| `elemental_id` | string | Yes      | ID of the elemental to ingest          |
| `trace_id`     | string | No       | ID for tracking (useful for debugging) |

### Step 2: Understand the Response

Ingestion is processed in **background**. You'll receive an immediate confirmation:

```json
{
  "status": "accepted",
  "message": "Ingestion started for YOUR_ELEMENTAL_ID",
  "data": {
    "job_id": "my-trace-001",
    "elemental_id": "YOUR_ELEMENTAL_ID"
  }
}
```

**Status code:** `202 Accepted`

This means the request was accepted and is being processed. Ingestion may take a few seconds to minutes, depending on the data size.

### Step 3: Verify Data Was Ingested

To confirm your data is available, make a simple search:

```bash
curl -X POST https://api-integrations.snackprompt.com/v1/kb/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "test",
    "filters": {
      "tenant_id": "YOUR_TENANT_ID",
      "elemental_id": "YOUR_ELEMENTAL_ID"
    },
    "limit": 1
  }'
```

If it returns results, your data was successfully ingested!

### How to Remove Data

#### Remove by Elemental ID

To remove all data from a specific elemental:

```bash
curl -X DELETE https://api-integrations.snackprompt.com/v1/kb/elemental/YOUR_ELEMENTAL_ID
```

**Response:**

```json
{
  "status": "success",
  "message": "Ingestion deleted for elemental_id: YOUR_ELEMENTAL_ID",
  "data": {
    "elemental_id": "YOUR_ELEMENTAL_ID"
  }
}
```

#### Remove by Filters

To remove data using more specific filters:

```bash
curl -X POST https://api-integrations.snackprompt.com/v1/kb/delete \
  -H "Content-Type: application/json" \
  -d '{
    "filters": {
      "tenant_id": "YOUR_TENANT_ID",
      "elemental_id": "YOUR_ELEMENTAL_ID"
    }
  }'
```

> **Important:** The `tenant_id` is **required** for filter-based deletion operations.

### What Happens During Ingestion?

When you send an elemental, the API executes the following steps:

```
1. Receives the elemental_id
       ↓
2. Fetches complete data from SnackPrompt platform
       ↓
3. Processes the content (parsing)
       ↓
4. Splits into chunks (smaller pieces)
       ↓
5. Generates embeddings
       ↓
6. Stores in our Vector Database
       ↓
7. Data available for search!
```

### Stored Metadata

During ingestion, the following metadata is stored with each chunk:

| Field                | Description                                   |
| -------------------- | --------------------------------------------- |
| `tenant_id`          | Tenant ID (for isolation)                     |
| `user_id`            | User ID                                       |
| `snack_elemental_id` | Source elemental ID                           |
| `snack_column_id`    | Column ID (if applicable)                     |
| `snack_item_id`      | Specific item ID                              |
| `source`             | Source type (`elemental`, `document`, `file`) |
| `type_name`          | Elemental type (Table, Document, etc.)        |
| `category_name`      | Elemental category                            |
| `original_text`      | Original chunk content                        |
| `tag_ids`            | Associated tag IDs                            |
| `tag_names`          | Associated tag names                          |

### Tag Inheritance

Tags are inherited in cascade:

```
Document (document tags)
    └── Column (column tags)
            └── Item (item tags)
```

The final item will have the **merge** of all tags (no duplicates).

### Next Steps

Now that your data is in the Knowledge Base:

1. Semantic Search - Learn how to search your data
2. Chat with your Data - Chat with your data using AI
3. Filter by Tags - Use tags to filter results

***

**Estimated time:** 10 minutes ✅
