Kleos - supercharge MindsDB interaction


Kleos CLI: Supercharging Your MindsDB Workflow with Knowledge Bases, AI Agents, and More!
A powerful Python CLI designed to streamline your interactions with MindsDB, focusing on Knowledge Bases, AI Agents, custom AI model creation, and automation. Built with Click and Rich for an exceptional developer experience.
Introduction: What is Kleos CLI and Why MindsDB?
In the fast-paced world of AI and data, developers are always on the lookout for tools that simplify complexity and speed up workflows. Enter MindsDB, an innovative open-source platform that integrates machine learning capabilities directly into your database, enabling you to create, train, and query AI models using standard SQL. To enhance the intuitiveness and efficiency of interacting with MindsDB's powerful features, particularly its advanced Knowledge Base and AI Agent functionalities, I developed Kleos CLI.
Kleos, derived from the Greek word for renown or glory, is a Python-based command-line interface designed to be your reliable companion for all things MindsDB. Every system has its telos—its ultimate purpose. This CLI fulfills the purpose of MindsDB's Knowledge Base: to seek, structure, and deliver insights through intelligent agents. Kleos aims to streamline the process of building and managing these intelligent systems directly from your terminal. This article will guide you through Kleos CLI, highlighting its key features and demonstrating how it leverages MindsDB to help you build powerful AI-driven applications with ease.
Core Philosophy: SQL as the Language of AI
One of MindsDB's core principles, which Kleos fully embraces, is using SQL as the primary language for AI development. Instead of requiring developers to learn complex machine learning libraries or manage separate MLOps pipelines for many common tasks, MindsDB allows you to:
Connect to diverse data sources: From your existing databases to SaaS applications and file storages.
Create AI Models: Train models for tasks like classification, regression, time series forecasting, and even interact with large language models (LLMs) for generative tasks.
Build Knowledge Bases: Create semantic search capabilities over your textual data.
Deploy AI Agents: Combine LLMs with your data and KBs to create intelligent assistants.
Query Predictions and Insights: Fetch predictions and insights as if you were querying a regular database table.
All of this is achieved using SQL extensions. Kleos CLI acts as a convenient and powerful interface to execute these SQL commands, manage your MindsDB resources, and automate workflows, making the power of in-database AI more accessible than ever. We've built Kleos using Python, Click for robust command-line parsing, and Rich for beautiful, informative terminal output. Let's dive into what Kleos can do!
Key Features of Kleos & MindsDB in Action
Kleos provides a comprehensive suite of commands to manage various aspects of your MindsDB environment. Here’s a look at some core functionalities:
1. Seamless Setup (kleos setup
)
Getting started often involves connecting to your data. MindsDB excels at integrating with numerous data sources. Kleos helps you quickly set up common data sources. For instance, the HackerNews data source, a popular source for real-time discussions and articles, can be configured with a single command:
bash kleos setup hackernews --name my_hackernews_data
This simple command tells MindsDB to create a connection named my_hackernews_data
that can query HackerNews directly. Kleos ensures this process is smooth, even creating the datasource if it doesn't already exist when you try to use it in other commands.
2. Knowledge Bases (KBs) - The Heart of Kleos (kleos kb ...
)
Knowledge Bases are a cornerstone of MindsDB's recent advancements, allowing you to embed and search large volumes of text data semantically. Kleos provides extensive support for managing KBs.
a. Creating Knowledge Bases (kleos kb create
)
You can easily create a new KB, specifying the underlying embedding models (to convert text to vectors) and optional reranking models (to improve search result relevance). Kleos supports models from various providers like Ollama (for local LLMs) and Google Gemini.
# Create a KB using a local Ollama model for embeddings
kleos kb create my_ollama_kb \
--embedding-model nomic-embed-text \
--content-columns "title,body_text" \
--metadata-columns "doc_id,category" \
--id-column doc_id
# Create a KB using Google's embedding model and an Ollama reranker
kleos kb create gemini_docs_kb \
--embedding-provider google \
--embedding-model text-embedding-004 \
--embedding-api-key YOUR_GOOGLE_API_KEY \
--reranking-provider ollama \
--reranking-model llama3 \
--content-columns "page_content"
Kleos handles the construction of the CREATE KNOWLEDGE_BASE
SQL, including the JSON parameters for model configurations.
b. Ingesting Data (kleos kb ingest
)
Once a KB is created, you need to populate it. Kleos simplifies data ingestion, especially from structured sources like the HackerNews tables.
# Ingest the latest 100 stories from HackerNews into 'my_hn_kb'
# This uses smart defaults for content and metadata columns.
kleos kb ingest my_hn_kb --from-hackernews stories --limit 100 --hn-datasource my_hackernews_data
For more control, you can specify which columns map to your KB's content and metadata:
kleos kb ingest my_custom_kb --from-hackernews comments \
--hn-datasource my_hackernews_data \
--content-column "text" \
--metadata-map '{"comment_id":"id", "author":"by", "parent_story":"parent"}' \
--limit 200
This command translates to an INSERT INTO ... SELECT ...
statement, efficiently loading data into your KB.
c. Semantic Search (kleos kb query
)
The true power of KBs lies in semantic search. Kleos allows you to query your KBs using natural language, with options for metadata filtering:
# Simple semantic search
kleos kb query my_docs_kb "recent breakthroughs in quantum computing"
# Search with metadata filtering and limit results
kleos kb query product_reviews_kb "positive feedback on model X" \
--metadata-filter '{"rating":{"$gte": 4}, "verified_purchase":true}' \
--limit 5
The --metadata-filter
accepts a JSON string, enabling powerful, targeted queries by combining vector search with traditional attribute filtering.
d. Indexing and Evaluation
Kleos also includes commands for managing KB indexes (kleos kb index
) which are crucial for search performance, and for evaluating KB effectiveness (kleos kb evaluate
) using various metrics and even LLM-based relevancy checks. These are vital for maintaining and optimizing your KBs.
3. AI Agents - Your Intelligent Assistants (kleos kb create-agent
, kleos kb query-agent
)
MindsDB allows you to create AI Agents that combine the power of Large Language Models (LLMs) with the contextual knowledge stored in your KBs and databases. Kleos makes agent creation and interaction straightforward.
a. Creating Agents (kleos kb create-agent
)
Define an agent, link it to one or more KBs, and specify the LLM it should use:
# Create an agent using Google's Gemini model, connected to 'product_faq_kb'
kleos kb create-agent product_support_agent \
--model-name gemini-1.5-flash \
--include-knowledge-bases "product_faq_kb" \
--prompt-template "You are a helpful support agent. Answer the user's question based on the provided documents: {{question}}. Context: {{context}}"
You can also include regular database tables for additional context and pass other parameters like temperature or API keys.
b. Querying Agents (kleos kb query-agent
)
Once created, interact with your agent using natural language:
kleos kb query-agent product_support_agent "What is the warranty period for model X?"
The agent will leverage its LLM and the content from product_faq_kb
to provide an answer.
4. AI Models / Generative AI Tables (kleos ai ...
)
Beyond KBs and Agents, Kleos helps you manage MindsDB's powerful AI Models (often referred to as Generative AI Tables). These models are trained on your data using SQL and can perform a variety of tasks.
a. Creating AI Models from Data (kleos ai create-model
)
Train a model directly from a SQL query. For example, to create a model that summarizes HackerNews story titles:
kleos ai create-model title_summarizer \
--select-data-query "SELECT title AS original_title FROM my_hackernews_data.stories WHERE score > 50 LIMIT 100" \
--predict-column title_summary \
--engine openai \
--prompt-template "Generate a very short, catchy summary for this news title: {{original_title}}" \
--param api_key YOUR_OPENAI_KEY \
--param model_name gpt-3.5-turbo-instruct
This creates a queryable title_summarizer
model. You can then select from it, providing new titles to get summaries. Kleos supports listing, describing, refreshing, and dropping these models too.
5. Automation with MindsDB Jobs (kleos job ...
)
Repetitive tasks like data ingestion or model retraining can be automated using MindsDB Jobs. Kleos provides commands to manage these jobs.
a. Creating Jobs (kleos job create
, kleos job update-hn-refresh
)
For instance, to create a job that updates your HackerNews data daily:
kleos job update-hn-refresh daily_hn_data_update --schedule "EVERY 1 day at 02:00"
Or, create a custom job with any SQL statements:
kleos job create nightly_kb_update \
"INSERT INTO my_kb SELECT new_text, new_metadata FROM new_data_source LATEST;" \
--schedule "EVERY 1 day at 03:00"
Kleos also allows you to list, check the status/history of, and drop jobs, giving you full control over your automated workflows.
CLI Structure & User Experience
Kleos is built with developer experience in mind, utilizing a modern Python stack:
Click: For creating a robust and composable command-line interface structure. This allows for clear command groups (
kb
,ai
,job
,setup
) and intuitive argument/option parsing.Rich: To provide beautiful and informative terminal output. Kleos uses Rich for:
Styling text with colors and emphasis.
Displaying data in well-formatted tables.
Showing progress with spinners during longer operations.
Syntax highlighting for SQL queries and JSON outputs.
Interactive Mode: Simply running
kleos
drops you into an interactive shell where you can execute commands sequentially without retypingkleos
each time. Typing a command group name (e.g.,kb
) in this mode shows help for that group.Comprehensive Help: Detailed help messages are available for all commands and options via
--help
or-h
, formatted clearly using Rich.Utility Commands: Includes handy utilities like
kleos info
(for CLI and project details),kleos about
(for author info), andkleos cls
(to clear the terminal screen).
This combination aims to make Kleos not just powerful but also pleasant to use.
Local Development & Experimentation Made Easy
To help you get started quickly with Kleos and a full MindsDB environment locally, the project includes a docker-compose.yml
file. With Docker and Docker Compose installed, you can spin up:
A MindsDB instance.
An Ollama instance for running local LLMs (like Llama3 or embedding models like Nomic).
Simply run:
docker-compose up -d
Then, pull your desired Ollama models:
docker exec -it ollama_instance ollama pull nomic-embed-text
docker exec -it ollama_instance ollama pull llama3
Configure your Kleos .env
file to point to these local services (e.g., MINDSDB_HOST="
http://127.0.0.1:47334
"
, OLLAMA_BASE_URL="
http://127.0.0.1:11434
"
), and you're ready to experiment with all of Kleos's features against a local, fully functional MindsDB setup.
Why This Matters: The Power of In-Database AI & Kleos's Role
The ability to perform complex AI/ML tasks directly within your database using SQL, as enabled by MindsDB, is a game-changer. It democratizes AI by lowering the barrier to entry and streamlines workflows by keeping data and intelligence in one place.
Kleos CLI aims to be a key enabler in this ecosystem by providing:
Accessibility: A user-friendly command-line tool that makes MindsDB's advanced features easy to discover and use.
Productivity: Simplifying common tasks like KB management, agent creation, and job automation.
Experimentation: Facilitating local development and rapid prototyping with tools like the provided Docker Compose setup.
Whether you're building RAG (Retrieval Augmented Generation) applications, creating custom chatbots, automating data insights, or simply exploring the potential of in-database AI, Kleos and MindsDB offer a powerful combination.
Call to Action & Future
Kleos CLI is an open-source project, and your contributions and feedback are highly welcome!
GitHub Repository: Kleos
Try it out: clone the repo and install locally, by running the
setup-dev.sh
bash scriptExplore MindsDB: Dive deeper into what MindsDB can offer.
The journey of Kleos is just beginning. Future enhancements could include even richer interactive experiences, more detailed reporting outputs, and support for a wider array of MindsDB's evolving features. Join us in building the future of accessible AI!
Connect With Me 🌐🤝
Explore my work and connect with me on these platforms:
I'm always open to networking and collaboration!
Subscribe to my newsletter
Read articles from Yash K. Saini directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
