docsonar 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.
- docsonar-0.1.0/.github/workflows/ci.yml +59 -0
- docsonar-0.1.0/.gitignore +25 -0
- docsonar-0.1.0/.mcp.json +8 -0
- docsonar-0.1.0/.vscode/launch.json +52 -0
- docsonar-0.1.0/.vscode/settings.json +5 -0
- docsonar-0.1.0/LICENSE +21 -0
- docsonar-0.1.0/PKG-INFO +242 -0
- docsonar-0.1.0/README.md +213 -0
- docsonar-0.1.0/examples/sample-docs/espresso-guide.md +23 -0
- docsonar-0.1.0/examples/sample-docs/expense-policy.pdf +54 -0
- docsonar-0.1.0/examples/sample-docs/kubernetes-basics.md +22 -0
- docsonar-0.1.0/examples/sample-docs/onboarding-checklist.docx +0 -0
- docsonar-0.1.0/examples/sample-docs/project-meeting-notes.txt +14 -0
- docsonar-0.1.0/examples/sample-docs/sourdough-notes.txt +14 -0
- docsonar-0.1.0/examples/sample-docs/tea-brewing.html +17 -0
- docsonar-0.1.0/pyproject.toml +70 -0
- docsonar-0.1.0/scripts/benchmark.py +123 -0
- docsonar-0.1.0/server.json +22 -0
- docsonar-0.1.0/src/docsonar/__init__.py +3 -0
- docsonar-0.1.0/src/docsonar/__main__.py +6 -0
- docsonar-0.1.0/src/docsonar/chunking.py +234 -0
- docsonar-0.1.0/src/docsonar/cli.py +48 -0
- docsonar-0.1.0/src/docsonar/config.py +120 -0
- docsonar-0.1.0/src/docsonar/db.py +162 -0
- docsonar-0.1.0/src/docsonar/embeddings.py +108 -0
- docsonar-0.1.0/src/docsonar/indexer.py +392 -0
- docsonar-0.1.0/src/docsonar/parsers/__init__.py +44 -0
- docsonar-0.1.0/src/docsonar/parsers/base.py +49 -0
- docsonar-0.1.0/src/docsonar/parsers/docx.py +59 -0
- docsonar-0.1.0/src/docsonar/parsers/html.py +85 -0
- docsonar-0.1.0/src/docsonar/parsers/markdown.py +86 -0
- docsonar-0.1.0/src/docsonar/parsers/pdf.py +45 -0
- docsonar-0.1.0/src/docsonar/parsers/text.py +24 -0
- docsonar-0.1.0/src/docsonar/py.typed +0 -0
- docsonar-0.1.0/src/docsonar/search.py +348 -0
- docsonar-0.1.0/src/docsonar/security.py +53 -0
- docsonar-0.1.0/src/docsonar/server.py +434 -0
- docsonar-0.1.0/src/docsonar/worker.py +147 -0
- docsonar-0.1.0/tests/conftest.py +24 -0
- docsonar-0.1.0/tests/fixtures/sample.html +21 -0
- docsonar-0.1.0/tests/fixtures/sample.md +26 -0
- docsonar-0.1.0/tests/fixtures/sample.txt +8 -0
- docsonar-0.1.0/tests/pdf_fixture.py +47 -0
- docsonar-0.1.0/tests/test_chunking.py +105 -0
- docsonar-0.1.0/tests/test_config.py +56 -0
- docsonar-0.1.0/tests/test_hybrid.py +156 -0
- docsonar-0.1.0/tests/test_incremental.py +142 -0
- docsonar-0.1.0/tests/test_parsers.py +52 -0
- docsonar-0.1.0/tests/test_parsers_rich.py +93 -0
- docsonar-0.1.0/tests/test_search.py +89 -0
- docsonar-0.1.0/tests/test_security.py +77 -0
- docsonar-0.1.0/uv.lock +2330 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
enable-cache: true
|
|
21
|
+
- run: uv sync --dev
|
|
22
|
+
- name: ruff
|
|
23
|
+
run: uv run ruff check .
|
|
24
|
+
- name: mypy
|
|
25
|
+
run: uv run mypy src tests
|
|
26
|
+
|
|
27
|
+
test:
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
include:
|
|
32
|
+
# Full Python matrix on Linux; latest-stable spot checks on macOS/Windows.
|
|
33
|
+
- { os: ubuntu-latest, python: "3.11" }
|
|
34
|
+
- { os: ubuntu-latest, python: "3.12" }
|
|
35
|
+
- { os: ubuntu-latest, python: "3.13" }
|
|
36
|
+
- { os: macos-latest, python: "3.12" }
|
|
37
|
+
- { os: windows-latest, python: "3.12" }
|
|
38
|
+
runs-on: ${{ matrix.os }}
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: astral-sh/setup-uv@v5
|
|
42
|
+
with:
|
|
43
|
+
python-version: ${{ matrix.python }}
|
|
44
|
+
enable-cache: true
|
|
45
|
+
- run: uv sync --dev
|
|
46
|
+
- name: pytest
|
|
47
|
+
run: uv run pytest
|
|
48
|
+
|
|
49
|
+
build:
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v4
|
|
53
|
+
- uses: astral-sh/setup-uv@v5
|
|
54
|
+
with:
|
|
55
|
+
python-version: "3.12"
|
|
56
|
+
- name: Build sdist and wheel
|
|
57
|
+
run: uv build
|
|
58
|
+
- name: Smoke-test the wheel
|
|
59
|
+
run: uv run --isolated --no-project --with dist/*.whl docsonar --version
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
|
|
8
|
+
# Environments
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
|
|
12
|
+
# Tooling caches
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
|
|
17
|
+
# docsonar local state
|
|
18
|
+
*.db
|
|
19
|
+
*.db-wal
|
|
20
|
+
*.db-shm
|
|
21
|
+
.scratch/
|
|
22
|
+
|
|
23
|
+
# OS
|
|
24
|
+
.DS_Store
|
|
25
|
+
Thumbs.db
|
docsonar-0.1.0/.mcp.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
5
|
+
"name": "docsonar server (HTTP)",
|
|
6
|
+
"type": "debugpy",
|
|
7
|
+
"request": "launch",
|
|
8
|
+
"module": "docsonar",
|
|
9
|
+
"args": ["--transport", "http", "--port", "8365"],
|
|
10
|
+
"console": "integratedTerminal",
|
|
11
|
+
"justMyCode": false
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "docsonar server (HTTP, scratch DB)",
|
|
15
|
+
"type": "debugpy",
|
|
16
|
+
"request": "launch",
|
|
17
|
+
"module": "docsonar",
|
|
18
|
+
"args": [
|
|
19
|
+
"--transport", "http",
|
|
20
|
+
"--port", "8365",
|
|
21
|
+
"--db-path", "${workspaceFolder}/.scratch/index.db"
|
|
22
|
+
],
|
|
23
|
+
"console": "integratedTerminal",
|
|
24
|
+
"justMyCode": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "pytest: all tests",
|
|
28
|
+
"type": "debugpy",
|
|
29
|
+
"request": "launch",
|
|
30
|
+
"module": "pytest",
|
|
31
|
+
"args": ["-v"],
|
|
32
|
+
"console": "integratedTerminal",
|
|
33
|
+
"justMyCode": false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "pytest: current file",
|
|
37
|
+
"type": "debugpy",
|
|
38
|
+
"request": "launch",
|
|
39
|
+
"module": "pytest",
|
|
40
|
+
"args": ["-v", "${file}"],
|
|
41
|
+
"console": "integratedTerminal",
|
|
42
|
+
"justMyCode": false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "benchmark",
|
|
46
|
+
"type": "debugpy",
|
|
47
|
+
"request": "launch",
|
|
48
|
+
"program": "${workspaceFolder}/scripts/benchmark.py",
|
|
49
|
+
"console": "integratedTerminal"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
docsonar-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ribhav Jain
|
|
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.
|
docsonar-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docsonar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local document search MCP server — chat with your folders, fully offline.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ribhav-jain/docsonar
|
|
6
|
+
Project-URL: Repository, https://github.com/ribhav-jain/docsonar
|
|
7
|
+
Project-URL: Issues, https://github.com/ribhav-jain/docsonar/issues
|
|
8
|
+
Author: Ribhav Jain
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: documents,fts5,local,mcp,rag,search,sqlite
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: mcp>=1.10.0
|
|
22
|
+
Requires-Dist: numpy>=1.26.0
|
|
23
|
+
Requires-Dist: platformdirs>=4.0.0
|
|
24
|
+
Requires-Dist: pypdf>=5.0.0
|
|
25
|
+
Requires-Dist: python-docx>=1.1.0
|
|
26
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
27
|
+
Requires-Dist: sqlite-vec>=0.1.6
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# docsonar
|
|
31
|
+
|
|
32
|
+
**Chat with your folders.** A local document search MCP server — your files never leave your machine.
|
|
33
|
+
|
|
34
|
+
docsonar indexes folders of documents into a single SQLite database and gives any MCP client (Claude Desktop, Claude Code, and others) hybrid keyword + semantic search over them. Fully offline, zero configuration, read-only by design.
|
|
35
|
+
|
|
36
|
+
## Quickstart
|
|
37
|
+
|
|
38
|
+
### Claude Code
|
|
39
|
+
|
|
40
|
+
Add to your project's `.mcp.json` (or `~/.claude.json` for all projects):
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"docsonar": {
|
|
46
|
+
"command": "uvx",
|
|
47
|
+
"args": ["docsonar"]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Claude Desktop
|
|
54
|
+
|
|
55
|
+
Add to `claude_desktop_config.json` (Settings → Developer → Edit Config):
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"mcpServers": {
|
|
60
|
+
"docsonar": {
|
|
61
|
+
"command": "uvx",
|
|
62
|
+
"args": ["docsonar"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Running from a source checkout instead: `"command": "uv", "args": ["run", "--directory", "/path/to/docsonar", "docsonar"]`.
|
|
69
|
+
|
|
70
|
+
Then just talk to it: _"Add my `~/Documents/notes` folder and find everything about quarterly planning."_ The first index downloads the embedding model (~130 MB, one time); keyword search works immediately while that happens.
|
|
71
|
+
|
|
72
|
+
For HTTP instead of stdio: `uvx docsonar --transport http --port 8365`.
|
|
73
|
+
|
|
74
|
+
## Tools
|
|
75
|
+
|
|
76
|
+
| Tool | Purpose |
|
|
77
|
+
| --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `add_folder(path, include_globs?, exclude_globs?)` | Register a folder; indexing starts in the background |
|
|
79
|
+
| `remove_folder(path)` | Unregister and purge its index data |
|
|
80
|
+
| `list_folders()` | Registered folders with counts and last index time |
|
|
81
|
+
| `search(query, top_k?, folder?, file_type?, mode?)` | Hybrid keyword+semantic search (RRF-fused); ranked passages with file path, heading/page location, and snippet |
|
|
82
|
+
| `read_file(path, start_line?, end_line?)` | File text (extracted text for pdf/docx/html); refuses paths outside registered folders |
|
|
83
|
+
| `find_similar(path, top_k?)` | Documents most similar in meaning to a given file |
|
|
84
|
+
| `reindex(folder?, force?)` | Incremental refresh: new/changed files reindexed, deleted files purged |
|
|
85
|
+
| `index_status()` | Index totals, embedding model state, background job progress, failed files |
|
|
86
|
+
|
|
87
|
+
Supported formats: `txt`, `md`, `pdf` (page-aware, cites `p. 12`), `docx`, `html`.
|
|
88
|
+
|
|
89
|
+
## Architecture
|
|
90
|
+
|
|
91
|
+
```mermaid
|
|
92
|
+
flowchart LR
|
|
93
|
+
Client["MCP client<br/>(Claude Desktop / Code)"] <-->|stdio or HTTP| Server["FastMCP server<br/>8 tools"]
|
|
94
|
+
Server --> Sec["path security<br/>(registered folders only)"]
|
|
95
|
+
Server --> Search["hybrid search<br/>BM25 + cosine KNN + RRF"]
|
|
96
|
+
Server --> Worker["background indexer<br/>(worker thread + queue)"]
|
|
97
|
+
Worker --> Parsers["parsers<br/>txt · md · pdf · docx · html"]
|
|
98
|
+
Parsers --> Chunker["heading/page-aware chunker<br/>~400 tokens, 60 overlap"]
|
|
99
|
+
Chunker --> DB[("SQLite<br/>FTS5 + sqlite-vec")]
|
|
100
|
+
Search --> DB
|
|
101
|
+
Embed["sentence-transformers<br/>bge-small-en-v1.5 (local)"] --> Worker
|
|
102
|
+
Embed --> Search
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Every chunk stores its location (heading path like `Setup > Windows`, or PDF page range), so search results can cite `report.pdf, p. 12`.
|
|
106
|
+
|
|
107
|
+
## Design decisions
|
|
108
|
+
|
|
109
|
+
- **Read-only by design.** There are no write, move, or delete tools, and there never will be. The server only reads files inside folders you explicitly register — with symlink-escape protection and strict path resolution — so the blast radius of a misbehaving client is zero.
|
|
110
|
+
- **SQLite as the single store.** FTS5 gives production-grade BM25 keyword search in the standard library, and [sqlite-vec](https://github.com/asg017/sqlite-vec) puts vectors in the same file. One database file, no services to run, trivial to back up or delete.
|
|
111
|
+
- **Hybrid search by default.** BM25 and cosine-KNN rankings are fused with reciprocal-rank fusion (k=60). Exact identifiers and rare terms win on the keyword side; paraphrased questions win on the semantic side; RRF needs no score calibration between them. `mode` lets the caller force either side.
|
|
112
|
+
- **Local embeddings.** [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) (384-dim) — same size class as the classic all-MiniLM-L6-v2 but stronger on retrieval benchmarks. Downloads on first index, runs on CPU, lazy-loaded so server startup stays instant. If the model can't load, everything degrades gracefully to keyword search and tool responses say so.
|
|
113
|
+
- **A tool surface built for an LLM caller.** `search` returns enough per hit (path, location, score, snippet) to decide what to read next without another round trip; results carry stable `chunk_id`s; every degradation is reported in-band via `note`/`embedding_note` fields instead of failing. There's no "answer the question" tool on purpose — the calling model does the reasoning; docsonar does retrieval.
|
|
114
|
+
- **Incremental by content, not just mtime.** Reindexing checks mtime+size first, then falls back to a SHA-256 content hash — touched-but-identical files are skipped, and deleted files are purged from both the FTS and vector indexes.
|
|
115
|
+
- **Scanned PDFs fail loudly.** A PDF with no extractable text is reported as failed with a clear reason rather than silently indexed as empty. OCR is out of scope.
|
|
116
|
+
|
|
117
|
+
## Benchmarks
|
|
118
|
+
|
|
119
|
+
Synthetic corpus of 200 markdown files (600 chunks); Intel Core Ultra 5 125U (laptop, CPU-only), Windows 11, Python 3.12. Reproduce with `uv run python scripts/benchmark.py`.
|
|
120
|
+
|
|
121
|
+
| Operation | Result |
|
|
122
|
+
| --------------------------------------- | ------------------------------------- |
|
|
123
|
+
| Index, keyword-only | 0.7 s (≈280 files/s) |
|
|
124
|
+
| Index, with embeddings | 59 s (≈3.4 files/s — embedding-bound) |
|
|
125
|
+
| Incremental reindex, nothing changed | 0.03 s |
|
|
126
|
+
| Search, keyword | 8.9 ms median |
|
|
127
|
+
| Search, semantic | 35 ms median |
|
|
128
|
+
| Search, hybrid | 54 ms median |
|
|
129
|
+
| Embedding model load (once per process) | ~21 s |
|
|
130
|
+
| Database size | 2.6 MB (1.1 MB keyword-only) |
|
|
131
|
+
|
|
132
|
+
## Configuration
|
|
133
|
+
|
|
134
|
+
Zero config needed. To customize, create `config.toml` in the platform config directory (Windows: `%LOCALAPPDATA%\docsonar\`, macOS: `~/Library/Application Support/docsonar/`, Linux: `~/.config/docsonar/`):
|
|
135
|
+
|
|
136
|
+
```toml
|
|
137
|
+
embedding_model = "BAAI/bge-small-en-v1.5" # any sentence-transformers model
|
|
138
|
+
chunk_target_tokens = 400
|
|
139
|
+
chunk_max_tokens = 512
|
|
140
|
+
chunk_min_tokens = 100
|
|
141
|
+
chunk_overlap_tokens = 60
|
|
142
|
+
max_file_size_mb = 50
|
|
143
|
+
extra_ignore_dirs = ["Archive"]
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
CLI flags: `--transport stdio|http`, `--host`, `--port`, `--db-path`, `--config`.
|
|
147
|
+
|
|
148
|
+
The index database lives in the platform data directory (Windows: `%LOCALAPPDATA%\docsonar\`, macOS: `~/Library/Application Support/docsonar/`, Linux: `~/.local/share/docsonar/`).
|
|
149
|
+
|
|
150
|
+
## Running from source
|
|
151
|
+
|
|
152
|
+
Requires [uv](https://docs.astral.sh/uv/) (it installs the right Python automatically):
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
# Windows
|
|
156
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
157
|
+
# macOS / Linux
|
|
158
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
159
|
+
|
|
160
|
+
git clone https://github.com/ribhav-jain/docsonar.git
|
|
161
|
+
cd docsonar
|
|
162
|
+
uv sync --dev # creates .venv and installs everything, incl. dev tools
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Run the tests
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
uv run pytest # full suite (~2 s, no model download needed)
|
|
169
|
+
uv run pytest -v # verbose, one line per test
|
|
170
|
+
uv run pytest tests/test_search.py # one file
|
|
171
|
+
uv run pytest -k incremental # tests matching a keyword
|
|
172
|
+
uv run ruff check . # lint
|
|
173
|
+
uv run mypy src tests # strict typecheck
|
|
174
|
+
uv run python scripts/benchmark.py # perf numbers (downloads the real model)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Run the server
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
uv run docsonar # stdio — for MCP clients (Claude Desktop/Code)
|
|
181
|
+
uv run docsonar --transport http --port 8365 # HTTP — for manual testing (Postman, curl)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
VS Code: press F5 — launch configs for the HTTP server and the test suite are in `.vscode/launch.json`.
|
|
185
|
+
|
|
186
|
+
### Try the tools without an MCP client
|
|
187
|
+
|
|
188
|
+
With the HTTP server running, the endpoint is `http://127.0.0.1:8365/mcp`. Recent Postman versions can connect directly (**New → MCP Request**, transport HTTP) and show all 8 tools as forms. For raw HTTP, MCP is JSON-RPC over POST with two setup calls, then tool calls. Send every request with headers `Content-Type: application/json` and `Accept: application/json, text/event-stream`:
|
|
189
|
+
|
|
190
|
+
```jsonc
|
|
191
|
+
// 1. initialize — copy the `mcp-session-id` RESPONSE header and send it
|
|
192
|
+
// back as a request header on every call below
|
|
193
|
+
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"postman","version":"1.0"}}}
|
|
194
|
+
|
|
195
|
+
// 2. initialized notification (expect 202, empty body)
|
|
196
|
+
{"jsonrpc":"2.0","method":"notifications/initialized"}
|
|
197
|
+
|
|
198
|
+
// 3. list the tools
|
|
199
|
+
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Then call tools — the repo ships a sample corpus in `examples/sample-docs` to play with (use forward slashes in JSON to avoid escaping; they work on Windows too):
|
|
203
|
+
|
|
204
|
+
```jsonc
|
|
205
|
+
// Register the sample folder (first ever call downloads the embedding model, ~30 s)
|
|
206
|
+
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"add_folder",
|
|
207
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs"}}}
|
|
208
|
+
|
|
209
|
+
// Watch indexing progress until indexing.active is false
|
|
210
|
+
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"index_status","arguments":{}}}
|
|
211
|
+
|
|
212
|
+
// Hybrid search — finds the expense-policy PDF, cites its page
|
|
213
|
+
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"search",
|
|
214
|
+
"arguments":{"query":"meal reimbursement limit","top_k":3,"mode":"hybrid"}}}
|
|
215
|
+
|
|
216
|
+
// Semantic search — no keyword overlap needed
|
|
217
|
+
{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"search",
|
|
218
|
+
"arguments":{"query":"how hot should water be for green tea","mode":"semantic"}}}
|
|
219
|
+
|
|
220
|
+
// Read a hit (works on PDFs too — returns extracted text)
|
|
221
|
+
{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"read_file",
|
|
222
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs/expense-policy.pdf"}}}
|
|
223
|
+
|
|
224
|
+
// "More like this"
|
|
225
|
+
{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"find_similar",
|
|
226
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs/espresso-guide.md","top_k":3}}}
|
|
227
|
+
|
|
228
|
+
// Refresh after files change on disk (force:true rebuilds everything)
|
|
229
|
+
{"jsonrpc":"2.0","id":9,"method":"tools/call","params":{"name":"reindex","arguments":{}}}
|
|
230
|
+
|
|
231
|
+
// Clean up — unregisters the folder and purges its index data
|
|
232
|
+
{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"remove_folder",
|
|
233
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs"}}}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Security check worth trying: `read_file` with any path outside a registered folder (e.g. `C:/Windows/System32/drivers/etc/hosts`) returns a refusal, not file content.
|
|
237
|
+
|
|
238
|
+
CI runs lint, typecheck, and the test suite on Linux, macOS, and Windows.
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT
|
docsonar-0.1.0/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# docsonar
|
|
2
|
+
|
|
3
|
+
**Chat with your folders.** A local document search MCP server — your files never leave your machine.
|
|
4
|
+
|
|
5
|
+
docsonar indexes folders of documents into a single SQLite database and gives any MCP client (Claude Desktop, Claude Code, and others) hybrid keyword + semantic search over them. Fully offline, zero configuration, read-only by design.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
### Claude Code
|
|
10
|
+
|
|
11
|
+
Add to your project's `.mcp.json` (or `~/.claude.json` for all projects):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"docsonar": {
|
|
17
|
+
"command": "uvx",
|
|
18
|
+
"args": ["docsonar"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Claude Desktop
|
|
25
|
+
|
|
26
|
+
Add to `claude_desktop_config.json` (Settings → Developer → Edit Config):
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"docsonar": {
|
|
32
|
+
"command": "uvx",
|
|
33
|
+
"args": ["docsonar"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Running from a source checkout instead: `"command": "uv", "args": ["run", "--directory", "/path/to/docsonar", "docsonar"]`.
|
|
40
|
+
|
|
41
|
+
Then just talk to it: _"Add my `~/Documents/notes` folder and find everything about quarterly planning."_ The first index downloads the embedding model (~130 MB, one time); keyword search works immediately while that happens.
|
|
42
|
+
|
|
43
|
+
For HTTP instead of stdio: `uvx docsonar --transport http --port 8365`.
|
|
44
|
+
|
|
45
|
+
## Tools
|
|
46
|
+
|
|
47
|
+
| Tool | Purpose |
|
|
48
|
+
| --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| `add_folder(path, include_globs?, exclude_globs?)` | Register a folder; indexing starts in the background |
|
|
50
|
+
| `remove_folder(path)` | Unregister and purge its index data |
|
|
51
|
+
| `list_folders()` | Registered folders with counts and last index time |
|
|
52
|
+
| `search(query, top_k?, folder?, file_type?, mode?)` | Hybrid keyword+semantic search (RRF-fused); ranked passages with file path, heading/page location, and snippet |
|
|
53
|
+
| `read_file(path, start_line?, end_line?)` | File text (extracted text for pdf/docx/html); refuses paths outside registered folders |
|
|
54
|
+
| `find_similar(path, top_k?)` | Documents most similar in meaning to a given file |
|
|
55
|
+
| `reindex(folder?, force?)` | Incremental refresh: new/changed files reindexed, deleted files purged |
|
|
56
|
+
| `index_status()` | Index totals, embedding model state, background job progress, failed files |
|
|
57
|
+
|
|
58
|
+
Supported formats: `txt`, `md`, `pdf` (page-aware, cites `p. 12`), `docx`, `html`.
|
|
59
|
+
|
|
60
|
+
## Architecture
|
|
61
|
+
|
|
62
|
+
```mermaid
|
|
63
|
+
flowchart LR
|
|
64
|
+
Client["MCP client<br/>(Claude Desktop / Code)"] <-->|stdio or HTTP| Server["FastMCP server<br/>8 tools"]
|
|
65
|
+
Server --> Sec["path security<br/>(registered folders only)"]
|
|
66
|
+
Server --> Search["hybrid search<br/>BM25 + cosine KNN + RRF"]
|
|
67
|
+
Server --> Worker["background indexer<br/>(worker thread + queue)"]
|
|
68
|
+
Worker --> Parsers["parsers<br/>txt · md · pdf · docx · html"]
|
|
69
|
+
Parsers --> Chunker["heading/page-aware chunker<br/>~400 tokens, 60 overlap"]
|
|
70
|
+
Chunker --> DB[("SQLite<br/>FTS5 + sqlite-vec")]
|
|
71
|
+
Search --> DB
|
|
72
|
+
Embed["sentence-transformers<br/>bge-small-en-v1.5 (local)"] --> Worker
|
|
73
|
+
Embed --> Search
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Every chunk stores its location (heading path like `Setup > Windows`, or PDF page range), so search results can cite `report.pdf, p. 12`.
|
|
77
|
+
|
|
78
|
+
## Design decisions
|
|
79
|
+
|
|
80
|
+
- **Read-only by design.** There are no write, move, or delete tools, and there never will be. The server only reads files inside folders you explicitly register — with symlink-escape protection and strict path resolution — so the blast radius of a misbehaving client is zero.
|
|
81
|
+
- **SQLite as the single store.** FTS5 gives production-grade BM25 keyword search in the standard library, and [sqlite-vec](https://github.com/asg017/sqlite-vec) puts vectors in the same file. One database file, no services to run, trivial to back up or delete.
|
|
82
|
+
- **Hybrid search by default.** BM25 and cosine-KNN rankings are fused with reciprocal-rank fusion (k=60). Exact identifiers and rare terms win on the keyword side; paraphrased questions win on the semantic side; RRF needs no score calibration between them. `mode` lets the caller force either side.
|
|
83
|
+
- **Local embeddings.** [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) (384-dim) — same size class as the classic all-MiniLM-L6-v2 but stronger on retrieval benchmarks. Downloads on first index, runs on CPU, lazy-loaded so server startup stays instant. If the model can't load, everything degrades gracefully to keyword search and tool responses say so.
|
|
84
|
+
- **A tool surface built for an LLM caller.** `search` returns enough per hit (path, location, score, snippet) to decide what to read next without another round trip; results carry stable `chunk_id`s; every degradation is reported in-band via `note`/`embedding_note` fields instead of failing. There's no "answer the question" tool on purpose — the calling model does the reasoning; docsonar does retrieval.
|
|
85
|
+
- **Incremental by content, not just mtime.** Reindexing checks mtime+size first, then falls back to a SHA-256 content hash — touched-but-identical files are skipped, and deleted files are purged from both the FTS and vector indexes.
|
|
86
|
+
- **Scanned PDFs fail loudly.** A PDF with no extractable text is reported as failed with a clear reason rather than silently indexed as empty. OCR is out of scope.
|
|
87
|
+
|
|
88
|
+
## Benchmarks
|
|
89
|
+
|
|
90
|
+
Synthetic corpus of 200 markdown files (600 chunks); Intel Core Ultra 5 125U (laptop, CPU-only), Windows 11, Python 3.12. Reproduce with `uv run python scripts/benchmark.py`.
|
|
91
|
+
|
|
92
|
+
| Operation | Result |
|
|
93
|
+
| --------------------------------------- | ------------------------------------- |
|
|
94
|
+
| Index, keyword-only | 0.7 s (≈280 files/s) |
|
|
95
|
+
| Index, with embeddings | 59 s (≈3.4 files/s — embedding-bound) |
|
|
96
|
+
| Incremental reindex, nothing changed | 0.03 s |
|
|
97
|
+
| Search, keyword | 8.9 ms median |
|
|
98
|
+
| Search, semantic | 35 ms median |
|
|
99
|
+
| Search, hybrid | 54 ms median |
|
|
100
|
+
| Embedding model load (once per process) | ~21 s |
|
|
101
|
+
| Database size | 2.6 MB (1.1 MB keyword-only) |
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
Zero config needed. To customize, create `config.toml` in the platform config directory (Windows: `%LOCALAPPDATA%\docsonar\`, macOS: `~/Library/Application Support/docsonar/`, Linux: `~/.config/docsonar/`):
|
|
106
|
+
|
|
107
|
+
```toml
|
|
108
|
+
embedding_model = "BAAI/bge-small-en-v1.5" # any sentence-transformers model
|
|
109
|
+
chunk_target_tokens = 400
|
|
110
|
+
chunk_max_tokens = 512
|
|
111
|
+
chunk_min_tokens = 100
|
|
112
|
+
chunk_overlap_tokens = 60
|
|
113
|
+
max_file_size_mb = 50
|
|
114
|
+
extra_ignore_dirs = ["Archive"]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
CLI flags: `--transport stdio|http`, `--host`, `--port`, `--db-path`, `--config`.
|
|
118
|
+
|
|
119
|
+
The index database lives in the platform data directory (Windows: `%LOCALAPPDATA%\docsonar\`, macOS: `~/Library/Application Support/docsonar/`, Linux: `~/.local/share/docsonar/`).
|
|
120
|
+
|
|
121
|
+
## Running from source
|
|
122
|
+
|
|
123
|
+
Requires [uv](https://docs.astral.sh/uv/) (it installs the right Python automatically):
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
# Windows
|
|
127
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
128
|
+
# macOS / Linux
|
|
129
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
130
|
+
|
|
131
|
+
git clone https://github.com/ribhav-jain/docsonar.git
|
|
132
|
+
cd docsonar
|
|
133
|
+
uv sync --dev # creates .venv and installs everything, incl. dev tools
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Run the tests
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
uv run pytest # full suite (~2 s, no model download needed)
|
|
140
|
+
uv run pytest -v # verbose, one line per test
|
|
141
|
+
uv run pytest tests/test_search.py # one file
|
|
142
|
+
uv run pytest -k incremental # tests matching a keyword
|
|
143
|
+
uv run ruff check . # lint
|
|
144
|
+
uv run mypy src tests # strict typecheck
|
|
145
|
+
uv run python scripts/benchmark.py # perf numbers (downloads the real model)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Run the server
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
uv run docsonar # stdio — for MCP clients (Claude Desktop/Code)
|
|
152
|
+
uv run docsonar --transport http --port 8365 # HTTP — for manual testing (Postman, curl)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
VS Code: press F5 — launch configs for the HTTP server and the test suite are in `.vscode/launch.json`.
|
|
156
|
+
|
|
157
|
+
### Try the tools without an MCP client
|
|
158
|
+
|
|
159
|
+
With the HTTP server running, the endpoint is `http://127.0.0.1:8365/mcp`. Recent Postman versions can connect directly (**New → MCP Request**, transport HTTP) and show all 8 tools as forms. For raw HTTP, MCP is JSON-RPC over POST with two setup calls, then tool calls. Send every request with headers `Content-Type: application/json` and `Accept: application/json, text/event-stream`:
|
|
160
|
+
|
|
161
|
+
```jsonc
|
|
162
|
+
// 1. initialize — copy the `mcp-session-id` RESPONSE header and send it
|
|
163
|
+
// back as a request header on every call below
|
|
164
|
+
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"postman","version":"1.0"}}}
|
|
165
|
+
|
|
166
|
+
// 2. initialized notification (expect 202, empty body)
|
|
167
|
+
{"jsonrpc":"2.0","method":"notifications/initialized"}
|
|
168
|
+
|
|
169
|
+
// 3. list the tools
|
|
170
|
+
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Then call tools — the repo ships a sample corpus in `examples/sample-docs` to play with (use forward slashes in JSON to avoid escaping; they work on Windows too):
|
|
174
|
+
|
|
175
|
+
```jsonc
|
|
176
|
+
// Register the sample folder (first ever call downloads the embedding model, ~30 s)
|
|
177
|
+
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"add_folder",
|
|
178
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs"}}}
|
|
179
|
+
|
|
180
|
+
// Watch indexing progress until indexing.active is false
|
|
181
|
+
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"index_status","arguments":{}}}
|
|
182
|
+
|
|
183
|
+
// Hybrid search — finds the expense-policy PDF, cites its page
|
|
184
|
+
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"search",
|
|
185
|
+
"arguments":{"query":"meal reimbursement limit","top_k":3,"mode":"hybrid"}}}
|
|
186
|
+
|
|
187
|
+
// Semantic search — no keyword overlap needed
|
|
188
|
+
{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"search",
|
|
189
|
+
"arguments":{"query":"how hot should water be for green tea","mode":"semantic"}}}
|
|
190
|
+
|
|
191
|
+
// Read a hit (works on PDFs too — returns extracted text)
|
|
192
|
+
{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"read_file",
|
|
193
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs/expense-policy.pdf"}}}
|
|
194
|
+
|
|
195
|
+
// "More like this"
|
|
196
|
+
{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"find_similar",
|
|
197
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs/espresso-guide.md","top_k":3}}}
|
|
198
|
+
|
|
199
|
+
// Refresh after files change on disk (force:true rebuilds everything)
|
|
200
|
+
{"jsonrpc":"2.0","id":9,"method":"tools/call","params":{"name":"reindex","arguments":{}}}
|
|
201
|
+
|
|
202
|
+
// Clean up — unregisters the folder and purges its index data
|
|
203
|
+
{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"remove_folder",
|
|
204
|
+
"arguments":{"path":"C:/path/to/docsonar/examples/sample-docs"}}}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Security check worth trying: `read_file` with any path outside a registered folder (e.g. `C:/Windows/System32/drivers/etc/hosts`) returns a refusal, not file content.
|
|
208
|
+
|
|
209
|
+
CI runs lint, typecheck, and the test suite on Linux, macOS, and Windows.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Home Espresso Guide
|
|
2
|
+
|
|
3
|
+
Notes on pulling consistent espresso shots on entry-level machines.
|
|
4
|
+
|
|
5
|
+
## Dialing In
|
|
6
|
+
|
|
7
|
+
Start with an 18 gram dose and aim for 36 grams of espresso out in 25 to
|
|
8
|
+
30 seconds. If the shot runs faster, grind finer; slower, grind coarser.
|
|
9
|
+
Change only one variable at a time or you will chase your own tail.
|
|
10
|
+
|
|
11
|
+
## Milk Steaming
|
|
12
|
+
|
|
13
|
+
Purge the wand, then stretch the milk for the first few seconds only.
|
|
14
|
+
Aim for glossy microfoam around 60 to 65 degrees Celsius — hotter than
|
|
15
|
+
68 and the milk sweetness collapses.
|
|
16
|
+
|
|
17
|
+
## Common Faults
|
|
18
|
+
|
|
19
|
+
Sour, thin shots usually mean under-extraction: grind finer or raise the
|
|
20
|
+
water temperature. Bitter, ashy shots mean over-extraction: coarsen the
|
|
21
|
+
grind or shorten the shot. Channeling shows up as spritzing from the
|
|
22
|
+
portafilter and is almost always a distribution problem, not a machine
|
|
23
|
+
problem.
|