> 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/get-started/how-to-use-your-knowledge-bases.md).

# How to use your Knowledge Bases

### Prerequisites

Before you begin, you need:

* A valid `tenant_id` (See how to find it below)
* Data already ingested in the Knowledge Base (if you don't have any, follow the [Ingesting Data tutorial first](/bring-your-data-into-ai/get-started/ingesting-data-into-the-knowledge-base.md))
* A tool to make HTTP requests (curl, Postman, Insomnia, etc.)
* Your `API Key` for authentication (see [Authentication](https://snack-prompt.gitbook.io/snack-prompt-docs/api-reference/authentication))

{% hint style="info" %}

#### 🔑 How to find your tenant\_id

Your **User ID** is used as the **tenant\_id** in all API requests.

1. In the platform dashboard, click on your **profile avatar** (bottom-left).
2. Click on **"Copy my ID"**.
3. Use this value whenever the documentation asks for YOUR\_TENANT\_ID.
   {% endhint %}

{% stepper %}
{% step %}

### Step 1: Make a Semantic Search

Let's start with a simple search. Run the command below, replacing `YOUR_TENANT_ID` with your tenant\_id:

```bash
curl -X POST https://api-integrations.snackprompt.com/v1/kb/search \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "query": "what are the available products?",
    "filters": {
      "tenant_id": "YOUR_TENANT_ID"
    },
    "limit": 5
  }'
```

{% endstep %}

{% step %}

### Step 2: Understand the Response

If everything is correct, you'll receive a response like this:

```json
{
  "items": [
    {
      "id": "abc123-uuid",
      "score": 0.85,
      "payload": {
        "tenant_id": "YOUR_TENANT_ID",
        "snack_elemental_id": "elemental-456",
        "snack_item_id": "item-789",
        "original_text": "Our products include: Management software, Integration API, Analytics Dashboard...",
        "tag_names": ["Products", "Catalog"]
      }
    },
    {
      "id": "def456-uuid",
      "score": 0.72,
      "payload": {
        "tenant_id": "YOUR_TENANT_ID",
        "snack_elemental_id": "elemental-456",
        "snack_item_id": "item-790",
        "original_text": "Product price list effective from...",
        "tag_names": ["Products", "Prices"]
      }
    }
  ],
  "total_found": 2
}
```

#### What Each Field Means

| Field                        | Description                                            |
| ---------------------------- | ------------------------------------------------------ |
| `items`                      | List of results found                                  |
| `id`                         | Unique identifier of the result in the vector database |
| `score`                      | Semantic similarity (0 to 1, higher is more relevant)  |
| `payload.original_text`      | The original document content                          |
| `payload.snack_elemental_id` | ID of the source elemental (document/table)            |
| `payload.tag_names`          | Tags associated with the content                       |
| `total_found`                | Total number of results found                          |

{% endstep %}

{% step %}

### Step 3: Try the Chat

Now that you've seen how search works, try chat to get more elaborate answers:

```bash
curl -X POST https://api-integrations.snackprompt.com/v1/kb/chat \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "query": "what are the available products and how much do they cost?",
    "filters": {
      "tenant_id": "YOUR_TENANT_ID"
    }
  }'
```

The response will include an AI-generated answer based on your data:

```json
{
  "answer": "Based on the available data, the products offered are: Management software ($99/month), Integration API ($199/month), and Analytics Dashboard ($149/month). All plans include technical support.",
  "sources": [
    {
      "id": "abc123-uuid",
      "score": 0.85,
      "snack_item_id": "item-789",
      "text": "Our products include..."
    }
  ]
}
```

### Possible Errors

#### Error: tenant\_id required

```json
{
  "detail": "tenant_id is required in filters"
}
```

**Solution:** Make sure to include `tenant_id` inside the `filters` object.

#### Error: No results found

```json
{
  "items": [],
  "total_found": 0
}
```

**Solution:** Check if you've already sent data to the Knowledge Base. Follow the Ingesting Data tutorial.

{% endstep %}
{% endstepper %}

### Next Steps

Now that you've made your first call, continue learning:

1. [Ingesting Data](/bring-your-data-into-ai/get-started/ingesting-data-into-the-knowledge-base.md) - Learn how to send your own data
2. [Semantic Search](/bring-your-data-into-ai/get-started/semantic-search.md) - Learn advanced search techniques
3. [Chat with your Data](/bring-your-data-into-ai/get-started/chat-with-your-data-rag.md) - Explore all chat options

***

**Estimated time:** 5 minutes ✅
