Interface BBjAdminAI
- All Superinterfaces:
Remote,Serializable
Provides access to the Basis AI natural-language-to-SQL library from within
the BBj Admin API. Use this interface to configure an LLM provider, index a
BBj database schema, and convert plain-English questions into SQL
SELECT statements.
Obtain an instance via BBjAdminBase.getAI(). The instance is not
yet configured on creation; call configure(BBjAdminAIConfig),
loadDefaultConfig(), or loadConfig(String) before invoking
any schema or query methods.
Java Sample
BBjAdminBase api = BBjAdminFactory.getBBjAdmin(InetAddress.getByName("myserver"), 2002, true, "admin", "secret");
BBjAdminAI ai = api.getAI();
BBjAdminAIConfig cfg = new BBjAdminAIConfig();
cfg.setActiveProvider(BBjAdminAIConfig.PROVIDER_OPENAI);
cfg.getOpenai().setApiKey("sk-...");
ai.configure(cfg);
ai.indexSchema("jdbc:bbj:///mydb", "admin", "secret", null);
BBjAdminAIQueryResult result = ai.buildQuery("Show all invoices for customer ACME Corp");
if (result.isSuccessful()) {
System.out.println(result.getGeneratedSql());
}
ai.close();
BBj Sample
use com.basis.api.admin.BBjAdminAI
use com.basis.api.admin.BBjAdminAIConfig
...
ai! = api!.getAI()
cfg! = new BBjAdminAIConfig()
cfg!.setActiveProvider(BBjAdminAIConfig.PROVIDER_OPENAI)
cfg!.getOpenai().setApiKey("sk-...")
ai!.configure(cfg!)
ai!.indexSchema("jdbc:bbj:///mydb", "admin", "secret", BBjAPI.NULL)
result! = ai!.buildQuery("Show all invoices for customer ACME Corp")
if result!.isSuccessful()
print result!.getGeneratedSql()
endif
ai!.close()
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuildQuery(String p_naturalLanguageQuery) Converts a plain-English question into a SQLSELECTstatement using a Retrieval-Augmented Generation (RAG) pipeline.voidDeletes all documents from the schema vector index.voidclose()Closes the underlying AI engine and releases all resources (schema vector store, embedding model, etc.).voidconfigure(BBjAdminAIConfig p_config) Configures the AI instance with the supplied settings and activates the specified LLM provider.Returns a snapshot of the currently active configuration, ornullif no configuration has been set yet.longReturns the number of documents currently stored in the schema index.voidOpens a new JDBC connection, reads the database schema viaDatabaseMetaData, embeds the schema as dense vectors, and stores them in a JSON-backed vector store.voidindexSchema(Connection p_connection, List<String> p_tables) Indexes the schema using an already-openConnection.listIndexedTableNames(String p_jdbcUrl) Returns an alphabetically sorted, immutable list of table names that have been indexed in the schema vector store for the database identified by the given JDBC URL.Returns every document in the schema index, sorted by type (TABLEfirst, thenRELATIONSHIP) then by table name.listTables(String p_jdbcUrl, String p_username, String p_password) Opens a JDBC connection and returns the names of all user tables visible to the given credentials, without modifying the schema index.voidloadConfig(String p_configPath) Loads configuration from the specified JSON file path and activates it.voidLoads configuration from the default location (~/.basis-ai/config.json) and activates it.voidEncrypts sensitive fields and writes the current configuration to the default location (~/.basis-ai/config.json).voidsaveConfig(BBjAdminAIConfig p_config) Updates the active configuration fromp_configand writes it to the default location (~/.basis-ai/config.json).voidsaveConfig(BBjAdminAIConfig p_config, String p_configPath) Updates the active configuration fromp_configand writes it to the specified path.voidsaveConfig(String p_configPath) Encrypts sensitive fields and writes the current configuration to the specified path.sendPrompt(BBjAdminAIPromptRequest p_request) Sends a fully configured prompt to the LLM, supporting an explicit system prompt, conversation history, temperature override, and max-token override.sendPrompt(String p_prompt) Sends a simple one-shot prompt to the configured LLM using the configuredgeneralSystemPrompt.
-
Method Details
-
configure
Configures the AI instance with the supplied settings and activates the specified LLM provider. Any previously active configuration is discarded.- Parameters:
p_config- Configuration to apply. Must not benull.- Throws:
BBjAdminException- if the underlying AI engine cannot be initialised with the given configuration.
-
loadDefaultConfig
Loads configuration from the default location (~/.basis-ai/config.json) and activates it. If the file does not exist, a default unconfigured instance is prepared.- Throws:
BBjAdminException- if the configuration file cannot be read or the AI engine cannot be initialised.
-
loadConfig
Loads configuration from the specified JSON file path and activates it.- Parameters:
p_configPath- Filesystem path to a JSON configuration file.- Throws:
BBjAdminException- if the file cannot be read or the AI engine cannot be initialised.
-
getConfig
Returns a snapshot of the currently active configuration, ornullif no configuration has been set yet.- Throws:
BBjAdminException
-
saveConfig
Encrypts sensitive fields and writes the current configuration to the default location (~/.basis-ai/config.json). Parent directories are created if they do not exist.- Throws:
BBjAdminException- if the configuration cannot be written.
-
saveConfig
Updates the active configuration fromp_configand writes it to the default location (~/.basis-ai/config.json).This is the preferred overload when the caller obtained a config via
getConfig(), modified it, and wants to persist the changes without reinitialising the AI engine.- Parameters:
p_config- The configuration to apply and save.- Throws:
BBjAdminException- if the configuration cannot be applied or written.
-
saveConfig
Updates the active configuration fromp_configand writes it to the specified path.- Parameters:
p_config- The configuration to apply and save.p_configPath- Filesystem path to write the JSON configuration to.- Throws:
BBjAdminException- if the configuration cannot be applied or written.
-
saveConfig
Encrypts sensitive fields and writes the current configuration to the specified path.- Parameters:
p_configPath- Filesystem path to write the JSON configuration to.- Throws:
BBjAdminException- if the configuration cannot be written.
-
listIndexedTableNames
Returns an alphabetically sorted, immutable list of table names that have been indexed in the schema vector store for the database identified by the given JDBC URL. The database name is extracted from thedatabasequery-string parameter of the URL.- Parameters:
p_jdbcUrl- JDBC URL containing adatabase=<name>parameter, e.g.jdbc:basis://localhost?database=ChileCompany&token=...- Returns:
- sorted list of indexed table names; empty if none are indexed
- Throws:
BBjAdminException- if the index cannot be read
-
listTables
List<String> listTables(String p_jdbcUrl, String p_username, String p_password) throws BBjAdminException Opens a JDBC connection and returns the names of all user tables visible to the given credentials, without modifying the schema index.This is a lightweight alternative to
indexSchema(java.lang.String, java.lang.String, java.lang.String, java.util.List<java.lang.String>)intended for populating a table-picker UI before the user decides which tables to index.- Parameters:
p_jdbcUrl- JDBC connection URL.p_username- Database username. May benull.p_password- Database password. May benull.- Returns:
- Sorted, immutable list of table names.
- Throws:
BBjAdminException- if the connection or metadata call fails.
-
indexSchema
void indexSchema(String p_jdbcUrl, String p_username, String p_password, List<String> p_tables) throws BBjAdminException Opens a new JDBC connection, reads the database schema viaDatabaseMetaData, embeds the schema as dense vectors, and stores them in a JSON-backed vector store. Any previously indexed data for the same tables is replaced.Schema indexing is a one-time operation. The schema index persists across JVM restarts; re-index only when the database schema changes.
- Parameters:
p_jdbcUrl- JDBC connection URL (e.g.jdbc:bbj:///mydb).p_username- Database username. May benull.p_password- Database password. May benull.p_tables- Table names to index. Passnullor an empty list to index all tables in the database.- Throws:
BBjAdminException- if indexing fails or no AI instance has been configured yet.
-
indexSchema
Indexes the schema using an already-openConnection. The connection is not closed by this method; the caller retains ownership.- Parameters:
p_connection- An open JDBC connection.p_tables- Table names to index, ornull/ empty to index all tables.- Throws:
BBjAdminException- if indexing fails or no AI instance has been configured yet.
-
clearSchemaIndex
Deletes all documents from the schema vector index. Useful before performing a full re-index.- Throws:
BBjAdminException- if the index cannot be cleared.
-
getSchemaDocumentCount
Returns the number of documents currently stored in the schema index.- Returns:
- Document count.
- Throws:
BBjAdminException- if the count cannot be retrieved.
-
listSchemaDocuments
Returns every document in the schema index, sorted by type (TABLEfirst, thenRELATIONSHIP) then by table name. Embedding vectors are not included in the returned objects.- Returns:
- Immutable list of
BBjAdminAISchemaDocumentobjects. - Throws:
BBjAdminException- if the index cannot be read.
-
buildQuery
Converts a plain-English question into a SQLSELECTstatement using a Retrieval-Augmented Generation (RAG) pipeline. The schema must have been indexed at least once before calling this method.Always check
BBjAdminAIQueryResult.isSuccessful()before usingBBjAdminAIQueryResult.getGeneratedSql().- Parameters:
p_naturalLanguageQuery- Plain-English description of the data to retrieve.- Returns:
- A
BBjAdminAIQueryResultcontaining the generated SQL or an error message. - Throws:
BBjAdminException- if the LLM call fails or no AI instance has been configured yet.
-
sendPrompt
Sends a simple one-shot prompt to the configured LLM using the configuredgeneralSystemPrompt. Ideal for explanations, summaries, or any non-SQL interaction.- Parameters:
p_prompt- The user message to send.- Returns:
- A
BBjAdminAIPromptResponsecontaining the reply and token-usage information. - Throws:
BBjAdminException- if the LLM call fails or no AI instance has been configured yet.
-
sendPrompt
Sends a fully configured prompt to the LLM, supporting an explicit system prompt, conversation history, temperature override, and max-token override.- Parameters:
p_request- ABBjAdminAIPromptRequestdescribing the request.- Returns:
- A
BBjAdminAIPromptResponsecontaining the reply and token-usage information. - Throws:
BBjAdminException- if the LLM call fails or no AI instance has been configured yet.
-
close
Closes the underlying AI engine and releases all resources (schema vector store, embedding model, etc.). After this call, all other methods will throwBBjAdminExceptionuntil the instance is reconfigured viaconfigure(BBjAdminAIConfig)orloadDefaultConfig().- Throws:
BBjAdminException- if resources cannot be released cleanly.
-