docuquery 0.1.0__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.
- docuquery-0.1.0/LICENSE +21 -0
- docuquery-0.1.0/PKG-INFO +392 -0
- docuquery-0.1.0/README.md +366 -0
- docuquery-0.1.0/docuquery/__init__.py +3 -0
- docuquery-0.1.0/docuquery/chunker.py +87 -0
- docuquery-0.1.0/docuquery/constants.py +67 -0
- docuquery-0.1.0/docuquery/database.py +385 -0
- docuquery-0.1.0/docuquery/ingest.py +52 -0
- docuquery-0.1.0/docuquery/main.py +157 -0
- docuquery-0.1.0/docuquery/rag.py +279 -0
- docuquery-0.1.0/docuquery/tools.py +118 -0
- docuquery-0.1.0/docuquery/utils.py +121 -0
- docuquery-0.1.0/pyproject.toml +104 -0
docuquery-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 John Nnamani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
docuquery-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docuquery
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A local file RAG engine CLI tool
|
|
5
|
+
Keywords: rag,cli,pdf,pgvector,openai,documents,search
|
|
6
|
+
Author: John Nnamani
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: click>=8.5.0
|
|
18
|
+
Requires-Dist: openai>=3.40.0
|
|
19
|
+
Requires-Dist: pgvector>=0.5.1
|
|
20
|
+
Requires-Dist: psycopg[binary]>=3.3.6
|
|
21
|
+
Requires-Dist: pypdf>=6.21.4
|
|
22
|
+
Requires-Dist: sentence-transformers>=6.2.0
|
|
23
|
+
Project-URL: Homepage, https://github.com/nnamanikester/docuquery
|
|
24
|
+
Project-URL: Issues, https://github.com/nnamanikester/docuquery/issues
|
|
25
|
+
|
|
26
|
+
# DocuQuery
|
|
27
|
+
|
|
28
|
+
**Ask questions about your documents from the terminal.**
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/docuquery/)
|
|
31
|
+
[](https://pypi.org/project/docuquery/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
DocuQuery reads your PDF and text files and keeps their text in a PostgreSQL database.
|
|
35
|
+
You ask a question in plain language. An OpenAI model finds the related text and writes the answer.
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
$ docuquery ingest lease.pdf
|
|
39
|
+
[+] Successfully indexed lease.pdf!
|
|
40
|
+
|
|
41
|
+
$ docuquery ask "When does my lease end?"
|
|
42
|
+
Answer: Your lease ends on 31 August 2027.
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Contents
|
|
46
|
+
|
|
47
|
+
1. [Quick start](#1-quick-start)
|
|
48
|
+
2. [Install](#2-install)
|
|
49
|
+
3. [Set up the database](#3-set-up-the-database)
|
|
50
|
+
4. [Configure](#4-configure)
|
|
51
|
+
5. [Add documents](#5-add-documents)
|
|
52
|
+
6. [Ask questions](#6-ask-questions)
|
|
53
|
+
7. [Sessions](#7-sessions)
|
|
54
|
+
8. [Commands](#8-commands)
|
|
55
|
+
9. [Problems and solutions](#9-problems-and-solutions)
|
|
56
|
+
10. [Privacy](#10-privacy)
|
|
57
|
+
11. [License](#11-license)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 1. Quick start
|
|
62
|
+
|
|
63
|
+
You need Docker and an [OpenAI API key](https://platform.openai.com/api-keys).
|
|
64
|
+
|
|
65
|
+
1. Install DocuQuery:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv tool install docuquery
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. Start a PostgreSQL database with pgvector:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
docker run -d --name docuquery-db --restart unless-stopped \
|
|
75
|
+
-e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=docuquery_db \
|
|
76
|
+
-p 5432:5432 -v docuquery-data:/var/lib/postgresql/data \
|
|
77
|
+
pgvector/pgvector:pg17
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
3. Set your settings:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export DOCUQUERY_POSTGRES_URL="postgresql://postgres:postgres@localhost:5432/docuquery_db"
|
|
84
|
+
export OPENAI_API_KEY="sk-your-key"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
4. Prepare the database:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
docuquery init
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
5. Add a document:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
docuquery ingest ~/Documents/report.pdf
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
6. Ask a question:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
docuquery ask "What are the main points in the report?"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
> **NOTE:** The first time DocuQuery adds a document or searches your documents, it downloads a small embedding model (approximately 90 MB). This occurs one time only.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 2. Install
|
|
110
|
+
|
|
111
|
+
DocuQuery needs Python 3.12 or later. Use one of these commands:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
uv tool install docuquery # recommended
|
|
115
|
+
pipx install docuquery
|
|
116
|
+
pip install docuquery
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If you do not have uv, read the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).
|
|
120
|
+
|
|
121
|
+
To make sure that the installation is correct, run:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
docuquery --help
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If the shell cannot find `docuquery`, run `uv tool update-shell` (or `pipx ensurepath`). Then open a new terminal.
|
|
128
|
+
|
|
129
|
+
> **NOTE:** If you install with `pip` on Linux and you do not have an NVIDIA GPU, install the CPU version of PyTorch first. This makes the download much smaller:
|
|
130
|
+
>
|
|
131
|
+
> ```bash
|
|
132
|
+
> pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
133
|
+
> pip install docuquery
|
|
134
|
+
> ```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 3. Set up the database
|
|
139
|
+
|
|
140
|
+
DocuQuery needs PostgreSQL 13 or later with the **pgvector** (0.5.0 or later) and **pg_trgm** extensions. Use one of these options.
|
|
141
|
+
|
|
142
|
+
### 3.1 Docker (on your computer)
|
|
143
|
+
|
|
144
|
+
1. Make a file with the name `docker-compose.yml`. Put this text in the file:
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
services:
|
|
148
|
+
postgres:
|
|
149
|
+
image: pgvector/pgvector:pg17
|
|
150
|
+
restart: unless-stopped
|
|
151
|
+
environment:
|
|
152
|
+
POSTGRES_USER: postgres
|
|
153
|
+
POSTGRES_PASSWORD: postgres
|
|
154
|
+
POSTGRES_DB: docuquery_db
|
|
155
|
+
ports:
|
|
156
|
+
- "5432:5432"
|
|
157
|
+
volumes:
|
|
158
|
+
- pgdata:/var/lib/postgresql/data
|
|
159
|
+
|
|
160
|
+
volumes:
|
|
161
|
+
pgdata:
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
2. In the same folder, start the database:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
docker compose up -d
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Your connection URL is:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
postgresql://postgres:postgres@localhost:5432/docuquery_db
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
> **NOTE:** If port 5432 is already in use, change `"5432:5432"` to `"5433:5432"`. Then use port `5433` in the URL.
|
|
177
|
+
|
|
178
|
+
### 3.2 Hosted database (online)
|
|
179
|
+
|
|
180
|
+
These providers supply PostgreSQL with pgvector. Many have a free plan.
|
|
181
|
+
|
|
182
|
+
| Provider | Where to find the connection URL |
|
|
183
|
+
|---|---|
|
|
184
|
+
| [Neon](https://neon.tech) | Project dashboard > **Connect** |
|
|
185
|
+
| [Supabase](https://supabase.com) | Project > **Connect** > **Session pooler** |
|
|
186
|
+
| AWS RDS, Google Cloud SQL, Azure | Use PostgreSQL 16 or later. On Azure, allow `VECTOR` and `PG_TRGM` in `azure.extensions`. |
|
|
187
|
+
|
|
188
|
+
If the URL does not contain `sslmode`, add `?sslmode=require` to the end.
|
|
189
|
+
|
|
190
|
+
> **NOTE:** `docuquery init` creates the `vector` and `pg_trgm` extensions. The database user must have permission to create extensions. On hosted providers, the default admin user usually has this permission.
|
|
191
|
+
|
|
192
|
+
### 3.3 Connection URL format
|
|
193
|
+
|
|
194
|
+
```text
|
|
195
|
+
postgresql://USER:PASSWORD@HOST:PORT/DATABASE
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
If the password has special characters, encode them. For example, `@` becomes `%40`.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 4. Configure
|
|
203
|
+
|
|
204
|
+
### 4.1 Settings
|
|
205
|
+
|
|
206
|
+
DocuQuery reads its settings from a config file and from environment variables.
|
|
207
|
+
|
|
208
|
+
| Variable | Required | Default |
|
|
209
|
+
|---|---|---|
|
|
210
|
+
| `DOCUQUERY_POSTGRES_URL` | Yes | `postgresql://postgres:postgres@localhost:5432/docuquery_db` |
|
|
211
|
+
| `OPENAI_API_KEY` | Yes | — |
|
|
212
|
+
| `DOCUQUERY_OPENAI_MODEL` | No | `gpt-5.4-mini` |
|
|
213
|
+
| `SENTENCE_TRANSFORMER_MODEL` | No | `sentence-transformers/all-MiniLM-L6-v2` |
|
|
214
|
+
| `DOCUQUERY_CHUNK_SIZE` | No | `512` (characters) |
|
|
215
|
+
| `DOCUQUERY_OVERLAP` | No | `50` (characters) |
|
|
216
|
+
|
|
217
|
+
If a setting is not set, DocuQuery asks for it one time. For an optional setting, push **Enter** to use the default.
|
|
218
|
+
|
|
219
|
+
DocuQuery saves your answers in a config file:
|
|
220
|
+
|
|
221
|
+
| System | Config file |
|
|
222
|
+
|---|---|
|
|
223
|
+
| macOS | `~/Library/Application Support/docuquery/config.env` |
|
|
224
|
+
| Linux | `~/.config/docuquery/config.env` |
|
|
225
|
+
| Windows | `%APPDATA%\docuquery\config.env` |
|
|
226
|
+
|
|
227
|
+
To change a saved setting, edit this file. The file contains your API key. On macOS and Linux, DocuQuery makes the file readable only by you.
|
|
228
|
+
|
|
229
|
+
### 4.2 Keep the settings
|
|
230
|
+
|
|
231
|
+
You can also set the settings as environment variables. Add them to your shell file. For zsh, the file is `~/.zshrc`. For bash, the file is `~/.bashrc`.
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
export DOCUQUERY_POSTGRES_URL="postgresql://postgres:postgres@localhost:5432/docuquery_db"
|
|
235
|
+
export OPENAI_API_KEY="sk-your-key"
|
|
236
|
+
export DOCUQUERY_OPENAI_MODEL="gpt-5.4-mini"
|
|
237
|
+
export SENTENCE_TRANSFORMER_MODEL="sentence-transformers/all-MiniLM-L6-v2"
|
|
238
|
+
export DOCUQUERY_CHUNK_SIZE="512"
|
|
239
|
+
export DOCUQUERY_OVERLAP="50"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Then open a new terminal. On Windows, use `setx NAME "value"` for each setting.
|
|
243
|
+
|
|
244
|
+
An environment variable has priority over the config file.
|
|
245
|
+
|
|
246
|
+
> **CAUTION:** Do not put your API key in a Git repository.
|
|
247
|
+
|
|
248
|
+
> **CAUTION:** Use only an embedding model that makes 384 dimensions. If you change the embedding model, add your documents again.
|
|
249
|
+
|
|
250
|
+
### 4.3 Prepare the database
|
|
251
|
+
|
|
252
|
+
Do this one time for each new database:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
docuquery init
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
You see `✔ Database initialized successfully.` It is safe to run this command again.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 5. Add documents
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
docuquery ingest path/to/file.pdf
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
DocuQuery reads **PDF files** and **UTF-8 text files** (`.txt`, `.md`, `.csv`, and source code). For a Word file, save it as PDF first.
|
|
269
|
+
|
|
270
|
+
To add all the PDF files in a folder:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
for f in ~/Documents/*.pdf; do docuquery ingest "$f"; done
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
If you add a file with the same name again, DocuQuery replaces the old copy. This also occurs for two different files that have the same name.
|
|
277
|
+
|
|
278
|
+
> **NOTE:** A scanned PDF contains only images. DocuQuery cannot read it. Use an OCR tool, for example [OCRmyPDF](https://ocrmypdf.readthedocs.io/), first.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 6. Ask questions
|
|
283
|
+
|
|
284
|
+
Start a conversation with a question:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
docuquery ask "What is the cancellation policy?"
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
After each answer, type your next question. The model remembers the conversation.
|
|
291
|
+
|
|
292
|
+
```text
|
|
293
|
+
$ docuquery ask "Which documents mention a deposit?"
|
|
294
|
+
Answer: lease.pdf and booking.pdf mention a deposit.
|
|
295
|
+
|
|
296
|
+
You: How much is the deposit in the lease?
|
|
297
|
+
Answer: The deposit is 1,200 EUR.
|
|
298
|
+
|
|
299
|
+
You: exit
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
To stop, type `exit` or push **Ctrl+D**.
|
|
303
|
+
|
|
304
|
+
### Examples of questions
|
|
305
|
+
|
|
306
|
+
- "What is the due date on the March invoice?"
|
|
307
|
+
- "Give me a summary of the project plan in 5 points."
|
|
308
|
+
- "Compare the salaries in the two job offers."
|
|
309
|
+
- "Which documents do I have?"
|
|
310
|
+
- "What did we talk about in my last session?"
|
|
311
|
+
|
|
312
|
+
### Get better answers
|
|
313
|
+
|
|
314
|
+
- Be specific. "What is the notice period in the lease?" is better than "Tell me about notice".
|
|
315
|
+
- If you know the document, say its name.
|
|
316
|
+
- Ask one thing at a time.
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## 7. Sessions
|
|
321
|
+
|
|
322
|
+
DocuQuery saves each conversation after each answer.
|
|
323
|
+
|
|
324
|
+
Show your 20 most recent sessions:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
docuquery sessions
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Continue a session:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
docuquery resume 3f6c2a1e-8d4b-4c1a-9e2f-7b5d0a9c1e33
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## 8. Commands
|
|
339
|
+
|
|
340
|
+
| Command | What it does |
|
|
341
|
+
|---|---|
|
|
342
|
+
| `docuquery init` | Prepares the database. |
|
|
343
|
+
| `docuquery ingest FILE_PATH` | Adds a document. |
|
|
344
|
+
| `docuquery ask [QUESTION]` | Starts a conversation. |
|
|
345
|
+
| `docuquery ask --session-id ID` | Continues a session. |
|
|
346
|
+
| `docuquery sessions` | Shows your sessions. |
|
|
347
|
+
| `docuquery resume SESSION_ID` | Continues a session. |
|
|
348
|
+
|
|
349
|
+
Run `docuquery COMMAND --help` for more information.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 9. Problems and solutions
|
|
354
|
+
|
|
355
|
+
| Problem | Solution |
|
|
356
|
+
|---|---|
|
|
357
|
+
| `docuquery: command not found` | Run `uv tool update-shell`. Then open a new terminal. |
|
|
358
|
+
| A setting is incorrect. | Edit the config file (read [4.1](#41-settings)), or set the environment variable (read [4.2](#42-keep-the-settings)). |
|
|
359
|
+
| `connection refused` | Start the database. Make sure that the host and port in the URL are correct. |
|
|
360
|
+
| `password authentication failed` | Correct the user and password in the URL. |
|
|
361
|
+
| `SSL connection is required` | Add `?sslmode=require` to the end of the URL. |
|
|
362
|
+
| `extension "vector" is not available` | Use the `pgvector/pgvector` Docker image, or a provider that supports pgvector. |
|
|
363
|
+
| `relation "document_chunks" does not exist` | Run `docuquery init`. |
|
|
364
|
+
| `port is already allocated` | Use port 5433. Read [3.1](#31-docker-on-your-computer). |
|
|
365
|
+
| `401` or `Incorrect API key` | Make a new key at <https://platform.openai.com/api-keys>. |
|
|
366
|
+
| `429` or `insufficient_quota` | Add credit to your OpenAI account. |
|
|
367
|
+
| `is not a PDF or a UTF-8 text file` | The file type is not supported. Save it as PDF. |
|
|
368
|
+
| `has no text` | The file is empty, or it is a scanned PDF. Use OCR first. |
|
|
369
|
+
| `[Stopped: reached max tool-call turns]` | The model needed more than 3 rounds of searches. Ask a more specific question. |
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## 10. Privacy
|
|
374
|
+
|
|
375
|
+
Your documents stay in your database. The embeddings are made on your computer.
|
|
376
|
+
|
|
377
|
+
When you ask a question, DocuQuery sends these items to OpenAI:
|
|
378
|
+
|
|
379
|
+
- Your question and the previous messages in the conversation.
|
|
380
|
+
- The parts of your documents that are related to the question.
|
|
381
|
+
- The names of your documents, and messages from your past sessions, if the model asks for them.
|
|
382
|
+
|
|
383
|
+
> **CAUTION:** Do not add documents that you cannot share with OpenAI.
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 11. License
|
|
388
|
+
|
|
389
|
+
DocuQuery is available under the MIT License. Read the `LICENSE` file.
|
|
390
|
+
|
|
391
|
+
To help develop DocuQuery, read the [contributing guide](https://github.com/nnamanikester/docuquery/blob/main/CONTRIBUTING.md).
|
|
392
|
+
|