Skip to content

Commit 84a1a82

Browse files
committed
feat: add LLM DB Query AI usecase (#876)
1 parent 49473c0 commit 84a1a82

34 files changed

Lines changed: 7602 additions & 0 deletions

docs/use-cases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ Transform your Intel® hardware into powerful AI and edge computing solutions wi
126126
9. [GMSL Camera Enablement](../usecases/camera/gmsl/README.md)
127127
10. [MIPI Camera Enablement](../usecases/camera/mipi/README.md)
128128
11. [Visual & Textual Query-driven Document Reasoning Engine](../usecases/ai/visual-textual-query-driven-document-reasoning-engine/README.md)
129+
12. [LLM Database Query using Intel AI Assistant Builder](../usecases/ai/llm_dbquery/README.md)

usecases/ai/llm_dbquery/.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# .gitignore for ODBC SuperBuilder
2+
3+
# Python
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
*.so
8+
.Python
9+
env/
10+
venv/
11+
ENV/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# Virtual Environment
29+
venv/
30+
ENV/
31+
env/
32+
.venv/
33+
34+
# IDE
35+
.vscode/
36+
.idea/
37+
*.swp
38+
*.swo
39+
*~
40+
41+
# OS
42+
.DS_Store
43+
Thumbs.db
44+
45+
# Docker volumes (data persists in named volumes)
46+
databases/
47+
database_exports/
48+
49+
# Logs
50+
*.log
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
production

usecases/ai/llm_dbquery/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!--
2+
Copyright (C) 2025 Intel Corporation
3+
SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
# LLM DB Query (ODBC SuperBuilder)
7+
8+
Lightweight toolkit for LLM-driven natural-language data exploration across multiple local SQLite databases using the MCP toolchain.
9+
Natural-language SQL queries across many local .sqlite files, with optional AI analysis of results.
10+
11+
## Key features
12+
- Query multiple local `.sqlite` files from a single natural-language prompt
13+
- Convert NL → SQL via a local OpenAI*-compatible or llama.cpp endpoint
14+
- Execute SQL across attached databases using ODBC (pyodbc)
15+
- Chain SQL results into an MCP data analysis server for AI-powered reports
16+
- Export database schema and data to text files for verification and auditing
17+
18+
## Architecture
19+
![Architecture diagram](./docs/Architecture.png)
20+
21+
## Example (Increased Playback Speed)
22+
<img src="./docs/LLMDB.gif" alt="Example" width="800" />
23+
24+
## Validated hardware
25+
- CPU: Intel Core Ultra Series 1 and above
26+
- GPU: Intel® Arc™ B60 graphics (serve 2 MCP and Intel Superbuilder in 1 machine)
27+
- RAM: 64GB
28+
- DISK: 256GB
29+
30+
## Software requirements
31+
- Python 3.10+ (see requirements.txt)
32+
- ODBC driver appropriate for your platform
33+
- Windows 11 supported; test on the platform matching your environment
34+
35+
## Quick start (Windows PowerShell)
36+
1. Install Python dependencies:
37+
```cmd
38+
pip install -r requirements.txt
39+
```
40+
41+
2. (Optional) Create sample databases and generated exports:
42+
```cmd
43+
python create_databases.py
44+
```
45+
46+
3. Run preflight checks:
47+
```cmd
48+
python startup_check.py
49+
```
50+
51+
4. Start MCP servers (two terminals)
52+
- Database query server:
53+
```powershell
54+
cd ./mcp_odbcserver
55+
run.ps1
56+
```
57+
58+
- Data analysis server:
59+
```powershell
60+
cd ./mcp_data_analysis_server
61+
run.ps1
62+
```
63+
64+
5. From your MCP client (for example, Intel® AI Superbuilder):
65+
- Configure the MCP servers/agents for ODBC querying and data analysis
66+
- Send natural-language queries to the ODBC server; receive JSON results and analysis from the data-analysis server
67+
- Use System Prompt at Intel AI Assistant Builder as below:
68+
```
69+
# Data Assistant Tools: query_database, analyze_data (both are MCP tools) ## Workflow For every user question: **STEP 1: Execute Task 1** Call `query_database("user's question")` - Returns JSON: `{"data": [...], "reasoning": {...}}` Show: - 🧠 Model Reasoning: [reasoning.model_reasoning] - 🔍 SQL: [reasoning.generated_sql] - 📊 Data: [display as table] - 🎯 Sources: [reasoning.databases_queried] **STEP 2: Execute Task 2** Call `analyze_data(data=result["data"], analysis_question="user's question")` **If analyze_data fails:** - Display the error message - Stop the workflow (do not retry) - Ask user if they want to proceed with just the query results ## Rules ✅ Pass result["data"] as JSON to analyze_data ✅ Stop immediately if analyze_data throws an error ✅ Do not attempt to retry analyze_data on failure ✅ Complete all steps only if both succeed
70+
```
71+
72+
## Project layout
73+
```
74+
usecases/ai/llm_dbquery/
75+
├── create_databases.py # create sample DBs and exports
76+
├── query_databases.py # ODBC helpers & multi-db logic
77+
├── nl_query.py # NL -> SQL interface (schema discovery)
78+
├── startup_check.py # preflight checks (drivers, LLM, deps)
79+
├── requirements.txt
80+
├── /databases # place your .sqlite files here
81+
├── /database_exports # generated text exports
82+
├── /mcp_odbcserver # ODBC server (MCP)
83+
└── /mcp_data_analysis_server # data analysis server (MCP)
84+
```
85+
86+
## FAQ
87+
Q: Where do I put my SQLite files?
88+
A: Add .sqlite files to the `databases/` folder. The toolkit auto-discovers all `.sqlite` files (no hardcoded names) but make sure to select your primary database when you run `startup_check.py`
89+

0 commit comments

Comments
 (0)