thesaurus-ai 0.2.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.
Files changed (67) hide show
  1. thesaurus_ai-0.2.0/.gitignore +16 -0
  2. thesaurus_ai-0.2.0/CHANGELOG.md +75 -0
  3. thesaurus_ai-0.2.0/LICENSE +21 -0
  4. thesaurus_ai-0.2.0/PKG-INFO +520 -0
  5. thesaurus_ai-0.2.0/README.md +489 -0
  6. thesaurus_ai-0.2.0/pyproject.toml +86 -0
  7. thesaurus_ai-0.2.0/src/thesaurus/__init__.py +16 -0
  8. thesaurus_ai-0.2.0/src/thesaurus/__main__.py +3 -0
  9. thesaurus_ai-0.2.0/src/thesaurus/adapters/__init__.py +1 -0
  10. thesaurus_ai-0.2.0/src/thesaurus/adapters/_paths.py +27 -0
  11. thesaurus_ai-0.2.0/src/thesaurus/adapters/base.py +17 -0
  12. thesaurus_ai-0.2.0/src/thesaurus/adapters/csv.py +99 -0
  13. thesaurus_ai-0.2.0/src/thesaurus/adapters/json.py +137 -0
  14. thesaurus_ai-0.2.0/src/thesaurus/adapters/registry.py +32 -0
  15. thesaurus_ai-0.2.0/src/thesaurus/api/__init__.py +1 -0
  16. thesaurus_ai-0.2.0/src/thesaurus/api/build/__init__.py +7 -0
  17. thesaurus_ai-0.2.0/src/thesaurus/api/build/app.py +385 -0
  18. thesaurus_ai-0.2.0/src/thesaurus/api/build/jobs.py +116 -0
  19. thesaurus_ai-0.2.0/src/thesaurus/api/build/servers.py +127 -0
  20. thesaurus_ai-0.2.0/src/thesaurus/api/common.py +48 -0
  21. thesaurus_ai-0.2.0/src/thesaurus/api/serve/__init__.py +6 -0
  22. thesaurus_ai-0.2.0/src/thesaurus/api/serve/app.py +271 -0
  23. thesaurus_ai-0.2.0/src/thesaurus/api/serve/store.py +95 -0
  24. thesaurus_ai-0.2.0/src/thesaurus/artifact/__init__.py +22 -0
  25. thesaurus_ai-0.2.0/src/thesaurus/artifact/bundle.py +180 -0
  26. thesaurus_ai-0.2.0/src/thesaurus/artifact/reader.py +344 -0
  27. thesaurus_ai-0.2.0/src/thesaurus/artifact/validate.py +273 -0
  28. thesaurus_ai-0.2.0/src/thesaurus/artifact/writer.py +156 -0
  29. thesaurus_ai-0.2.0/src/thesaurus/cli.py +367 -0
  30. thesaurus_ai-0.2.0/src/thesaurus/compiler/__init__.py +5 -0
  31. thesaurus_ai-0.2.0/src/thesaurus/compiler/cache.py +265 -0
  32. thesaurus_ai-0.2.0/src/thesaurus/compiler/context.py +95 -0
  33. thesaurus_ai-0.2.0/src/thesaurus/compiler/core.py +1014 -0
  34. thesaurus_ai-0.2.0/src/thesaurus/compiler/glossary.py +47 -0
  35. thesaurus_ai-0.2.0/src/thesaurus/compiler/graph.py +203 -0
  36. thesaurus_ai-0.2.0/src/thesaurus/compiler/schemas.py +75 -0
  37. thesaurus_ai-0.2.0/src/thesaurus/compiler/select.py +184 -0
  38. thesaurus_ai-0.2.0/src/thesaurus/compiler/services.py +277 -0
  39. thesaurus_ai-0.2.0/src/thesaurus/config.py +217 -0
  40. thesaurus_ai-0.2.0/src/thesaurus/ids.py +38 -0
  41. thesaurus_ai-0.2.0/src/thesaurus/models.py +257 -0
  42. thesaurus_ai-0.2.0/src/thesaurus/normalize.py +19 -0
  43. thesaurus_ai-0.2.0/src/thesaurus/types.py +89 -0
  44. thesaurus_ai-0.2.0/src/thesaurus_search/__init__.py +25 -0
  45. thesaurus_ai-0.2.0/src/thesaurus_search/cli.py +113 -0
  46. thesaurus_ai-0.2.0/src/thesaurus_search/client.py +284 -0
  47. thesaurus_ai-0.2.0/src/thesaurus_search/fuzzy.py +86 -0
  48. thesaurus_ai-0.2.0/src/thesaurus_search/index.py +262 -0
  49. thesaurus_ai-0.2.0/src/thesaurus_search/models.py +84 -0
  50. thesaurus_ai-0.2.0/src/thesaurus_search/query.py +155 -0
  51. thesaurus_ai-0.2.0/src/thesaurus_search/text.py +27 -0
  52. thesaurus_ai-0.2.0/tests/__init__.py +0 -0
  53. thesaurus_ai-0.2.0/tests/fakes.py +139 -0
  54. thesaurus_ai-0.2.0/tests/search_fixture.py +236 -0
  55. thesaurus_ai-0.2.0/tests/test_adapters.py +180 -0
  56. thesaurus_ai-0.2.0/tests/test_api_build.py +229 -0
  57. thesaurus_ai-0.2.0/tests/test_api_serve.py +190 -0
  58. thesaurus_ai-0.2.0/tests/test_bundle.py +141 -0
  59. thesaurus_ai-0.2.0/tests/test_cache.py +198 -0
  60. thesaurus_ai-0.2.0/tests/test_cli.py +120 -0
  61. thesaurus_ai-0.2.0/tests/test_compiler.py +263 -0
  62. thesaurus_ai-0.2.0/tests/test_config.py +82 -0
  63. thesaurus_ai-0.2.0/tests/test_fuzzy.py +50 -0
  64. thesaurus_ai-0.2.0/tests/test_reader.py +100 -0
  65. thesaurus_ai-0.2.0/tests/test_search.py +130 -0
  66. thesaurus_ai-0.2.0/tests/test_translation.py +83 -0
  67. thesaurus_ai-0.2.0/tests/test_validate.py +137 -0
@@ -0,0 +1,16 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ /artifact/
7
+ /artifacts/
8
+ /dist/
9
+ /build/
10
+ /.thesaurus-cache/
11
+ *.egg-info/
12
+ experiments/**/artifact/
13
+ experiments/**/artifact-*/
14
+ experiments/**/cache/
15
+ experiments/**/*.tar.gz
16
+ experiments/**/*.log
@@ -0,0 +1,75 @@
1
+ # Changelog
2
+
3
+ All notable changes to Thesaurus are documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and the project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## [0.2.0] - 2026-11-30
9
+
10
+ ### Added
11
+
12
+ - `thesaurus_search` runtime package and `thesaurus-search` CLI.
13
+ - In-memory inverted index over fields, translated fields, and generated forms.
14
+ - BM25 ranking with phrase boosts and per-field match explanations.
15
+ - Fuzzy search by default, with trigram candidates and bounded
16
+ Damerau-Levenshtein matching.
17
+ - Explicit `prefix` and `exact` search modes.
18
+ - Concept/relation query expansion in fuzzy mode.
19
+ - Filters by language, view, status, field path, and form type.
20
+ - Deterministic runtime search tests for typos, prefixes, phrases, filters, and
21
+ CLI behavior.
22
+ - `thesaurus validate` command for manifest hashes, counts, unique ids, foreign
23
+ keys, form normalization, and view paths.
24
+ - Incremental content-addressed build cache for translations, generation, and
25
+ embeddings, enabled by default and configurable with `cache.enabled`,
26
+ `cache.path`, `--cache-dir`, and `--no-cache`.
27
+ - Lazy model-client construction so a fully cached rebuild needs no credentials.
28
+ - Cache hit/miss/write/error statistics in `BuildResult` and CLI output.
29
+ - Portable tar.gz artifact bundles with `thesaurus export` and
30
+ `thesaurus extract`.
31
+ - `Artifact.open` support for reading bundles directly from a tar.gz file.
32
+ - `Artifact.export_bundle` and `Artifact.extract_bundle`, with validation,
33
+ unsafe-path rejection, and explicit extraction directories.
34
+ - Vanilla JavaScript browser search client under `js/`, with native gzip + TAR
35
+ loading, BM25, fuzzy/prefix/exact modes, filters, concept expansion, and a
36
+ browser test page.
37
+
38
+ ## [0.1.0] - 2026-11-28
39
+
40
+ First public MVP.
41
+
42
+ ### Added
43
+
44
+ - Offline compiler that turns JSON, JSONL, and CSV corpora into multilingual
45
+ lexical search artifacts.
46
+ - Field-level translation strategies: `translate_source`,
47
+ `translate_candidates`, and `select_then_translate`.
48
+ - Structured candidate generation for paraphrases, queries, key terms, and
49
+ short answers.
50
+ - Deterministic context assembly with `field`, `document`, and `auto` modes.
51
+ - Per-form similarity thresholds, Pareto filtering, and greedy max-min
52
+ diversity selection.
53
+ - Concepts, typed relations, field/form links, views, and audit events.
54
+ - Atomic layered artifact writer with a hashed manifest.
55
+ - Lazy Python artifact reader with collections, filters, and document bundles.
56
+ - CLI commands: `build`, `inspect`, `build-api`, and `artifact-api`.
57
+ - Build API with token auth, jobs, progress, SSE events, cancellation, result
58
+ metadata, and managed Artifact API instances.
59
+ - Read-only Artifact API with multi-artifact mounts, filters, pagination,
60
+ nested grouping, bundles, ZIP export, optional auth, and `SIGHUP` reload.
61
+ - Optional YAML translation glossary and preserved terms.
62
+ - GitHub Actions CI for Python 3.12 and 3.13, plus distribution builds.
63
+ - Deterministic test suite using generator, translator, and embedder doubles.
64
+
65
+ ### Known limitations
66
+
67
+ - No runtime search or ranking; the artifact is consumed by a separate lexical
68
+ search client.
69
+ - No review workflow yet; generated forms remain `proposed`.
70
+ - No incremental builds, content-addressed reuse, or persistent jobs.
71
+ - No cross-host artifact publication; the Build API and Artifact API share a
72
+ filesystem in the MVP.
73
+ - Artifact API token authentication is optional.
74
+ - In-process Artifact API launch from the Build API is intended for local and
75
+ development use.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GIA-UH and SYALIA S.R.L.
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.
@@ -0,0 +1,520 @@
1
+ Metadata-Version: 2.5
2
+ Name: thesaurus-ai
3
+ Version: 0.2.0
4
+ Summary: Offline compiler for multilingual lexical search artifacts.
5
+ Project-URL: Homepage, https://github.com/gia-uh/thesaurus
6
+ Project-URL: Repository, https://github.com/gia-uh/thesaurus
7
+ Project-URL: Issues, https://github.com/gia-uh/thesaurus/issues
8
+ Project-URL: Changelog, https://github.com/gia-uh/thesaurus/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/gia-uh/thesaurus/blob/main/docs/spec.md
10
+ Author: GIA-UH, SYALIA S.R.L.
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: artifacts,lexical,multilingual,nlp,search
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
21
+ Classifier: Topic :: Text Processing :: Linguistic
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: lingo-ai>=2.2.1
24
+ Requires-Dist: pydantic>=2.12.4
25
+ Requires-Dist: pyyaml>=6.0.3
26
+ Provides-Extra: api
27
+ Requires-Dist: fastapi>=0.115; extra == 'api'
28
+ Requires-Dist: python-multipart>=0.0.20; extra == 'api'
29
+ Requires-Dist: uvicorn>=0.32; extra == 'api'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Thesaurus
33
+
34
+ [![CI](https://github.com/gia-uh/thesaurus/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gia-uh/thesaurus/actions/workflows/ci.yml)
35
+
36
+ Thesaurus is a co-development between **GIA-UH** and **SYALIA S.R.L.**
37
+
38
+ Thesaurus is an offline compiler that turns arbitrary corpora into multilingual
39
+ lexical search artifacts.
40
+
41
+ LLMs and embeddings are used **only at build time**. The artifact is
42
+ self-contained: a lexical search runtime can load it without models, embeddings,
43
+ or network access.
44
+
45
+ ```text
46
+ corpus + config ──► compiler ──► artifact/ ──► Artifact API
47
+ (LLM, │ (read-only,
48
+ embeddings) │ no models)
49
+ └──────────► thesaurus-search
50
+ (lexical, no models)
51
+ ```
52
+
53
+ The compiler is the product; the artifact is the contract. The project has two
54
+ separate HTTP planes:
55
+
56
+ | Plane | Purpose | Writes | Default |
57
+ |---|---|---|---|
58
+ | **Build API** | Run compilation jobs | Yes | `:8001` |
59
+ | **Artifact API** | Serve mounted artifacts | No | `:8000` |
60
+
61
+ They are different FastAPI applications with different routes, auth, and
62
+ lifecycle. The Build API never proxies artifact routes. The Artifact API never
63
+ runs the compiler.
64
+
65
+ ## Install
66
+
67
+ From PyPI:
68
+
69
+ ```bash
70
+ pip install thesaurus-ai
71
+ pip install "thesaurus-ai[api]" # Build API and Artifact API
72
+ ```
73
+
74
+ From source:
75
+
76
+ ```bash
77
+ uv sync # compiler, CLIs, reader, and search runtime
78
+ uv sync --extra api # Build API and Artifact API
79
+ ```
80
+
81
+ Requires Python 3.12+.
82
+
83
+ ## Compile an artifact
84
+
85
+ ```bash
86
+ uv run thesaurus build --config config.example.yaml
87
+ ```
88
+
89
+ The default config reads `examples/corpus.jsonl` and writes `artifact/`:
90
+
91
+ ```yaml
92
+ languages:
93
+ source: es
94
+ targets: [en]
95
+
96
+ models:
97
+ llm: gpt-4.1-mini
98
+ embedding: text-embedding-3-small
99
+ api_key_env: API_KEY
100
+ ```
101
+
102
+ API keys are read from the environment named by `models.api_key_env`. They are
103
+ never written to the artifact.
104
+
105
+ For the loaded LM Studio models, use `config.lmstudio.yaml`:
106
+
107
+ ```bash
108
+ export LMSTUDIO_API_KEY=lm-studio
109
+ uv run thesaurus build --config config.lmstudio.yaml
110
+ ```
111
+
112
+ LM Studio does not require a real key, but the OpenAI client requires a non-empty
113
+ value.
114
+
115
+ CLI flags override the config:
116
+
117
+ ```bash
118
+ uv run thesaurus build \
119
+ --config config.yaml \
120
+ --output ./artifacts/feria-2026 \
121
+ --artifact-id feria-2026 \
122
+ --overwrite
123
+ ```
124
+
125
+ `--serve` builds and then starts the Artifact API for the new artifact:
126
+
127
+ ```bash
128
+ uv run thesaurus build --config config.yaml --serve --port 8000
129
+ ```
130
+
131
+ ## Compile from Python
132
+
133
+ ```python
134
+ import asyncio
135
+
136
+ from thesaurus import Compiler, load_config
137
+
138
+ config = load_config("config.yaml")
139
+ result = asyncio.run(Compiler(config).build())
140
+
141
+ print(result.artifact_id, result.path, result.counts)
142
+ ```
143
+
144
+ For records already in memory:
145
+
146
+ ```python
147
+ from thesaurus import compile_records
148
+
149
+ # records: list[thesaurus.models.Record]
150
+ result = asyncio.run(compile_records(records, config))
151
+ ```
152
+
153
+ `Compiler` accepts optional `generator`, `translator`, and `embedder` objects
154
+ implementing the protocols in `thesaurus.compiler.services`; this is how the
155
+ test suite runs without network access.
156
+
157
+ ## Incremental builds
158
+
159
+ The cache is enabled by default and lives next to the artifact in
160
+ `.thesaurus-cache/`. It is content-addressed, atomic, and outside the artifact
161
+ contract.
162
+
163
+ ```bash
164
+ uv run thesaurus build --config config.yaml # default cache
165
+ uv run thesaurus build --config config.yaml --cache-dir ./cache # explicit path
166
+ uv run thesaurus build --config config.yaml --no-cache # disable
167
+ ```
168
+
169
+ A second build with unchanged corpus and configuration makes **zero LLM,
170
+ translation, and embedding calls**. Translation, generation, and embedding
171
+ entries are keyed by text, context, model, prompt version, glossary, and the
172
+ semantic configuration. A fully cached rebuild does not need model credentials.
173
+
174
+ Cache hits, misses, writes, and errors are reported in `BuildResult.cache` and
175
+ in the CLI JSON output. Corrupt entries are ignored and rebuilt. If the cache
176
+ directory is not writable, the build continues and records a warning. The cache
177
+ is safe to delete.
178
+
179
+ ## Search an artifact
180
+
181
+ The `thesaurus_search` runtime is a separate lexical layer. It never calls
182
+ models, embeddings, or the network, and the Artifact API itself remains
183
+ read-only and search-free.
184
+
185
+ ```bash
186
+ uv run thesaurus-search query "robtóica" --artifact ./artifacts/feria-2026
187
+ uv run thesaurus-search query "pabell" --artifact ./artifacts/feria-2026 --mode prefix
188
+ uv run thesaurus-search query "robótica" --artifact ./artifacts/feria-2026 --mode exact
189
+ ```
190
+
191
+ **Fuzzy is the default.** Exact search must be requested explicitly:
192
+
193
+ | Mode | Behavior |
194
+ |---|---|
195
+ | `fuzzy` (default) | Exact + prefix + bounded typo correction + concept expansion |
196
+ | `prefix` | Exact + prefix completion, no typos |
197
+ | `exact` | Strict token equality only |
198
+
199
+ ```python
200
+ from thesaurus_search import SearchClient
201
+
202
+ client = SearchClient.open("./artifacts/feria-2026")
203
+ response = client.search("robtóica") # fuzzy
204
+ response = client.search("pabell", mode="prefix") # exact + prefix
205
+ response = client.search("robótica", mode="exact") # strict
206
+ ```
207
+
208
+ Fuzzy matching uses trigram candidates and bounded Damerau-Levenshtein
209
+ distance, with distance 1 allowed for tokens of 5–7 characters and distance 2
210
+ for longer tokens. Short tokens, codes, and numbers are not expanded. Results
211
+ are ranked with BM25 and include the exact, prefix, fuzzy, or expansion reason
212
+ for every match.
213
+
214
+ Filters include `language`, `view`, `statuses`, `field_paths`, and `form_types`.
215
+ The CLI also exposes `thesaurus-search stats`.
216
+
217
+ ## Browser search (vanilla JavaScript)
218
+
219
+ The `js/` directory contains a dependency-free browser client. It loads the
220
+ `.tar.gz` bundle directly, decompresses it with the native gzip stream, parses
221
+ the TAR, and searches locally. No npm, Node, bundler, server, or model is
222
+ required.
223
+
224
+ ```html
225
+ <script type="module">
226
+ import { SearchClient } from "./js/index.js";
227
+
228
+ const response = await fetch("./feria-2026.tar.gz");
229
+ const client = await SearchClient.fromBundle(response);
230
+
231
+ console.log(client.search("robtóica")); // fuzzy default
232
+ console.log(client.search("pabell", { mode: "prefix" }));
233
+ console.log(client.search("robótica", { mode: "exact" }));
234
+ </script>
235
+ ```
236
+
237
+ It implements the same modes, BM25 ranking, concept expansion, filters, and
238
+ result explanations as the Python runtime. See [`js/README.md`](js/README.md)
239
+ for the API and the browser test page.
240
+
241
+ ## Use the reader from Python
242
+
243
+ ```python
244
+ from thesaurus import Artifact
245
+
246
+ artifact = Artifact.open("./artifacts/feria-2026")
247
+
248
+ artifact.manifest
249
+ artifact.documents.get("doc-3")
250
+ artifact.fields.filter(document_id="doc-3")
251
+ artifact.forms.filter(language="en", type="query")
252
+ artifact.concepts.get("concept-robotics")
253
+ artifact.relations.filter(source_id="concept-robotics")
254
+ artifact.views.get("lang-en")
255
+
256
+ bundle = artifact.bundle("doc-3", include={"fields", "forms", "concepts"})
257
+ ```
258
+
259
+ Collections are lazy and indexed by id on first access. The reader never writes
260
+ to the artifact directory.
261
+
262
+ Validate an artifact before serving or publishing it:
263
+
264
+ ```bash
265
+ uv run thesaurus validate --artifact ./artifacts/feria-2026
266
+ uv run thesaurus validate --artifact ./artifacts/feria-2026 --json
267
+ ```
268
+
269
+ Validation checks manifest hashes, collection counts, unique ids, foreign keys,
270
+ form normalization, and view field paths.
271
+
272
+ ## Serve artifacts
273
+
274
+ ```bash
275
+ uv run thesaurus artifact-api --scan ./artifacts --port 8000
276
+ # or mount explicit directories
277
+ uv run thesaurus artifact-api \
278
+ --artifact ./artifacts/feria-2026 \
279
+ --artifact ./artifacts/feria-2025 \
280
+ --port 8000
281
+ ```
282
+
283
+ Main endpoints:
284
+
285
+ | Endpoint | Returns |
286
+ |---|---|
287
+ | `GET /artifacts` | Mounted artifacts |
288
+ | `GET /artifacts/{id}` | Manifest |
289
+ | `GET /artifacts/{id}/documents` | Documents |
290
+ | `GET /artifacts/{id}/documents/{doc_id}` | One document |
291
+ | `GET /artifacts/{id}/documents/{doc_id}/bundle` | Document + fields + forms + concepts + relations |
292
+ | `GET /artifacts/{id}/fields` | Fields |
293
+ | `GET /artifacts/{id}/forms` | Generated forms |
294
+ | `GET /artifacts/{id}/concepts` | Concepts |
295
+ | `GET /artifacts/{id}/relations` | Concept relations |
296
+ | `GET /artifacts/{id}/links` | Field/form → concept links |
297
+ | `GET /artifacts/{id}/views` | Views |
298
+ | `GET /artifacts/{id}/export` | tar.gz bundle of the artifact |
299
+
300
+ Listings support filters, pagination, sorting, and nested grouping:
301
+
302
+ ```bash
303
+ curl 'http://127.0.0.1:8000/artifacts/feria-2026/forms?language=en&type=query&limit=20'
304
+ curl 'http://127.0.0.1:8000/artifacts/feria-2026/forms?group_by=language,type'
305
+ ```
306
+
307
+ ```json
308
+ {
309
+ "data": {
310
+ "es": {"paraphrase": ["..."], "query": ["..."]},
311
+ "en": {"paraphrase": ["..."], "query": ["..."]}
312
+ },
313
+ "meta": {"group_by": ["language", "type"], "count": 42}
314
+ }
315
+ ```
316
+
317
+ Set `THESAURUS_ARTIFACT_TOKEN` to require `Authorization: Bearer <token>` or
318
+ `X-API-Key: <token>`. Send `SIGHUP` to rescan mounts without a restart.
319
+
320
+ ## Build over HTTP
321
+
322
+ ```bash
323
+ export THESAURUS_BUILD_TOKEN="change-me"
324
+ uv run thesaurus build-api --output ./artifacts --port 8001
325
+ ```
326
+
327
+ The Build API refuses to start without a token.
328
+
329
+ ```bash
330
+ curl -X POST http://127.0.0.1:8001/builds \
331
+ -H "Authorization: Bearer $THESAURUS_BUILD_TOKEN" \
332
+ -F config=@config.yaml \
333
+ -F corpus=@examples/corpus.jsonl \
334
+ -F artifact_id=feria-2026 \
335
+ -F serve=true
336
+ ```
337
+
338
+ Returns a job immediately:
339
+
340
+ ```json
341
+ {
342
+ "data": {
343
+ "build_id": "bld-01J...",
344
+ "status": "queued",
345
+ "links": {"self": "/builds/bld-01J...", "events": "/builds/bld-01J.../events"}
346
+ }
347
+ }
348
+ ```
349
+
350
+ | Endpoint | Purpose |
351
+ |---|---|
352
+ | `POST /builds` | Start a build |
353
+ | `GET /builds` | List jobs |
354
+ | `GET /builds/{id}` | Status, phase, progress, counts |
355
+ | `GET /builds/{id}/events` | Server-sent progress events |
356
+ | `GET /builds/{id}/result` | Artifact id, path, manifest, counts |
357
+ | `POST /builds/{id}/cancel` | Cancel a queued or running build |
358
+ | `DELETE /builds/{id}` | Remove the job and its uploads |
359
+ | `POST /servers` | Start an Artifact API for a directory |
360
+ | `GET /servers` | List managed Artifact APIs |
361
+ | `DELETE /servers/{id}` | Stop a managed Artifact API |
362
+
363
+ `serve=true` asks the Build API to launch an Artifact API for the output root
364
+ and return its URL. This is an in-process convenience for local use. In
365
+ production, run the Artifact API separately and point both services at the same
366
+ shared directory.
367
+
368
+ The handoff is the filesystem:
369
+
370
+ ```text
371
+ Build API writes {output_root}/{artifact_id}/
372
+ Artifact API mounts {output_root}/
373
+ Clients cross only artifact_id.
374
+ ```
375
+
376
+ ## Artifact layout
377
+
378
+ ```text
379
+ artifact/
380
+ manifest.json # format version, languages, models, counts, file hashes
381
+ documents.jsonl # original documents and fields
382
+ fields.jsonl # canonical fields + translated variants
383
+ forms.jsonl # paraphrases, queries, terms, answers
384
+ concepts.jsonl # reusable concepts with labels per language
385
+ relations.jsonl # typed concept relations
386
+ links.jsonl # field/form → concept links
387
+ views.json # named projections
388
+ audit.jsonl # build events
389
+ ```
390
+
391
+ The artifact is the source of truth. The reader and the Artifact API add no
392
+ state and no data.
393
+
394
+ ## Portable bundles
395
+
396
+ An artifact directory is portable as-is. To move it between machines, export it
397
+ as a tar.gz bundle, transfer the file, and extract it into the exact directory you
398
+ want to use:
399
+
400
+ ```bash
401
+ # Build into a chosen directory
402
+ uv run thesaurus build --config config.yaml --output ./artifacts/feria-2026
403
+
404
+ # Bundle it
405
+ uv run thesaurus export --artifact ./artifacts/feria-2026 --output ./feria-2026.tar.gz
406
+
407
+ # Extract into a chosen directory
408
+ uv run thesaurus extract --bundle ./feria-2026.tar.gz --output ./deploy/feria-2026
409
+
410
+ # Serve from the extracted path
411
+ uv run thesaurus artifact-api --artifact ./deploy/feria-2026 --port 8000
412
+ ```
413
+
414
+ Both the Python reader and the browser client can read a bundle directly,
415
+ without an explicit extraction step:
416
+
417
+ ```python
418
+ from thesaurus import Artifact
419
+
420
+ with Artifact.open("./feria-2026.tar.gz") as artifact:
421
+ print(artifact.artifact_id)
422
+ artifact.forms.filter(language="es")
423
+
424
+ Artifact.extract_bundle("./feria-2026.tar.gz", "./deploy/feria-2026")
425
+ artifact = Artifact.open("./deploy/feria-2026")
426
+ artifact.export_bundle("./backup.tar.gz")
427
+ ```
428
+
429
+ Bundles are validated on export and extract, reject unsafe paths, and contain
430
+ the artifact files at the archive root. There is no registry, object storage, or
431
+ publication service: the tar.gz file is the transport and the extracted
432
+ directory is what the Artifact API mounts.
433
+
434
+ ## How generation works
435
+
436
+ 1. The adapter reads JSON, JSONL, or CSV into canonical `Record` objects.
437
+ 2. Documents and fields are preserved; every field is a generation unit.
438
+ 3. The source field is translated per target language (default strategy).
439
+ 4. One structured LLM call per field and language produces candidates:
440
+ paraphrases, queries, key terms, a short answer, concepts, and relations.
441
+ 5. Candidates are embedded, filtered by a per-type threshold, reduced to a
442
+ Pareto front, and selected with greedy max-min diversity.
443
+ 6. Concepts are merged, relations deduplicated, and fields/forms linked.
444
+ 7. Views, audit events, and the layered artifact are written atomically.
445
+
446
+ Translation strategies:
447
+
448
+ - `translate_source` (default): translate the field, then generate per language.
449
+ - `translate_candidates`: generate in the source language, translate candidates.
450
+ - `select_then_translate`: select in the source language, translate selected forms.
451
+
452
+ Context modes: `field`, `document`, `auto` (default). `auto` uses the full
453
+ document when it fits; otherwise an extractive summary plus relevant sibling
454
+ fields and metadata.
455
+
456
+ ## Configuration
457
+
458
+ See [`config.example.yaml`](config.example.yaml). Semantic layers (concepts,
459
+ relations, views) are artifact data, not configuration.
460
+
461
+ An optional glossary is a YAML mapping from a source term to its translations:
462
+
463
+ ```yaml
464
+ # glossary.yaml
465
+ robótica:
466
+ en: robotics
467
+ fr: robotique
468
+ ```
469
+
470
+ ```yaml
471
+ translation:
472
+ glossary: glossary.yaml
473
+ preserve: [SKU, "Model X"]
474
+ ```
475
+
476
+ ## Development
477
+
478
+ ```bash
479
+ uv sync --extra api
480
+ uv run pytest -q
481
+ uv run ruff check .
482
+ ```
483
+
484
+ The test suite uses deterministic generator, translator, and embedder doubles;
485
+ no network or model credentials are required.
486
+
487
+ ## Status
488
+
489
+ MVP base implemented:
490
+
491
+ - [x] Execution configuration and validation
492
+ - [x] JSON/JSONL and CSV adapters with a registry
493
+ - [x] Field-level translation and candidate generation
494
+ - [x] Thresholds, Pareto front, and greedy max-min selection
495
+ - [x] Concepts, relations, links, views, and audit
496
+ - [x] Atomic layered artifact writer
497
+ - [x] Python artifact reader
498
+ - [x] Artifact validation with `thesaurus validate`
499
+ - [x] Portable tar.gz bundles with `export`, `extract`, and direct library reads
500
+ - [x] Incremental content-addressed build cache
501
+ - [x] Lexical search runtime with fuzzy default, prefix, and exact modes
502
+ - [x] Vanilla JavaScript browser search from a tar.gz bundle
503
+ - [x] Build API with jobs, progress, cancellation, and server lifecycle
504
+ - [x] Read-only Artifact API with filtering, grouping, bundles, and export
505
+ - [x] CLI: `build`, `build-api`, `artifact-api`, `inspect`, `validate`, `export`, `extract`, `thesaurus-search`
506
+
507
+ Not in the MVP: a search HTTP service, review UI, cross-artifact joins,
508
+ persistent job storage, and automatic publication/registries. The portable
509
+ artifact bundle is the supported transport. The Artifact API deliberately does
510
+ not search; `thesaurus_search` is the runtime consumer.
511
+
512
+ See [`docs/spec.md`](docs/spec.md) for the consolidated design.
513
+
514
+ ## License
515
+
516
+ MIT. See [`LICENSE`](LICENSE).
517
+
518
+ ## Changelog
519
+
520
+ See [`CHANGELOG.md`](CHANGELOG.md).