# 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 ✅


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.snackprompt.com/bring-your-data-into-ai/get-started/how-to-use-your-knowledge-bases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
