# Question & Answer

Allows to query the knowledge base using a specific AI model.

### The Knowledge Base model

| Key               | Type    | Description                                                                                                      |
| ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------- |
| id                | String  | The unique identifier for the knowledge base which is given by Tiledesk.                                         |
| name              | String  | The knowledge base name.                                                                                         |
| id\_project       | String  | The unique identifier of the project                                                                             |
| preview\_settings | Object  | The settings for the knowledge base preview                                                                      |
| default           | Boolean | Specifies if the knowledge base is the default one                                                               |
| hybrid            | Boolean | Specifies if the knowledge base is hybrid. Default is false (standard type)                                      |
| engine            | Object  | Specifies the configuration of the vector store system used by the knowledge base. A default engine is provided. |
| embedding         | Object  | Indicates which embeddings are used for vector-based search. A default embedding is present.                     |

## Ask the Knowledge Base

<mark style="color:green;">`POST`</mark> `https://api.tiledesk.com/v3/:project_id/kb/qa`

Allows to query the knowledge base using a specific AI model.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| project\_id | string | The Project Id is a unique code assigned to your project when you create it in Tiledesk. |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | Authorization token. Basic Auth or JWT |

#### Request Body

| Name            | Type    | Description                                                                                                        |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------ |
| question        | string  | The question submitted                                                                                             |
| namespace       | string  | The id of the Knowledge Base in which to search for the answer                                                     |
| llm             | string  | (Optional) The LLM to use to generate the response (Default: "openai")                                             |
| model           | string  | The model to use to generate the response (e.g. gpt-4o)                                                            |
| max\_tokens     | Number  | The maximum number of tokens that can be consumed to generate the response                                         |
| temperature     | Number  | Defines creativity in generating responses (low values ​​determine more specific and predictable responses)        |
| top\_k          | Number  | The number of nearby chunks to use to generate the response                                                        |
| engine          | Object  | (Optional) The engine configuration object to use for the vector store system if different from the Default Engine |
| embedding       | Object  | (Optional) The embedding object to use for the embedding generation if different from the Default Engine           |
| system\_context | string  | (Optional) The context to give to the AI ​​to shape its behavior in generating the response.                       |
| alpha           | Number  | (Optional) Defines the balance of hybrid search (0 = full-text focused, 1 = semantic/vector focused).              |
| chunks\_only    | Boolean | (Optional) Returns only the retrieved text chunks without generating a final answer.                               |
| stream          | Boolean | (Optional) Enables real-time streaming of the response as it is generated.                                         |
| citations       | Boolean | (Optional) Includes source references for the retrieved or generated content.                                      |
| tags            | Array   | (Optional) Filters or categorizes results based on associated tags.                                                |
| rereanking      | Boolean | (Optional) Applies a secondary ranking step to improve the relevance of retrieved results.                         |

{% tabs %}
{% tab title="200 " %}

```
{
    "answer": "To create an AI assistant using OpenAI, you can follow these steps:\n\n1. **Visit OpenAI**: Navigate to the OpenAI website.\n2. **Access the API Section**:\n   - Go to ‘Products’, then select ‘API’.\n   - Log in and select ‘API’.\n3. **Navigate to Assistant Creation**:\n   - Ensure you are on the Dashboard.\n   - Click on ‘Assistant’ from the left sidebar menu.\n4. **Create the Assistant**:\n   - Click the green ‘Create’ button in the top right corner.\n   - Name your assistant and provide context in the ‘Instructions’ section to fine-tune its responses.\n5. **Select the Model**:\n   - For this example, you can use GPT-4o.\n6. **Handle File Formats**:\n   - If uploading a CSV file, use a Code interpreter.\n   - For PDF or text files, use the File Search feature.\n7. **Integrate with Tiledesk**:\n   - Copy the assistant ID.\n   - Go to the Tiledesk dashboard, click on the block where the ChatGPT Assistant is placed.\n   - In the right-side menu, paste the assistant ID into the “Assign GPT Assistant” field.\n\nIf you need",
    "success": true,
    "namespace": "66a897133eaa7f0013632c5b",
    "id": "66b6268722af86ab6a739cb6",
    "ids": [
        "66b6268722af86ab6a739cb6"
    ],
    "source": "https://gethelp.tiledesk.com/articles/create-an-ai-assistant-in-openai/",
    "sources": [
        "https://gethelp.tiledesk.com/articles/create-an-ai-assistant-in-openai/"
    ],
    "content_chunks": null,
    "prompt_token_size": 1185,
    "error_message": null,
    "chat_history_dict": {
        "0": {
            "question": "how can i create an AI assistant?",
            "answer": "To create an AI assistant using OpenAI, you can follow these steps:\n\n1. **Visit OpenAI**: Navigate to the OpenAI website.\n2. **Access the API Section**:\n   - Go to ‘Products’, then select ‘API’.\n   - Log in and select ‘API’.\n3. **Navigate to Assistant Creation**:\n   - Ensure you are on the Dashboard.\n   - Click on ‘Assistant’ from the left sidebar menu.\n4. **Create the Assistant**:\n   - Click the green ‘Create’ button in the top right corner.\n   - Name your assistant and provide context in the ‘Instructions’ section to fine-tune its responses.\n5. **Select the Model**:\n   - For this example, you can use GPT-4o.\n6. **Handle File Formats**:\n   - If uploading a CSV file, use a Code interpreter.\n   - For PDF or text files, use the File Search feature.\n7. **Integrate with Tiledesk**:\n   - Copy the assistant ID.\n   - Go to the Tiledesk dashboard, click on the block where the ChatGPT Assistant is placed.\n   - In the right-side menu, paste the assistant ID into the “Assign GPT Assistant” field.\n\nIf you need"
        }
    }
}
```

{% endtab %}
{% endtabs %}

Example

```
curl -v -X GET -u giovanni@tiledesk.com:password -d {"question":"how can i create an AI assistant?","namespace":"66a897133eaa7f0013632c5b","model":"gpt-4o","temperature":0.7,"max_tokens":256,"top_k":4,"system_context":null} https://api.tiledesk.com/v3/63ad512e70d5ed0012ad6286/kb/qa
```

***


---

# 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://developer.tiledesk.com/apis/rest-api/knowledge-bases/qa.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.
