contextsql-garvit 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {contextsql_garvit-0.1.0/contextsql_garvit.egg-info → contextsql_garvit-0.1.2}/PKG-INFO +8 -1
- contextsql_garvit-0.1.0/PKG-INFO → contextsql_garvit-0.1.2/README.md +7 -13
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/cli.py +9 -0
- contextsql_garvit-0.1.0/README.md → contextsql_garvit-0.1.2/contextsql_garvit.egg-info/PKG-INFO +423 -403
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/pyproject.toml +1 -1
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/__init__.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/agent.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/autoglossary.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/config.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/db.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/feedback.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/glossary.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/hints.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/introspect.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/learn.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/names.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/phrasing.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/prompt.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql/retrieve.py +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/SOURCES.txt +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/dependency_links.txt +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/entry_points.txt +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/requires.txt +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/top_level.txt +0 -0
- {contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: contextsql_garvit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Local, free, business-context-aware text-to-SQL agent
|
|
5
5
|
Requires-Python: >=3.9
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -11,6 +11,13 @@ Requires-Dist: llama-cpp-python
|
|
|
11
11
|
Provides-Extra: postgres
|
|
12
12
|
Requires-Dist: psycopg2-binary; extra == "postgres"
|
|
13
13
|
|
|
14
|
+
Windows users: if pip install contextsql fails while building llama-cpp-python, they should first run:
|
|
15
|
+
|
|
16
|
+
pip install llama-cpp-python --prefer-binary --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
|
17
|
+
|
|
18
|
+
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
|
|
19
|
+
pypi-AgEIcHlwaS5vcmcCJDNmNDYwOWQwLWNhZWQtNDkyZC1hMjUxLThiMTc2MGVkYTAwMgACKlszLCIxOTVhZjFmYy1kMjhlLTQwOTgtYjI1NS00NmQ2MzFmNjAzNmUiXQAABiB8KDxlQkkM9TV1GxvJLmr-dA_MLLgTtMYbkyN-UDsv0Q
|
|
20
|
+
|
|
14
21
|
# contextsql
|
|
15
22
|
|
|
16
23
|
Ask your database questions in plain English. **Local, free and private**: the model runs on your own machine, and your data is never sent to any cloud service.
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Requires-Dist: sqlalchemy>=2.0
|
|
8
|
-
Requires-Dist: pymysql>=1.1
|
|
9
|
-
Requires-Dist: huggingface_hub>=0.20
|
|
10
|
-
Requires-Dist: llama-cpp-python
|
|
11
|
-
Provides-Extra: postgres
|
|
12
|
-
Requires-Dist: psycopg2-binary; extra == "postgres"
|
|
1
|
+
Windows users: if pip install contextsql fails while building llama-cpp-python, they should first run:
|
|
2
|
+
|
|
3
|
+
pip install llama-cpp-python --prefer-binary --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
|
4
|
+
|
|
5
|
+
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
|
|
6
|
+
pypi-AgEIcHlwaS5vcmcCJDNmNDYwOWQwLWNhZWQtNDkyZC1hMjUxLThiMTc2MGVkYTAwMgACKlszLCIxOTVhZjFmYy1kMjhlLTQwOTgtYjI1NS00NmQ2MzFmNjAzNmUiXQAABiB8KDxlQkkM9TV1GxvJLmr-dA_MLLgTtMYbkyN-UDsv0Q
|
|
13
7
|
|
|
14
8
|
# contextsql
|
|
15
9
|
|
|
@@ -413,4 +407,4 @@ contextsql glossary remove "term"
|
|
|
413
407
|
contextsql good # last answer was right
|
|
414
408
|
contextsql fix "SELECT ..." # last answer was wrong
|
|
415
409
|
contextsql status
|
|
416
|
-
```
|
|
410
|
+
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""contextsql connect | learn | ask | glossary | status"""
|
|
2
|
+
import shlex
|
|
2
3
|
import argparse, getpass, json, os, sys
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from . import glossary as gl
|
|
@@ -92,6 +93,14 @@ def cmd_ask(a):
|
|
|
92
93
|
while True:
|
|
93
94
|
q = input("\n> ").strip()
|
|
94
95
|
if not q: break
|
|
96
|
+
if q.lower() in ("cls", "clear", "/cls", "/clear"):
|
|
97
|
+
os.system("cls" if os.name == "nt" else "clear"); continue
|
|
98
|
+
if q.startswith("/") or q.startswith("contextsql "):
|
|
99
|
+
try:
|
|
100
|
+
main(shlex.split(q[1:] if q.startswith("/") else q[11:]))
|
|
101
|
+
except SystemExit as e:
|
|
102
|
+
print(e.code if isinstance(e.code, str) else "")
|
|
103
|
+
continue
|
|
95
104
|
show(agent.ask(q))
|
|
96
105
|
|
|
97
106
|
def cmd_glossary(a):
|
contextsql_garvit-0.1.0/README.md → contextsql_garvit-0.1.2/contextsql_garvit.egg-info/PKG-INFO
RENAMED
|
@@ -1,403 +1,423 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
contextsql
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
### `contextsql
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
|
182
|
-
|
|
183
|
-
| `
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
### `contextsql
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
contextsql
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
contextsql
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
contextsql
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
- **
|
|
322
|
-
- **
|
|
323
|
-
- **
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: contextsql_garvit
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Local, free, business-context-aware text-to-SQL agent
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
8
|
+
Requires-Dist: pymysql>=1.1
|
|
9
|
+
Requires-Dist: huggingface_hub>=0.20
|
|
10
|
+
Requires-Dist: llama-cpp-python
|
|
11
|
+
Provides-Extra: postgres
|
|
12
|
+
Requires-Dist: psycopg2-binary; extra == "postgres"
|
|
13
|
+
|
|
14
|
+
Windows users: if pip install contextsql fails while building llama-cpp-python, they should first run:
|
|
15
|
+
|
|
16
|
+
pip install llama-cpp-python --prefer-binary --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
|
17
|
+
|
|
18
|
+
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
|
|
19
|
+
pypi-AgEIcHlwaS5vcmcCJDNmNDYwOWQwLWNhZWQtNDkyZC1hMjUxLThiMTc2MGVkYTAwMgACKlszLCIxOTVhZjFmYy1kMjhlLTQwOTgtYjI1NS00NmQ2MzFmNjAzNmUiXQAABiB8KDxlQkkM9TV1GxvJLmr-dA_MLLgTtMYbkyN-UDsv0Q
|
|
20
|
+
|
|
21
|
+
# contextsql
|
|
22
|
+
|
|
23
|
+
Ask your database questions in plain English. **Local, free and private**: the model runs on your own machine, and your data is never sent to any cloud service.
|
|
24
|
+
|
|
25
|
+
contextsql first *learns* your database (tables, columns, value patterns, business terms). When you ask a question, it picks the relevant tables, writes the SQL, runs it, and shows the result.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
$ contextsql ask "top 5 customers by total payments"
|
|
29
|
+
|
|
30
|
+
SQL (1 attempt, 4210 ms; tables: payments, customers, orders):
|
|
31
|
+
SELECT ... LIMIT 5;
|
|
32
|
+
|
|
33
|
+
name total
|
|
34
|
+
------------ --------
|
|
35
|
+
Customer 482 39984.38
|
|
36
|
+
...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Contents
|
|
42
|
+
|
|
43
|
+
1. [Requirements](#requirements)
|
|
44
|
+
2. [Installation](#installation)
|
|
45
|
+
3. [Quick start](#quick-start)
|
|
46
|
+
4. [Commands](#commands)
|
|
47
|
+
5. [Teaching it your business terms (glossary)](#teaching-it-your-business-terms-glossary)
|
|
48
|
+
6. [Improving answers (good / fix)](#improving-answers-good--fix)
|
|
49
|
+
7. [Using other databases](#using-other-databases)
|
|
50
|
+
8. [Safety](#safety)
|
|
51
|
+
9. [Where files are stored](#where-files-are-stored)
|
|
52
|
+
10. [Tips for better answers](#tips-for-better-answers)
|
|
53
|
+
11. [Troubleshooting](#troubleshooting)
|
|
54
|
+
12. [Updating and uninstalling](#updating-and-uninstalling)
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
| Item | Requirement |
|
|
61
|
+
|------|-------------|
|
|
62
|
+
| Python | 3.9 or newer (**3.10 to 3.12 recommended**, especially on Windows) |
|
|
63
|
+
| Database | MySQL (default), PostgreSQL or SQLite |
|
|
64
|
+
| Disk space | About 2 GB for the model (downloaded once) |
|
|
65
|
+
| RAM | 4 GB free or more |
|
|
66
|
+
| Internet | Needed only for installation and the first model download |
|
|
67
|
+
|
|
68
|
+
No GPU is needed. The model runs on the CPU.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
### 1. Create a virtual environment (recommended)
|
|
75
|
+
|
|
76
|
+
**Windows**
|
|
77
|
+
```
|
|
78
|
+
python -m venv contextsql_env
|
|
79
|
+
contextsql_env\Scripts\activate
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Mac / Linux**
|
|
83
|
+
```
|
|
84
|
+
python3 -m venv contextsql_env
|
|
85
|
+
source contextsql_env/bin/activate
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. Install the model runner first (Windows)
|
|
89
|
+
|
|
90
|
+
On Windows, install the prebuilt `llama-cpp-python` before installing contextsql. This avoids a C++ compiler error (`CMAKE_C_COMPILER not set` / `nmake` failed):
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
pip install llama-cpp-python --prefer-binary --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Mac and Linux users can skip this step.
|
|
97
|
+
|
|
98
|
+
### 3. Install contextsql
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
pip install contextsql
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Check that it works:
|
|
105
|
+
```
|
|
106
|
+
contextsql status
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Optional: PostgreSQL support
|
|
110
|
+
```
|
|
111
|
+
pip install "contextsql[postgres]"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Quick start
|
|
117
|
+
|
|
118
|
+
Three steps: **connect**, **learn**, **ask**.
|
|
119
|
+
|
|
120
|
+
### Step 1: Connect to your database
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
contextsql connect
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
You will be asked for:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Host [127.0.0.1]:
|
|
130
|
+
Port [3306]:
|
|
131
|
+
User:
|
|
132
|
+
Password: (hidden while typing)
|
|
133
|
+
Database name:
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Or pass everything in one line:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
contextsql connect --host 127.0.0.1 --port 3306 --user myuser --password mypass --db mydatabase
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
On the **first** connect, the model (about 1.8 GB) is downloaded from Hugging Face and cached. This happens only once, so it takes a few minutes. After that, everything works offline.
|
|
143
|
+
|
|
144
|
+
### Step 2: Learn your database (one time)
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
contextsql learn
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
contextsql reads your table structure, scans the data and builds notes about your columns and values (for example, which status values exist). It prints a summary like:
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
Done: 4 tables, 12,000 rows scanned, 7 data notes, 10 auto glossary terms, 0 glossary terms imported.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Run `learn` again whenever your tables or data change a lot.
|
|
157
|
+
|
|
158
|
+
### Step 3: Ask questions
|
|
159
|
+
|
|
160
|
+
One question:
|
|
161
|
+
```
|
|
162
|
+
contextsql ask "how many orders were placed last month"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Interactive session (the model loads once, so later questions are faster):
|
|
166
|
+
```
|
|
167
|
+
contextsql ask
|
|
168
|
+
> top 5 customers by revenue
|
|
169
|
+
> average order value per month
|
|
170
|
+
> (press Enter on an empty line to quit)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Commands
|
|
176
|
+
|
|
177
|
+
### `contextsql connect`
|
|
178
|
+
|
|
179
|
+
Saves your database login and downloads the model if needed.
|
|
180
|
+
|
|
181
|
+
| Option | Meaning | Default |
|
|
182
|
+
|--------|---------|---------|
|
|
183
|
+
| `--dialect` | `mysql`, `postgresql` or `sqlite` | `mysql` |
|
|
184
|
+
| `--host` | Server address | `127.0.0.1` |
|
|
185
|
+
| `--port` | Server port | 3306 (MySQL) / 5432 (PostgreSQL) |
|
|
186
|
+
| `--user` | Database user | asked |
|
|
187
|
+
| `--password` | Database password | asked (hidden) |
|
|
188
|
+
| `--db` | Database name (or file path for SQLite) | asked |
|
|
189
|
+
| `--model` | Path to your own `.gguf` model file | auto-download |
|
|
190
|
+
|
|
191
|
+
Run it again at any time to switch databases. The old settings are overwritten. After switching, run `contextsql learn`.
|
|
192
|
+
|
|
193
|
+
### `contextsql learn`
|
|
194
|
+
|
|
195
|
+
Reads and analyzes the connected database. Run it once after `connect`, and again after big schema or data changes.
|
|
196
|
+
|
|
197
|
+
### `contextsql ask`
|
|
198
|
+
|
|
199
|
+
| Usage | What it does |
|
|
200
|
+
|-------|--------------|
|
|
201
|
+
| `contextsql ask "question"` | Answers one question and exits |
|
|
202
|
+
| `contextsql ask` | Starts an interactive session (empty line quits) |
|
|
203
|
+
| `contextsql ask --threads 8 "question"` | Uses 8 CPU threads (default is half your cores) |
|
|
204
|
+
|
|
205
|
+
Every answer shows:
|
|
206
|
+
- the SQL it wrote,
|
|
207
|
+
- how many attempts it needed (it retries automatically if the SQL fails or returns nothing),
|
|
208
|
+
- the tables it used,
|
|
209
|
+
- a **low confidence** warning when it is unsure. Always read the SQL in that case.
|
|
210
|
+
|
|
211
|
+
Results show up to 20 rows on screen.
|
|
212
|
+
|
|
213
|
+
### `contextsql glossary`
|
|
214
|
+
|
|
215
|
+
Manage your business terms. See [the next section](#teaching-it-your-business-terms-glossary).
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
contextsql glossary # list all terms (same as "list")
|
|
219
|
+
contextsql glossary list
|
|
220
|
+
contextsql glossary add "term" "definition" "SQL expression" --tables t1,t2
|
|
221
|
+
contextsql glossary remove "term"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### `contextsql good`
|
|
225
|
+
|
|
226
|
+
Marks the **last answer** as correct. It is saved as an example and reused for similar questions.
|
|
227
|
+
|
|
228
|
+
### `contextsql fix`
|
|
229
|
+
|
|
230
|
+
Replaces the last answer with your corrected SQL:
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
contextsql fix "SELECT COUNT(*) FROM orders WHERE status = 'completed'"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The SQL is checked and test-run first. It is saved only if it runs successfully.
|
|
237
|
+
|
|
238
|
+
### `contextsql status`
|
|
239
|
+
|
|
240
|
+
Shows whether you are connected, which model file is used, how many tables were learned, and how many glossary terms exist.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Teaching it your business terms (glossary)
|
|
245
|
+
|
|
246
|
+
Databases rarely say what *revenue*, *active customer* or *late delivery* mean in your business. The glossary lets you define them once, and contextsql uses the definition every time you ask.
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
contextsql glossary add "revenue" "Sum of quantity times price for completed orders" "SUM(quantity*unit_price)" --tables orders,order_items
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Arguments, in order:
|
|
253
|
+
|
|
254
|
+
1. **term**: the word you will use in questions
|
|
255
|
+
2. **definition**: a plain description
|
|
256
|
+
3. **SQL expression**: how it is calculated
|
|
257
|
+
4. `--tables`: tables the term needs (comma-separated, no spaces)
|
|
258
|
+
|
|
259
|
+
Then:
|
|
260
|
+
```
|
|
261
|
+
contextsql ask "revenue by month"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Other glossary commands:
|
|
265
|
+
```
|
|
266
|
+
contextsql glossary list
|
|
267
|
+
contextsql glossary remove "revenue"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Terms marked `(auto)` in the list were generated automatically during `learn`. Your own terms override them. You do not need to run `learn` again after adding a term.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Improving answers (good / fix)
|
|
275
|
+
|
|
276
|
+
contextsql gets better the more you correct it.
|
|
277
|
+
|
|
278
|
+
1. Ask a question.
|
|
279
|
+
2. If the SQL and result are right, run `contextsql good`.
|
|
280
|
+
3. If they are wrong, run `contextsql fix "your corrected SQL"`.
|
|
281
|
+
|
|
282
|
+
Both commands apply to the **last question you asked**. Saved examples are used for similar questions in the future.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Using other databases
|
|
287
|
+
|
|
288
|
+
### MySQL (default)
|
|
289
|
+
```
|
|
290
|
+
contextsql connect --user myuser --password mypass --db mydatabase
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### PostgreSQL
|
|
294
|
+
```
|
|
295
|
+
pip install "contextsql[postgres]"
|
|
296
|
+
contextsql connect --dialect postgresql --host localhost --port 5432 --user myuser --password mypass --db mydatabase
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### SQLite
|
|
300
|
+
```
|
|
301
|
+
contextsql connect --dialect sqlite --db C:\path\to\file.db
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Remote server
|
|
305
|
+
Use `--host` with the server's IP address or name. Make sure the server allows connections from your machine.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Safety
|
|
310
|
+
|
|
311
|
+
- **Use a read-only database user.** Never connect with an admin account such as `root` on a production database. Example for MySQL:
|
|
312
|
+
|
|
313
|
+
```sql
|
|
314
|
+
CREATE USER 'ctx'@'localhost' IDENTIFIED BY 'a_strong_password';
|
|
315
|
+
GRANT SELECT ON mydatabase.* TO 'ctx'@'localhost';
|
|
316
|
+
FLUSH PRIVILEGES;
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Then connect with `--user ctx`.
|
|
320
|
+
|
|
321
|
+
- **Always read the SQL** before trusting a result, especially when you see the low-confidence warning.
|
|
322
|
+
- **Your login is stored in plain text** in `~/.contextsql/` (see below). This is another reason to use a read-only user.
|
|
323
|
+
- **Your data stays on your machine.** The model runs locally. The only network use is the one-time model download.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Where files are stored
|
|
328
|
+
|
|
329
|
+
| What | Location |
|
|
330
|
+
|------|----------|
|
|
331
|
+
| Your settings, learned data, glossary and saved examples | `.contextsql` folder in your user home (Windows: `C:\Users\<you>\.contextsql`) |
|
|
332
|
+
| Downloaded model | Hugging Face cache (Windows: `C:\Users\<you>\.cache\huggingface\hub`) |
|
|
333
|
+
|
|
334
|
+
**Reset everything:** delete the `.contextsql` folder, then run `connect` and `learn` again.
|
|
335
|
+
**Free disk space:** delete the model folder `models--Garvitarunav--contextsql-v4` inside the Hugging Face cache. It will be re-downloaded when needed.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Tips for better answers
|
|
340
|
+
|
|
341
|
+
- **Run `learn`** after connecting and after major data changes.
|
|
342
|
+
- **Name things the way your tables do.** "orders per customer" works better when the tables are called `orders` and `customers`.
|
|
343
|
+
- **Add glossary terms** for your key metrics (revenue, margin, active user, churn, and so on).
|
|
344
|
+
- **Be specific.** "Top 10 customers by total payments in 2026" is better than "best customers".
|
|
345
|
+
- **Check date questions.** Phrases like "last month" are supported; others ("last 7 days", "year to date") may need a check. Read the SQL.
|
|
346
|
+
- **Use `good` and `fix`** so it learns your preferred answers.
|
|
347
|
+
- **Speed:** use the interactive `contextsql ask` session so the model loads once. Try `--threads` with your CPU core count.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Troubleshooting
|
|
352
|
+
|
|
353
|
+
### `Failed building wheel for llama-cpp-python` / `CMAKE_C_COMPILER not set`
|
|
354
|
+
No prebuilt wheel was found, and Windows has no C++ compiler. Run this first, then install contextsql:
|
|
355
|
+
```
|
|
356
|
+
pip install llama-cpp-python --prefer-binary --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
|
357
|
+
pip install contextsql
|
|
358
|
+
```
|
|
359
|
+
If it still tries to build, check `python --version`. Prebuilt wheels exist for Python 3.10 to 3.12.
|
|
360
|
+
|
|
361
|
+
### `Could not connect: (1045, "Access denied for user ...")`
|
|
362
|
+
The username or password is wrong, or you pressed Enter at the prompts and left them empty. Test your login outside contextsql:
|
|
363
|
+
```
|
|
364
|
+
mysql -u myuser -p
|
|
365
|
+
```
|
|
366
|
+
Then run `contextsql connect` with the same user and password. Also check that the user has access to the database (`GRANT SELECT ON mydatabase.* TO 'myuser'@'localhost';`).
|
|
367
|
+
|
|
368
|
+
### `Could not connect: (2003, "Can't connect to MySQL server")`
|
|
369
|
+
The host or port is wrong, or the server is not running or does not allow your machine to connect.
|
|
370
|
+
|
|
371
|
+
### `Not ready yet - run: contextsql connect` or `contextsql learn`
|
|
372
|
+
You skipped a step. Run `connect`, then `learn`, then `ask`.
|
|
373
|
+
|
|
374
|
+
### Model download fails or is interrupted
|
|
375
|
+
Check your internet connection and free disk space (about 2 GB), then run `contextsql connect` again. A partial download resumes automatically.
|
|
376
|
+
|
|
377
|
+
### Answers are wrong or "low confidence"
|
|
378
|
+
1. Read the SQL shown.
|
|
379
|
+
2. Rephrase with exact table or column names.
|
|
380
|
+
3. Add a glossary term for the concept.
|
|
381
|
+
4. Use `contextsql fix "correct SQL"` to teach it.
|
|
382
|
+
5. Run `contextsql learn` again if your data has changed.
|
|
383
|
+
|
|
384
|
+
### It is slow
|
|
385
|
+
- Use the interactive `contextsql ask` session, so the model loads only once.
|
|
386
|
+
- Close other heavy programs and use `--threads <number of CPU cores>`.
|
|
387
|
+
- The first question after loading the model is always slower than later ones.
|
|
388
|
+
|
|
389
|
+
### Everything seems stuck on an old database
|
|
390
|
+
Settings are shared per user. Run `contextsql status` to see what you are connected to. To start fresh, delete the `.contextsql` folder.
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## Updating and uninstalling
|
|
395
|
+
|
|
396
|
+
**Update**
|
|
397
|
+
```
|
|
398
|
+
pip install --upgrade contextsql
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Uninstall**
|
|
402
|
+
```
|
|
403
|
+
pip uninstall contextsql
|
|
404
|
+
```
|
|
405
|
+
Then optionally delete the `.contextsql` folder and the Hugging Face model cache (see [Where files are stored](#where-files-are-stored)).
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Command cheat sheet
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
pip install contextsql
|
|
413
|
+
contextsql connect --user USER --password PASS --db DBNAME
|
|
414
|
+
contextsql learn
|
|
415
|
+
contextsql ask "your question"
|
|
416
|
+
contextsql ask # interactive session
|
|
417
|
+
contextsql glossary add "term" "definition" "SQL" --tables t1,t2
|
|
418
|
+
contextsql glossary list
|
|
419
|
+
contextsql glossary remove "term"
|
|
420
|
+
contextsql good # last answer was right
|
|
421
|
+
contextsql fix "SELECT ..." # last answer was wrong
|
|
422
|
+
contextsql status
|
|
423
|
+
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{contextsql_garvit-0.1.0 → contextsql_garvit-0.1.2}/contextsql_garvit.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|