fieldkit 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.
@@ -0,0 +1,48 @@
1
+ # build output
2
+ dist/
3
+ .astro/
4
+
5
+ # dependencies
6
+ node_modules/
7
+
8
+ # logs
9
+ npm-debug.log*
10
+ yarn-debug.log*
11
+ yarn-error.log*
12
+ pnpm-debug.log*
13
+
14
+ # environment variables
15
+ .env
16
+ .env.production
17
+
18
+ # macOS-specific files
19
+ .DS_Store
20
+
21
+ # jetbrains setting folder
22
+ .idea/
23
+
24
+ # local-only working material (not for the public blog)
25
+ ideas/
26
+ HANDOFF.md
27
+ .claude/
28
+
29
+ # transient vibe-test artifacts (Playwright screenshots written to repo root)
30
+ .playwright-mcp/
31
+ /*.png
32
+
33
+ # bench-run outputs land inside articles/<slug>/evidence/runs/ — bulky, not for git
34
+ articles/*/evidence/runs/
35
+
36
+ __pycache__/
37
+
38
+ # fieldkit Python build / venv detritus (keep alongside the package, not committed)
39
+ fieldkit/build/
40
+ fieldkit/dist/
41
+ fieldkit/*.egg-info/
42
+ fieldkit/.pytest_cache/
43
+ fieldkit/.mypy_cache/
44
+ fieldkit/.ruff_cache/
45
+ fieldkit/.venv/
46
+ fieldkit/src/fieldkit.egg-info/
47
+ *.pyc
48
+
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ All notable changes to `fieldkit` are documented in this file.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). While the package is on `0.x`, minor versions may include breaking changes. `1.0` will mark API stability.
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] — 2026-05-02
10
+
11
+ First public release. Four library modules + a CLI + a docs site section, lifted from 25+ articles in [ai-field-notes](https://ainative.business/field-notes/).
12
+
13
+ ### Added
14
+
15
+ - **`fieldkit.capabilities`** — typed Python facade over `spark-capabilities.json`. `Capabilities.load()` cached singleton (with `.hardware`, `.memory_budget_rules_of_thumb`, `.stack`, `.in_envelope_signals`, `.out_of_envelope_signals`, `.stage_routing_hints`, `.series_routing_hints`), plus canonical math helpers `kv_cache_bytes()`, `weight_bytes()`, `practical_inference_envelope()`. Numbers pinned to `kv-cache-arithmetic-at-inference` and `gpu-sizing-math-for-fine-tuning`. ([#capabilities])
16
+ - **`fieldkit.nim`** — OpenAI-compatible `NIMClient` over `httpx` with `tenacity`-backed retries on 429 / 503 / `ConnectError` / timeouts. `NIMClient.chat()` runs a pre-flight context check and raises `NIMContextOverflowError` with the estimated token count *before any network call*, so the opaque NIM 400 from a >8192-token request never surfaces. Helpers: `chunk_text()` (paragraph→sentence→word splitting under a `max_tokens` budget), `estimate_tokens()` (1 tok ≈ 4 chars), `wait_for_warm()` (polls `/v1/models` for the ~90s NIM cold start). Constants: `NIM_CONTEXT_WINDOW = 8192`, `DEFAULT_CHUNK_TOKENS = 1024`. Errors: `NIMError` → `NIMHTTPError`, `NIMTimeoutError`, `NIMContextOverflowError`. ([#nim])
17
+ - **`fieldkit.rag`** — composable ingest → retrieve → rerank → fuse pipeline backed by pgvector + a NIM embedder + the strict-context grounded prompt from `naive-rag-on-spark`. `Pipeline.ingest()` chunks via `fieldkit.nim.chunk_text` and upserts in batches of 32; `Pipeline.retrieve()` does pgvector cosine top-K; `Pipeline.rerank()` is a pass-through when `rerank_url=None`; `Pipeline.fuse()` builds the strict-context messages list and calls the generator; `Pipeline.ask()` chains all three. Embed and rerank inherit `NIMClient.chat`'s retry policy so co-resident memory pressure doesn't fail the pipeline. ([#rag])
18
+ - **`fieldkit.eval`** — `Bench` (latency aggregation with the same `{summary, calls}` JSON shape as the article evidence files), `Judge` (LLM-as-judge with built-in `correctness` / `faithfulness` / `relevance` rubrics + a static `Judge.parse()` JSON-then-regex extractor), `Trajectory` (agent-loop JSONL analyzer with `knob_coverage / repeat_rate / mode_dominance / cumulative_best`), `is_refusal()` (regex catalog unioned across the project's articles), `summarize_metric()`. ([#eval])
19
+ - **`fieldkit.cli`** — Typer wrapper exposing `fieldkit version`, `fieldkit envelope <size>`, `fieldkit feasibility <model_id> [--ctx --batch --dtype]`, `fieldkit bench rag`. On `$PATH` after `pip install`. ([#cli])
20
+ - **Astro docs site** — `/fieldkit/` landing page with install + quickstart + module grid, and `/fieldkit/api/<module>/` reference pages backed by a new `fieldkit_docs` content collection. Articles can opt-in via `fieldkit_modules:` frontmatter to display a "USES fieldkit.X" chip on cards and appear under each module's "Articles that use fieldkit.<module>" footer. 11 articles opted in for the v0.1.0 launch.
21
+ - **Samples**: `samples/feasibility-math.py` (capabilities reproduction of the kv-cache article's table), `samples/hello-nim.py` (Python equivalent of the curl one-liner), `samples/naive-rag.py` (end-to-end RAG in <30 lines), `samples/bench-rag.py` (offline `Bench` + `Judge.parse()` walkthrough).
22
+ - `scripts/sync_capabilities.py` keeps the package-bundled `spark-capabilities.json` in sync with the source-of-truth at `scripts/lib/spark-capabilities.json` (pre-commit-enforced).
23
+ - `pytest --spark` flag (via `tests/conftest.py`) gates integration tests that need a live NIM / pgvector on the DGX Spark; default runs skip them.
24
+
25
+ ### Changed
26
+
27
+ - `frontier-scout` skill (`refresh` and `eval` modes, plus `references/feasibility-prompt.md` and `references/classifier-prompt.md`) now teaches the typed `from fieldkit.capabilities import …` API as the preferred grounding path; raw JSON read is the documented fallback.
28
+
29
+ ### Verified on Spark
30
+
31
+ Phases 3, 4, 5 were live-verified end-to-end against the chat NIM (Llama 3.1 8B, port 8000), the embed NIM (Nemotron Embed 1B v2, port 8001), and pgvector (port 5432) before being committed. Phase 5 in particular rewrote `articles/naive-rag-on-spark/evidence/benchmark.py` against `fieldkit.eval.Bench` + `fieldkit.rag.Pipeline.fuse` and reproduced the original article's behavioral fingerprint (5 of 6 refusals incl. the canonical Google-IPO false refusal, plus the Ian Thorpe grounded answer).
32
+
33
+ ### Test suite
34
+
35
+ **157 passing, 2 skipped** without `--spark` (151 passing with `--spark` against warm NIMs + pgvector). Reproduce: `pip install fieldkit/[dev]` then `pytest`; for the live tests, `pytest --spark`.
36
+
37
+ [#capabilities]: https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit/src/fieldkit/capabilities
38
+ [#nim]: https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit/src/fieldkit/nim
39
+ [#rag]: https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit/src/fieldkit/rag
40
+ [#eval]: https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit/src/fieldkit/eval
41
+ [#cli]: https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit/src/fieldkit/cli
fieldkit-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.4
2
+ Name: fieldkit
3
+ Version: 0.1.0
4
+ Summary: Verified-on-Spark patterns lifted from the ai-field-notes blog into one importable Python package.
5
+ Project-URL: Homepage, https://ainative.business/fieldkit/
6
+ Project-URL: Source, https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit
7
+ Project-URL: Changelog, https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/manavsehgal/ai-field-notes/issues
9
+ Author-email: Manav Sehgal <sehgal.manav@gmail.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agents,dgx-spark,llm,nim,nvidia,rag
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: numpy>=1.26
24
+ Requires-Dist: psycopg[binary]>=3.2
25
+ Requires-Dist: tenacity>=8.5
26
+ Requires-Dist: typer>=0.12
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.2; extra == 'dev'
29
+ Requires-Dist: mypy>=1.11; extra == 'dev'
30
+ Requires-Dist: pre-commit>=3.7; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
32
+ Requires-Dist: pytest>=8.2; extra == 'dev'
33
+ Requires-Dist: respx>=0.21; extra == 'dev'
34
+ Requires-Dist: ruff>=0.6; extra == 'dev'
35
+ Requires-Dist: twine>=5.0; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # fieldkit
39
+
40
+ > Verified-on-Spark patterns lifted from the [ai-field-notes](https://ainative.business/field-notes/) blog into one importable Python package.
41
+
42
+ Every essay in `ai-field-notes` ends with `evidence/` — a folder of working code that produced the article's numbers. After 25+ articles the same patterns kept reappearing: the same NIM client wrapper, the same chunk-embed-store dance, the same bench harness. `fieldkit` is what those `evidence/` folders look like once the boilerplate is lifted into a real package.
43
+
44
+ The blog stays the long-form rationale. `fieldkit` is the `pip install`-able surface so you can reproduce — and extend — the work without re-pasting 80 lines of NIM-client setup per article.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install fieldkit
50
+ ```
51
+
52
+ For the bleeding edge between releases, install from the git tag instead:
53
+
54
+ ```bash
55
+ pip install "git+https://github.com/manavsehgal/ai-field-notes.git@fieldkit/v0.1.0#subdirectory=fieldkit"
56
+ ```
57
+
58
+ ## Quickstart
59
+
60
+ ```python
61
+ from fieldkit.nim import NIMClient
62
+
63
+ client = NIMClient(base_url="http://localhost:8000/v1", model="meta/llama-3.1-8b-instruct")
64
+ print(client.chat([{"role": "user", "content": "Hello, Spark."}]))
65
+ ```
66
+
67
+ ## What's in v0.1.0
68
+
69
+ | Module | Purpose | Source articles |
70
+ |---|---|---|
71
+ | `fieldkit.capabilities` | Typed Python facade over `spark-capabilities.json` — KV cache math, weight bytes, inference envelope. | `kv-cache-arithmetic-at-inference`, `gpu-sizing-math-for-fine-tuning` |
72
+ | `fieldkit.nim` | OpenAI-compatible NIM client wrapper with retry, chunking, and the 8192-token context guard. | `nim-first-inference-dgx-spark` and friends |
73
+ | `fieldkit.rag` | `Pipeline(embed_url, rerank_url, pgvector_dsn, generator)` — ingest → retrieve → rerank → fuse. | `naive-rag-on-spark` and friends |
74
+ | `fieldkit.eval` | `Bench`, `Judge`, `Trajectory` — the recurring eval harness shapes. | every article with a `bench.py` or `benchmark.py` |
75
+ | `fieldkit.cli` | `fieldkit bench rag`, `fieldkit feasibility <id>`, `fieldkit envelope <size>`. | discoverability |
76
+
77
+ Modules deferred to `v0.2`: `retriever`, `ft`, `guardrails`, `agents`. To `v0.3`: `train`, `observe`.
78
+
79
+ ## Hardware
80
+
81
+ `v0.1` is **Spark-only**. Every code path is verified on a DGX Spark (GB10, 128 GB unified memory, NIM 8B + embed NIM + pgvector co-resident). Portability to other CUDA 12.x boxes lands in `v0.2+` when there's demand.
82
+
83
+ ## License
84
+
85
+ Apache-2.0. See [`LICENSE`](https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/LICENSE).
86
+
87
+ ## Links
88
+
89
+ - **Blog:** https://ainative.business/field-notes/
90
+ - **Docs:** https://ainative.business/fieldkit/
91
+ - **Source:** https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit
92
+ - **Changelog:** [`CHANGELOG.md`](https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/CHANGELOG.md)
@@ -0,0 +1,55 @@
1
+ # fieldkit
2
+
3
+ > Verified-on-Spark patterns lifted from the [ai-field-notes](https://ainative.business/field-notes/) blog into one importable Python package.
4
+
5
+ Every essay in `ai-field-notes` ends with `evidence/` — a folder of working code that produced the article's numbers. After 25+ articles the same patterns kept reappearing: the same NIM client wrapper, the same chunk-embed-store dance, the same bench harness. `fieldkit` is what those `evidence/` folders look like once the boilerplate is lifted into a real package.
6
+
7
+ The blog stays the long-form rationale. `fieldkit` is the `pip install`-able surface so you can reproduce — and extend — the work without re-pasting 80 lines of NIM-client setup per article.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install fieldkit
13
+ ```
14
+
15
+ For the bleeding edge between releases, install from the git tag instead:
16
+
17
+ ```bash
18
+ pip install "git+https://github.com/manavsehgal/ai-field-notes.git@fieldkit/v0.1.0#subdirectory=fieldkit"
19
+ ```
20
+
21
+ ## Quickstart
22
+
23
+ ```python
24
+ from fieldkit.nim import NIMClient
25
+
26
+ client = NIMClient(base_url="http://localhost:8000/v1", model="meta/llama-3.1-8b-instruct")
27
+ print(client.chat([{"role": "user", "content": "Hello, Spark."}]))
28
+ ```
29
+
30
+ ## What's in v0.1.0
31
+
32
+ | Module | Purpose | Source articles |
33
+ |---|---|---|
34
+ | `fieldkit.capabilities` | Typed Python facade over `spark-capabilities.json` — KV cache math, weight bytes, inference envelope. | `kv-cache-arithmetic-at-inference`, `gpu-sizing-math-for-fine-tuning` |
35
+ | `fieldkit.nim` | OpenAI-compatible NIM client wrapper with retry, chunking, and the 8192-token context guard. | `nim-first-inference-dgx-spark` and friends |
36
+ | `fieldkit.rag` | `Pipeline(embed_url, rerank_url, pgvector_dsn, generator)` — ingest → retrieve → rerank → fuse. | `naive-rag-on-spark` and friends |
37
+ | `fieldkit.eval` | `Bench`, `Judge`, `Trajectory` — the recurring eval harness shapes. | every article with a `bench.py` or `benchmark.py` |
38
+ | `fieldkit.cli` | `fieldkit bench rag`, `fieldkit feasibility <id>`, `fieldkit envelope <size>`. | discoverability |
39
+
40
+ Modules deferred to `v0.2`: `retriever`, `ft`, `guardrails`, `agents`. To `v0.3`: `train`, `observe`.
41
+
42
+ ## Hardware
43
+
44
+ `v0.1` is **Spark-only**. Every code path is verified on a DGX Spark (GB10, 128 GB unified memory, NIM 8B + embed NIM + pgvector co-resident). Portability to other CUDA 12.x boxes lands in `v0.2+` when there's demand.
45
+
46
+ ## License
47
+
48
+ Apache-2.0. See [`LICENSE`](https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/LICENSE).
49
+
50
+ ## Links
51
+
52
+ - **Blog:** https://ainative.business/field-notes/
53
+ - **Docs:** https://ainative.business/fieldkit/
54
+ - **Source:** https://github.com/manavsehgal/ai-field-notes/tree/main/fieldkit
55
+ - **Changelog:** [`CHANGELOG.md`](https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/CHANGELOG.md)
@@ -0,0 +1,98 @@
1
+ ---
2
+ module: capabilities
3
+ title: fieldkit.capabilities
4
+ summary: Typed Python facade over the project's Spark capabilities map. Canonical KV-cache and weight arithmetic.
5
+ order: 1
6
+ ---
7
+
8
+ ## What it is
9
+
10
+ A read-only typed view of `spark-capabilities.json` — the project's grounding floor for hardware envelope claims (KV-cache math, weight memory, in/out-envelope signals, NIM/NeMo/TRT-LLM stack notes). The same JSON the `frontier-scout` skill uses to decide whether a paper fits on the Spark.
11
+
12
+ The package keeps its own copy of the JSON in sync with the source-of-truth at `scripts/lib/spark-capabilities.json` via a pre-commit drift check.
13
+
14
+ ## Public API
15
+
16
+ ```python
17
+ from fieldkit.capabilities import (
18
+ Capabilities,
19
+ kv_cache_bytes,
20
+ weight_bytes,
21
+ practical_inference_envelope,
22
+ DTYPE_BYTES,
23
+ UnknownDtype,
24
+ UnknownEnvelope,
25
+ )
26
+ ```
27
+
28
+ ### `Capabilities.load(refresh=False) -> Capabilities`
29
+
30
+ Cached singleton typed view. Pass `refresh=True` to force a re-read from disk.
31
+
32
+ ```python
33
+ caps = Capabilities.load()
34
+ caps.hardware.unified_memory_gb # 128
35
+ caps.hardware.compute_arch # "GB10 Grace Blackwell"
36
+ caps.memory_budget_rules_of_thumb.practical_inference_envelope
37
+ caps.stack["nim"].verified_in_articles
38
+ caps.in_envelope_signals # tuple[str, ...]
39
+ caps.out_of_envelope_signals
40
+ caps.stage_routing_hints # {"inference": "...", ...}
41
+ caps.raw # full JSON dict for ad-hoc inspection
42
+ ```
43
+
44
+ ### `kv_cache_bytes(*, hidden, n_layers, ctx, batch, dtype) -> int`
45
+
46
+ Canonical KV-cache equation from `kv-cache-arithmetic-at-inference`:
47
+
48
+ ```
49
+ KV bytes = 2 × n_layers × kv_hidden × ctx × batch × bytes_per_dtype
50
+ ```
51
+
52
+ `hidden` here is the **KV hidden size** (`n_kv_heads × head_dim`), not the model's full hidden dim — important for GQA models like Llama 3.1 70B (8 KV heads × 128 head_dim = 1024).
53
+
54
+ ```python
55
+ kv_cache_bytes(hidden=1024, n_layers=80, ctx=16384, batch=32, dtype="fp16")
56
+ # 171_798_691_840 (≈ 171.8 GB)
57
+ ```
58
+
59
+ ### `weight_bytes(*, params_b, dtype) -> int`
60
+
61
+ Weight memory in bytes for `params_b` billion parameters at `dtype`.
62
+
63
+ ```python
64
+ weight_bytes(params_b=70, dtype="bf16") # 140_000_000_000 (140 GB)
65
+ weight_bytes(params_b=100, dtype="fp8") # 100_000_000_000 (100 GB)
66
+ weight_bytes(params_b=100, dtype="nf4") # 50_000_000_000 ( 50 GB)
67
+ ```
68
+
69
+ ### `practical_inference_envelope(model_size: str) -> str`
70
+
71
+ Look up the rule-of-thumb envelope string for a model size.
72
+
73
+ ```python
74
+ practical_inference_envelope("8B params bf16")
75
+ # "fits with room — ~16 GB weights + KV; 24.8 tok/s measured on NIM"
76
+
77
+ practical_inference_envelope("70B params fp8")
78
+ # "~70 GB weights; leaves ~50 GB for KV + activations + system; tight but possible"
79
+ ```
80
+
81
+ Raises `UnknownEnvelope` if no rule matches.
82
+
83
+ ### `DTYPE_BYTES`
84
+
85
+ Bytes-per-parameter table:
86
+
87
+ | dtype | bytes |
88
+ |---|---|
89
+ | `fp32` | 4 |
90
+ | `bf16` / `fp16` | 2 |
91
+ | `fp8` / `int8` | 1 |
92
+ | `int4` / `nf4` | 0.5 |
93
+
94
+ Unknown dtype → `UnknownDtype`.
95
+
96
+ ## Sample
97
+
98
+ [`samples/feasibility-math.py`](https://github.com/manavsehgal/ai-field-notes/blob/main/fieldkit/samples/feasibility-math.py) reproduces the kv-cache article's serving table, the 100B Nemotron weight table, and the envelope lookup, all via the public API.
@@ -0,0 +1,74 @@
1
+ ---
2
+ module: cli
3
+ title: fieldkit (CLI)
4
+ summary: A thin Typer wrapper over the four modules. Quick checks and smoke benchmarks without writing Python.
5
+ order: 5
6
+ ---
7
+
8
+ ## What it is
9
+
10
+ A thin command-line entry point exposed at `fieldkit` after `pip install`. Every subcommand is a ~20-line wrapper over the existing module APIs — for real workloads, import `fieldkit.{capabilities,nim,rag,eval}` directly instead.
11
+
12
+ ## Commands
13
+
14
+ ### `fieldkit version`
15
+
16
+ Print the installed package version.
17
+
18
+ ```bash
19
+ $ fieldkit version
20
+ 0.1.0.dev0
21
+ ```
22
+
23
+ ### `fieldkit envelope <size>`
24
+
25
+ Look up the practical inference envelope rule for a model size from `spark-capabilities.json`.
26
+
27
+ ```bash
28
+ $ fieldkit envelope "70B params fp8"
29
+ ~70 GB weights; leaves ~50 GB for KV + activations + system; tight but possible
30
+
31
+ $ fieldkit envelope "8B params bf16"
32
+ fits with room — ~16 GB weights + KV; 24.8 tok/s measured on NIM
33
+ ```
34
+
35
+ Unknown size → exit code 2 with the list of known keys.
36
+
37
+ ### `fieldkit feasibility <model_id>`
38
+
39
+ Quick weights + KV-cache feasibility view for a known shape. Built-in catalog: `llama-3.1-8b`, `llama-3.1-70b`, `100b-bf16`.
40
+
41
+ ```bash
42
+ $ fieldkit feasibility llama-3.1-70b --ctx 4096 --batch 32 --dtype fp8
43
+ model: llama-3.1-70b
44
+ hardware: NVIDIA DGX Spark (GB10 Grace Blackwell) — 128 GB unified
45
+ weights (fp8): 70.0 GB
46
+ KV cache (fp8): 21.5 GB (ctx=4096, batch=32)
47
+ weights + KV: 91.5 GB
48
+ envelope rule: ~70 GB weights; leaves ~50 GB for KV + activations + system; tight but possible
49
+ ```
50
+
51
+ Flags:
52
+
53
+ | Flag | Default | Notes |
54
+ |---|---|---|
55
+ | `--ctx` | 4096 | Context length in tokens |
56
+ | `--batch` | 1 | Concurrency / batch size |
57
+ | `--dtype` | fp16 | `fp32`, `bf16`, `fp16`, `fp8`, `int8`, `int4`, `nf4` |
58
+
59
+ ### `fieldkit bench rag`
60
+
61
+ Smoke-bench `Pipeline.ask` against a 3-doc in-memory corpus. Requires the chat NIM, embed NIM, and pgvector to be reachable.
62
+
63
+ ```bash
64
+ $ fieldkit bench rag --table fieldkit_cli_bench_rag --out /tmp/bench.json
65
+ waiting for embed NIM at http://localhost:8001/v1 ...
66
+ waiting for chat NIM at http://localhost:8000/v1 ...
67
+ ingested 3 chunks into fieldkit_cli_bench_rag
68
+
69
+ | call | latency_ms | success |
70
+ |---|---|---|
71
+ | ... |
72
+ ```
73
+
74
+ Env vars: `EMBED_BASE_URL`, `NIM_BASE_URL`, `NIM_MODEL`, `PGVECTOR_DSN`. Each has a matching `--flag` form.