Knowledge Bases store data from databases, files, or webpages, and use different retrieval methods to fetch relevant information and present it as answers.
Learn more about AI Agents here.
Syntax
To feed an agent with data from different sources, use the knowledge_base skills. Here is how to create a knowledge base:
/**
* Create a new knowledge base.
* @param name The name of the knowledge base.
* @param model The model to use for the knowledge base.
* @param storage The storage to use for the knowledge base.
* @param metadataColumns The metadata columns for the knowledge base.
* @param contentColumns The content columns for the knowledge base.
* @param idColumn The ID column for the knowledge base.
* @param params Additional parameters for the knowledge base.
* @return The created knowledge base.
*/
public KnowledgeBase create(
String name,
Model model,
mindsdb.models.MDBTable storage,
List<String> metadataColumns,
List<String> contentColumns,
String idColumn,
Map<String, Object> params)
/**
* Create a new knowledge base with default parameters.
*
* @param name The name of the knowledge base.
* @return The created knowledge base.
*/
public KnowledgeBase create(String name)
KnowledgeBase kb = server.knowledgeBases.create("my_kb");
Here is how to insert data into a knowledge base:
// Insert data into a knowledge base from a file
Table data;
data = Table.read().csv("file_name.csv");
kb.insert(data);
// Insert data into a knowledge base from a database
Database db = server.getDatabase("db_name");
MDBTable table = db.getTable("table_name").filter("column_name=value");
kb.insert(table);
// insert data into a knowledge base
Map<String, String> data = Map.of(
"column_name1", "value1",
"column_name2", "value2"
);
kb.insert(data);
Here is how to query data from a knowledge base using specified keywords:
Table response = kb.find("my query").fetch();
Here is how to list all available knowledge bases:
List<KnowledgeBase> kbs = server.knowledgeBases.list();
Here is how to get a knowledge base by name:
KnowldgeBase kb = server.knowledgeBases.get('my_kb');
Here is how to drop a knowledge base:
server.getKnowledgeBases().drop("my_kb");