Skip to main content

Database

When to Use a Database​

Developers already have mini programs/web applications. Users generate data through mini programs/web. You want the AI to comprehend this data and become a personalized AI agent. For instance, the same query can yield answers tailored to each user's specific data.

Database vs. Knowledge Base​

Comparison ItemKnowledge BaseDatabase
Data Typedocx/pdf/ppt/markdownTables/json
Data Update FrequencyLow frequencyHigh frequency
Data MaintainerDevelopersDevelopers + End Users
Typical ApplicationsIntelligent Customer Service, Q&A System, Expert Decision-MakingUser Behavior Analysis, Data Querying

How to Configure a Data Model​

In the Cloud Development Platform database module, you can create new data models.

  1. Create a new data model, select the database (document-based). Creating a Data Model
  2. Model names and field names should be described in Chinese to facilitate the large model's understanding of the relationship between user questions and the data model. Configuring a Data Model

How to Bind a Data Model to an AI Agent​

const msg = "user question"
const databaseModel = ["Data Model ID-1", "Data Model ID-2"]
const result = await this.botContext.bot.tools.searchDB(
this.botContext.info.botId,
msg,
databaseModel
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query data model content: ${result?.message}`);
}

How to talk to an agent​

You can talk to the agent in natural language. If your question contains database-related information, it will trigger a database query.

Library agent Example​

Suppose we want to create a library AI assistant that can help students quickly check whether the library has specific books, query which books they have borrowed, and analyze their favorite book genres.

Data Model​

Requires three data models: User Information Table, Book Information Table, Borrowing Records Table.

  • The permissions for the User Information Table are readable by everyone, and readable and writable only by the creator and administrators. It includes at least the following fields: ID, User Name, User Grade.
  • The permissions for the Book Information Table are readable by everyone, and writable only by administrators. It includes at least the following fields: ID, Book Name, Book Author.
  • The permissions for the Borrowing Records Table are readable and writable only by the creator and administrators. It includes at least the following fields: Book ID, Borrower ID, Borrowing Time.

Book Information Table User Table Borrowing Records Table

Dialogue Effect​

Query All Books​

This will trigger querying the Book Information Table.

Matching a Table

Query Borrowed Books​

This will trigger querying the Book Information Table and Borrowing Records Table.

Joining Two Tables

Query Freshmen's Favorite Books​

This will trigger querying the User Information Table, Borrowing Records Table, and Book Information Table.

Joining Three Tables