Datasets
Datasets play a crucial role in building intelligent agents within the Chatbotkit platform. They act as structured collections of information that agents can query to provide accurate responses. This guide covers how to manage datasets and their records using the Chatbotkit SDK.
1. Overview
A Dataset is a collection of records that agents use to search for information. Each dataset can be configured with search parameters and visibility settings to control its behavior and accessibility.
Creating a Dataset
To create a new dataset in Chatbotkit, use the dataset.create method. This method accepts various configuration parameters that define how the dataset will behave and interact with agents. Here's a breakdown of the creation process:
const dataset = await cbk.dataset.create({ description: 'Customer support FAQs', matchInstruction: 'Focus on matching customer issues', mismatchInstruction: 'Avoid technical jargon', name: 'SupportFAQs', recordMaxTokens: 500, searchMaxRecords: 10, searchMaxTokens: 100, searchMinScore: 0.8, separators: '\n\n', store: 'default', visibility: 'protected' });
javascript
description
: A brief explanation of the dataset.matchInstruction
/mismatchInstruction
: Guidance for matching queries.recordMaxTokens
: Maximum tokens per record.searchMaxRecords
/searchMaxTokens
: Search result limits.visibility
: Controls access (private
,protected
,public
).
Fetching a Dataset
To retrieve an existing dataset from Chatbotkit, use the dataset.fetch method. This method requires the dataset's unique identifier and returns the dataset's configuration and metadata.
const dataset = await cbk.dataset.fetch('123');
javascript
- Retrieves a dataset by its unique ID.
Listing All Datasets
The dataset.list method allows you to retrieve a paginated list of all datasets in your account. You can control the order and number of results using optional parameters.
const datasets = await cbk.dataset.list({ order: 'asc', take: 20 });
javascript
- Lists all datasets with optional sorting and pagination.
Updating a Dataset
To update an existing dataset's configuration, use the dataset.update method. This method requires the dataset's ID and accepts configuration parameters similar to those used during creation. Any parameters not specified will retain their current values.
const updatedDataset = await cbk.dataset.update('123', { description: 'Updated support FAQs', visibility: 'public' });
javascript
- Modifies existing datasets using their ID.
Deleting a Dataset
To remove a dataset from your Chatbotkit account, use the dataset.delete method. This operation permanently deletes the dataset and all its associated records, so use it with caution. The method requires the dataset's unique identifier as a parameter.
const result = await cbk.dataset.delete('123');
javascript
- Permanently removes a dataset.
Searching a Dataset
The dataset.search method allows you to search through dataset records using natural language queries. This method takes a dataset ID and a search query as parameters, returning relevant records based on the dataset's configured search parameters like searchMaxRecords and searchMinScore.
const searchResults = await cbk.dataset.search('123', 'refund policy');
javascript
- Queries the dataset for relevant records.
2. Dataset Records Overview
Dataset Records are individual entries within a dataset. Each record contains specific pieces of information that agents can retrieve.
Creating a Dataset Record
To create a new record in a dataset, use the datasetRecord.create method, which allows you to specify the record's content, name, and source information.
const datasetRecord = await cbk.dataset.record.create({ text: 'Refunds are processed within 5-7 business days.', name: 'Refund Policy', source: 'Support Documentation' });
javascript
text
: The main content of the record.name
: A descriptive label for the record.source
: The origin of the data.
Fetching a Dataset Record
The dataset.fetch method allows you to retrieve a specific record from a dataset by providing both the dataset ID and the record ID as parameters.
const record = await cbk.dataset.record.fetch('123', '456');
javascript
- Retrieves a record by dataset and record ID.
Listing All Records
The datasetRecord.list method allows you to retrieve a paginated list of all records within a dataset, with options to control the order and number of results returned.
const records = await cbk.dataset.record.list('123', { order: 'desc', take: 50 });
javascript
- Lists records with optional sorting and limits.
Updating a Dataset Record
The datasetRecord.update method allows you to modify existing records within a dataset by providing the dataset ID, record ID, and the updated content.
const updatedRecord = await cbk.dataset.record.update('123', '456', { text: 'Refunds are now processed within 3-5 business days.' });
javascript
- Modifies existing records.
Deleting a Dataset Record
To remove a specific record from a dataset, use the datasetRecord.delete method, which requires both the dataset ID and record ID as parameters.
const result = await cbk.dataset.record.delete('123', '456');
javascript
- Permanently removes a record.
Conclusion
This guide demonstrates how datasets and records form the backbone of Chatbotkit agents by providing structured, searchable information. By effectively managing datasets, developers can build more responsive and intelligent chatbot agents.