Class KnowledgeBase

java.lang.Object
mindsdb.services.Query
mindsdb.models.KnowledgeBase
All Implemented Interfaces:
Cloneable

public class KnowledgeBase extends Query implements 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.

See Also:
  • Constructor Details

    • KnowledgeBase

      public KnowledgeBase(RestAPI api, Project project, Map<String,Object> data)
      Create a new KnowledgeBase object
      Parameters:
      api - - RestAPI object
      project - - Project object
      data - - Map containing knowledge base data
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Query
    • find

      public KnowledgeBase find(String query, Integer limit)
      Find data in the knowledge base
      Parameters:
      query - - query string
      limit - - limit the number of results
      Returns:
      KnowledgeBase object
    • find

      public KnowledgeBase find(String query)
      Find data in the knowledge base
      Parameters:
      query - - query string
      Returns:
      KnowledgeBase object
    • insertFiles

      public void insertFiles(List<String> filePaths)
      Insert files into the knowledge base
      Parameters:
      filePaths - - list of file paths to insert
    • insertWebpages

      public void insertWebpages(List<String> urls, int crawlDepth, List<String> filters)
      Insert webpages into the knowledge base
      Parameters:
      urls - - list of URLs to insert
      crawlDepth - - depth of the crawl
      filters - - 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

      public void insert(Query data)
      Insert data into the knowledge base using a Query object
      Parameters:
      data - Query object containing the data to insert
    • insert

      public void insert(Map<String,String> data)
      Insert data into the knowledge base using a map
      Parameters:
      data - Map containing the data to insert
    • clone

      protected KnowledgeBase clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException