Query your database in plain English.
Runs on your machine.

OpsMind is an open source tool that connects to a SQL database, ingests PDF documents, and lets you ask questions in natural language. It uses a local LLM via Ollama — no cloud, no API keys, no data leaves your machine.

Python Streamlit SQLAlchemy ChromaDB Ollama SQLite / SQL Server
View Source Code
OpsMind — Streamlit dashboard showing natural language SQL query interface

What it does

A Streamlit app with 7 tabs. Connects to SQLite (demo) or SQL Server (production).

Natural Language SQL

Type a question. The LLM converts it to SQL, runs it against your database, and explains the result. Pre-built queries handle the 10 most common questions without LLM generation.

Document Search (RAG)

Upload PDFs. ChromaDB indexes them into vector embeddings. Ask questions like "What is the allergen procedure?" and get the relevant paragraph with source citation.

Dashboard

Production output, waste, yield, and orders visualised with Plotly charts. KPIs update from live database queries. Waste cost shown in GBP.

Compliance

Batch traceability by code. Temperature excursion detection. Allergen matrix generation. Compliance score calculation.

Smart Alerts

Checks for: yield drops vs 30-day average, temperature excursions, overtime breaches (Working Time Regulations), expiring stock, order shortfalls.

Excel/CSV Upload

Upload a spreadsheet, ask a question about it. Uses Pandas for analysis. The LLM summarises the results.

How it works

Architecture diagram.

# User types a question
"How much salmon did we process this week?"

# Step 1: Query Library checks 10 pre-built patterns
Match found → uses tested SQL (no LLM needed)

# Step 2: If no match → Schema Registry selects relevant tables
150 tables → only 4 sent to LLM prompt

# Step 3: LLM generates SQL (Phi3 Mini via Ollama)
SELECT pr.name, SUM(p.finished_output_kg) ...

# Step 4: SQLAlchemy executes query on your database
# Step 5: LLM explains the result in plain English
# Step 6: Plotly auto-generates a chart if data is numeric

Tech stack

All dependencies are free and open source.

ComponentToolPurpose
LLMOllama (Phi3 Mini / Mistral 7B)Natural language to SQL, result explanation
DatabaseSQLAlchemySupports SQLite (demo) and SQL Server (production)
Vector SearchChromaDB + sentence-transformersPDF document search (RAG)
UIStreamlitDashboard, chat, charts
ChartsPlotlyInteractive production and waste visualisation
DataPandasExcel/CSV analysis
ConfigYAMLSchema registry for mapping table names

Schema Registry

How it handles large databases (100+ tables).

The LLM cannot hold 147 table definitions in its prompt. The schema registry maps business domains to specific tables. When you ask about "orders", only order-related tables are sent to the LLM — not all 147.

# schema.yaml — map your actual table names
traceability:
  tables:
    ProductionBatch: BatchID, BatchNo, ProductCode, ProductionDate
    RawMaterialIntake: IntakeID, ProductCode, BatchNo, SupplierCode
    Products: ProductCode, ProductName, Species, Allergens
    SalesOrders: OrderID, CustomerCode, QuantityKg, DeliveryDate

# 7 domains: traceability, production, orders, temperature, staff, stock, compliance
# Each domain maps to 2-5 tables instead of 147

Tests

36 pytest tests. All passing.

$ python -m pytest tests/test_core.py -v

tests/test_core.py::TestConfig::test_config_loads PASSED
tests/test_core.py::TestSQLDialect::test_days_ago_sqlite PASSED
tests/test_core.py::TestSchemaRegistry::test_detect_domain_traceability PASSED
tests/test_core.py::TestDatabase::test_query_returns_dataframe PASSED
tests/test_core.py::TestCompliance::test_trace_batch_returns_dict PASSED
tests/test_core.py::TestAlerts::test_check_all_alerts_returns_list PASSED
tests/test_core.py::TestWastePredictor::test_predict_waste PASSED
tests/test_core.py::TestSQLAgentSafety::test_blocks_insert PASSED
tests/test_core.py::TestDocSearch::test_search_returns_list PASSED
... 27 more tests

36 passed, 0 failed

Setup

Requires Python 3.11+ and Ollama.

# 1. Install Ollama from https://ollama.com
ollama pull phi3:mini

# 2. Clone and install
git clone https://github.com/Pawansingh3889/OpsMind.git
cd OpsMind
pip install -r requirements.txt

# 3. Create demo database (662 production runs, 451 orders, 3600 temp logs)
python scripts/seed_demo_db.py
python scripts/ingest_documents.py

# 4. Run
streamlit run app.py

# 5. Connect to SQL Server (optional)
# Set environment variable:
OPSMIND_DB=mssql+pyodbc://user:pass@server/database?driver=ODBC+Driver+17+for+SQL+Server

Known limitations

LLM accuracyPhi3 Mini generates incorrect SQL for complex queries. Pre-built query library handles the 10 most common questions reliably.
Response time10-25 seconds per query on 16GB RAM. The LLM is the bottleneck, not the database.
No authenticationStreamlit app has no login system. Intended for single-user or trusted network use.
Read-onlyOnly SELECT queries are allowed. Cannot write to or modify the database.
Demo dataShips with synthetic data. Not tested on production databases yet.

Project structure

OpsMind/
├── app.py                      # Streamlit app (7 tabs)
├── config.py                   # Configuration
├── schema.yaml                 # Table mapping for large databases
├── modules/
│   ├── sql_agent.py            # NL to SQL + pre-built query library
│   ├── query_library.py        # 10 tested SQL patterns
│   ├── schema_registry.py      # Domain-to-table mapping
│   ├── sql_dialect.py          # SQLite/SQL Server abstraction
│   ├── database.py             # SQLAlchemy connection layer
│   ├── doc_search.py           # ChromaDB RAG
│   ├── compliance.py           # Traceability, allergens, audit
│   ├── alerts.py               # Anomaly detection (5 alert types)
│   ├── waste_predictor.py      # Yield trends, waste analysis
│   └── llm.py                  # Ollama connection
├── tests/
│   └── test_core.py            # 36 pytest tests
├── scripts/
│   ├── seed_demo_db.py         # Demo database generator
│   └── ingest_documents.py     # Sample document loader
└── requirements.txt