# Use Tables to store your KBAI questions

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F7Ym8whtqwwOoAOYoBDZn%2FScreenshot%202024-10-01%20at%2016.23.57.png?alt=media&#x26;token=6c4cd743-35c6-4496-8eab-c416102aecef" alt=""><figcaption><p>Collect what the user asked.</p></figcaption></figure>

## Collect your KBAI answers

To store your KBAI questions and answers with Tables:

1. [Create a KBAI flow](https://docs.chatlayer.ai/navigation/knowledge-base-ai/build-your-kbai-flow) inside your bot or use the [KBAI template bot](https://docs.chatlayer.ai/start-quickly/bot-templates#knowledge-base-ai).
2. Make sure to [add content to your KBAI](https://docs.chatlayer.ai/navigation/knowledge-base-ai/add-content-to-your-kbai).
3. [Create a Table](https://docs.chatlayer.ai/navigation/tables/create-a-table-with-records) called *QuestionCollection*, with 2 text columns:&#x20;

   * *questionAsked*
   * *answerGiven*

   <figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fpbpwy2JWf9nYM2zsVg2N%2FScreenshot%202024-09-13%20at%2011.35.54.png?alt=media&#x26;token=76ff9fbd-6777-47c3-a50e-f7c9f771f779" alt="" width="375"><figcaption><p>Create a table that collects your KBAI questions and answers.</p></figcaption></figure>
4. **Save**.
5. Go back to your [**Flows**](https://docs.chatlayer.ai/navigation/bot-builder/flows).
6. Open the block where the KBAI search happens. In our case, it will be the **Not understood** block.&#x20;
7. Add a **Go to** after this block that you'll call *Populate table*.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F3ztdFW2QNJLSlZTjIYpU%2FScreenshot%202024-09-13%20at%2011.45.40.png?alt=media&#x26;token=778cc867-e871-48e2-a556-0b24f9907000" alt="" width="375"><figcaption><p>After the KBAI block, populate your table.</p></figcaption></figure>

7. **Save** this block.
8. Open the **Populate table** bloc&#x6B;**.**
9. Add a [**Table operations** ](https://docs.chatlayer.ai/tables/operate-on-your-records#add-a-table-operation-to-your-flow)step.
10. Select **Insert record** to the ***QuestionCollection*** table.
11. Configure the operation so that:
    * `{internal.nlp.expression}` is added to the **questionAsked** column
    * `{knowledgebase.answer}` is added to the **answerGiven** column

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F1zjOES3b6d4IhWVEP3Fm%2FScreenshot%202024-09-13%20at%2011.47.27.png?alt=media&#x26;token=a566c88d-9ff6-4c03-87d0-45103b5ec4e4" alt="" width="360"><figcaption><p>Populate your table with the KBAI question and answer.</p></figcaption></figure>

You could also add a time stamp:

<details>

<summary>Add the timestamp to your Table</summary>

To add a timestamp to your Table:

1. Make sure your Table has a *timestamp* column with a [timestamp](https://docs.chatlayer.ai/tables/column-types#timestamp) column type.&#x20;
2. Open the block that happens just before the **Populate Table** block.
3. Add a [**Set variables**](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state/action-bot-dialog#set-variables) step to it.
4. Set a `{timestamp}` variable as an expression for `NOW()`. You will need [expression syntax](https://docs.chatlayer.ai/integrateandcode/expression-syntax) for this.

<img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F9balGrQEBNmoZNgc4uC2%2FScreenshot%202024-10-01%20at%2016.29.35.png?alt=media&#x26;token=7a783347-ffad-4f9d-97c0-1c53e1697e50" alt="" data-size="original">

4. Click **Save**.
5. Open your **Populate Table** block.
6. Insert a `{timestamp}` record in the **timestamp** column.
7. Click **Save**.

The time stamp would appear like this in your Table:

</details>

12. **Save** your changes.

Now you should be able to see a list of your questions and answers from your Tables!

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FjHTSsWu8ZF9o9wrBM0zx%2FScreenshot%202024-10-01%20at%2016.21.49.png?alt=media&#x26;token=8f6e5aaf-4259-4907-adf2-c72c83c2b207" alt=""><figcaption><p>What your Table should look like after collection.</p></figcaption></figure>

## Collect questions where KBAI was unsatisfactory

It can be useful for you to store the places where your KBAI didn't answer to what the user said.

To collect variables where your KBAI was unsatisfactory:

1. Find the blocks where your KBAI goes when either an error occured or no result was found.
2. In each of them, pass on a variable that you'll call failure\_reason, and give it the value error occured or no result.
3. Make sure you have a column in your Table to store those.
4. When you populate your table, add those to the Table.&#x20;
