Package mindsdb.models
Class KnowledgeBase
java.lang.Object
mindsdb.services.Query
mindsdb.models.KnowledgeBase
- All Implemented Interfaces:
Cloneable
The KnowledgeBase class represents a knowledge base within a MindsDB project.
It extends the Query class and implements the Cloneable interface.
This class provides methods to interact with the knowledge base, including finding data, inserting files, inserting webpages, and inserting data using various formats such as Table objects, Query objects, and maps.
The KnowledgeBase class also supports deep cloning of its instances.
Example usage:
// Get KnowledgeBase object
KnowledgeBase kb = server.knowledgeBases.get("knowledge_base_name");
// Find data in the knowledge base
KnowledgeBase result = kb.find("some query", 10);
// Insert files into the knowledge base
List<String> filePaths = List.of("/path/to/file1.txt", "/path/to/file2.txt");
kb.insertFiles(filePaths);
// Insert webpages into the knowledge base
List<String> urls = List.of("http://example.com/page1", "http://example.com/page2");
kb.insertWebpages(urls, 2, List.of("filter1", "filter2"));
// Insert data using a Table object
tech.tablesaw.api.Table table = tech.tablesaw.api.Table.create("data");
kb.insert(table);
// Insert data using a Query object
Query query = new Query(api, "SELECT * FROM some_table");
kb.insert(query);
// Insert data using a map
Map<String, String> dataMap = new HashMap<>();
dataMap.put("column1", "value1");
dataMap.put("column2", "value2");
kb.insert(dataMap);
Note: This class requires the Tablesaw library for handling table data and the Unirest library for making HTTP requests.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected KnowledgeBase
clone()
Find data in the knowledge baseFind data in the knowledge basevoid
Insert data into the knowledge base using a mapvoid
Insert data into the knowledge base using a Query objectvoid
insert
(tech.tablesaw.api.Table data) Insert data into the knowledge base using a Table objectvoid
insertFiles
(List<String> filePaths) Insert files into the knowledge basevoid
insertWebpages
(List<String> urls, int crawlDepth, List<String> filters) Insert webpages into the knowledge basetoString()
-
Constructor Details
-
KnowledgeBase
Create a new KnowledgeBase object- Parameters:
api
- - RestAPI objectproject
- - Project objectdata
- - Map containing knowledge base data
-
-
Method Details
-
toString
-
find
Find data in the knowledge base- Parameters:
query
- - query stringlimit
- - limit the number of results- Returns:
- KnowledgeBase object
-
find
Find data in the knowledge base- Parameters:
query
- - query string- Returns:
- KnowledgeBase object
-
insertFiles
Insert files into the knowledge base- Parameters:
filePaths
- - list of file paths to insert
-
insertWebpages
Insert webpages into the knowledge base- Parameters:
urls
- - list of URLs to insertcrawlDepth
- - depth of the crawlfilters
- - list of filters
-
insert
public void insert(tech.tablesaw.api.Table data) Insert data into the knowledge base using a Table object- Parameters:
data
- - Table object containing the data to insert
-
insert
Insert data into the knowledge base using a Query object- Parameters:
data
- Query object containing the data to insert
-
insert
Insert data into the knowledge base using a map- Parameters:
data
- Map containing the data to insert
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-