MindSQL
MindSQL copied to clipboard
Add MariaDB integration with native MariaDB VECTOR support
Add MariaDB Integration with Native VECTOR Support
This PR adds MariaDB database and vector store integration to MindSQL with native VECTOR(384) data type support.
What's Added
MariaDB Database Connector (mindsql/databases/mariadb.py)
- Uses official mariadb Python connector
- Works with MariaDB 11.7+ (includes VECTOR support)
- Handles schema discovery and DDL extraction
- Connection management with proper error handling
MariaDB Vector Store (mindsql/vectorstores/mariadb_vector.py)
- Native VECTOR(384) data type support - no JSON serialization needed
- FULLTEXT indexing for hybrid search (combines vector similarity with keyword search)
- Stores data and vectors in the same database
- ACID compliant with transaction support
What's Modified
Constants (mindsql/_utils/constants.py)
- Added MariaDB-specific query constants for database introspection
- SHOW DATABASES, table info schema, and CREATE TABLE queries
Helper Functions (mindsql/_helper/helper.py)
- Improved SQL extraction to handle different LLM response formats
- Better parsing of SQLQuery labels and code blocks
Core Pipeline (mindsql/core/mindsql_core.py)
- Enhanced DDL retrieval with fallback logic
- Tries vector search first, falls back to full schema if needed
Module Exports (mindsql/databases/__init__.py and mindsql/vectorstores/__init__.py)
- Added MariaDB and MariaDBVectorStore to public API
Architecture
Usage Example
from mindsql.core import MindSQLCore
from mindsql.databases import MariaDB
from mindsql.vectorstores import MariaDBVectorStore
from mindsql.llms import GoogleGenAi
# Setup
database = MariaDB()
vectorstore = MariaDBVectorStore(config={
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': 'password',
'database': 'mydb'
})
llm = GoogleGenAi(config={'api_key': 'your-key'})
mindsql = MindSQLCore(database=database, vectorstore=vectorstore, llm=llm)
# Connect and query
connection = database.create_connection('mariadb://user:pass@localhost:3306/mydb')
tables = database.get_table_names(connection, 'mydb')['table_name'].tolist()
# Ask questions in natural language
sql = mindsql.create_database_query(
question="Show me customers who ordered this month",
connection=connection,
tables=tables
)
results = database.execute_sql(connection, sql)