lens-xt 0.1.0b1__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 (41) hide show
  1. lens_xt-0.1.0b1/LICENSE +201 -0
  2. lens_xt-0.1.0b1/PKG-INFO +244 -0
  3. lens_xt-0.1.0b1/README.md +188 -0
  4. lens_xt-0.1.0b1/lens_xt/__init__.py +18 -0
  5. lens_xt-0.1.0b1/lens_xt.egg-info/PKG-INFO +244 -0
  6. lens_xt-0.1.0b1/lens_xt.egg-info/SOURCES.txt +39 -0
  7. lens_xt-0.1.0b1/lens_xt.egg-info/dependency_links.txt +1 -0
  8. lens_xt-0.1.0b1/lens_xt.egg-info/entry_points.txt +2 -0
  9. lens_xt-0.1.0b1/lens_xt.egg-info/requires.txt +34 -0
  10. lens_xt-0.1.0b1/lens_xt.egg-info/top_level.txt +2 -0
  11. lens_xt-0.1.0b1/lensx/__init__.py +68 -0
  12. lens_xt-0.1.0b1/lensx/ast.py +369 -0
  13. lens_xt-0.1.0b1/lensx/backends/__init__.py +42 -0
  14. lens_xt-0.1.0b1/lensx/backends/base.py +289 -0
  15. lens_xt-0.1.0b1/lensx/backends/local_mdlm.py +350 -0
  16. lens_xt-0.1.0b1/lensx/backends/openai_backend.py +333 -0
  17. lens_xt-0.1.0b1/lensx/cli.py +379 -0
  18. lens_xt-0.1.0b1/lensx/lock_resolver.py +416 -0
  19. lens_xt-0.1.0b1/lensx/parser.py +710 -0
  20. lens_xt-0.1.0b1/lensx/retrieval.py +144 -0
  21. lens_xt-0.1.0b1/lensx/retrieval_lattice.py +257 -0
  22. lens_xt-0.1.0b1/lensx/runtime.py +411 -0
  23. lens_xt-0.1.0b1/lensx/sdk.py +355 -0
  24. lens_xt-0.1.0b1/lensx/server.py +300 -0
  25. lens_xt-0.1.0b1/lensx/validator.py +211 -0
  26. lens_xt-0.1.0b1/pyproject.toml +105 -0
  27. lens_xt-0.1.0b1/setup.cfg +4 -0
  28. lens_xt-0.1.0b1/tests/test_backends_base.py +144 -0
  29. lens_xt-0.1.0b1/tests/test_cli.py +83 -0
  30. lens_xt-0.1.0b1/tests/test_examples.py +28 -0
  31. lens_xt-0.1.0b1/tests/test_local_mdlm.py +108 -0
  32. lens_xt-0.1.0b1/tests/test_lock_resolver.py +337 -0
  33. lens_xt-0.1.0b1/tests/test_openai_backend.py +377 -0
  34. lens_xt-0.1.0b1/tests/test_parser.py +487 -0
  35. lens_xt-0.1.0b1/tests/test_reasoning.py +283 -0
  36. lens_xt-0.1.0b1/tests/test_retrieval.py +173 -0
  37. lens_xt-0.1.0b1/tests/test_retrieval_lattice.py +287 -0
  38. lens_xt-0.1.0b1/tests/test_runtime.py +384 -0
  39. lens_xt-0.1.0b1/tests/test_sdk.py +343 -0
  40. lens_xt-0.1.0b1/tests/test_server.py +301 -0
  41. lens_xt-0.1.0b1/tests/test_validator.py +176 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Thomas Garren / SOPHIA XT LLC
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: lens-xt
3
+ Version: 0.1.0b1
4
+ Summary: A declarative specification language for deterministically constrained generation in discrete-sequence diffusion models
5
+ Author-email: Thomas Garren <thomas@sophiaxt.com>
6
+ Maintainer-email: Thomas Garren <thomas@sophiaxt.com>
7
+ License: Apache-2.0
8
+ Project-URL: Homepage, https://sophiaxt.com/lens-x-spec
9
+ Project-URL: Repository, https://github.com/Chorozion/lens-xt
10
+ Project-URL: Bug Tracker, https://github.com/Chorozion/lens-xt/issues
11
+ Project-URL: Specification, https://sophiaxt.com/lens-x-spec.pdf
12
+ Keywords: language-model,diffusion,masked-diffusion,constrained-generation,anchor-token-masking,forced-anchor-decoding,ltmi-xt,specification-language
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: pyyaml>=6.0
28
+ Requires-Dist: click>=8.0
29
+ Provides-Extra: local
30
+ Requires-Dist: torch>=2.1; extra == "local"
31
+ Requires-Dist: tokenizers>=0.15; extra == "local"
32
+ Provides-Extra: openai
33
+ Requires-Dist: openai>=1.40; extra == "openai"
34
+ Requires-Dist: tiktoken>=0.7; extra == "openai"
35
+ Provides-Extra: anthropic
36
+ Requires-Dist: anthropic>=0.30; extra == "anthropic"
37
+ Provides-Extra: server
38
+ Requires-Dist: fastapi>=0.110; extra == "server"
39
+ Requires-Dist: uvicorn[standard]>=0.27; extra == "server"
40
+ Requires-Dist: pydantic>=2.5; extra == "server"
41
+ Provides-Extra: all
42
+ Requires-Dist: torch>=2.1; extra == "all"
43
+ Requires-Dist: tokenizers>=0.15; extra == "all"
44
+ Requires-Dist: openai>=1.40; extra == "all"
45
+ Requires-Dist: tiktoken>=0.7; extra == "all"
46
+ Requires-Dist: anthropic>=0.30; extra == "all"
47
+ Requires-Dist: fastapi>=0.110; extra == "all"
48
+ Requires-Dist: uvicorn[standard]>=0.27; extra == "all"
49
+ Requires-Dist: pydantic>=2.5; extra == "all"
50
+ Provides-Extra: dev
51
+ Requires-Dist: pytest>=7.0; extra == "dev"
52
+ Requires-Dist: ruff>=0.4; extra == "dev"
53
+ Requires-Dist: mypy>=1.10; extra == "dev"
54
+ Requires-Dist: httpx>=0.27; extra == "dev"
55
+ Dynamic: license-file
56
+
57
+ <div align="center">
58
+
59
+ <img src="assets/lens-xt-banner.svg" alt="LENS-XT — declarative constrained generation for masked-diffusion language models" width="100%">
60
+
61
+ &nbsp;
62
+
63
+ [![License](https://img.shields.io/badge/runtime-Apache_2.0-00D4FF?style=flat-square&labelColor=050A15)](LICENSE)
64
+ [![Spec](https://img.shields.io/badge/spec-CC_BY_4.0-FFD93D?style=flat-square&labelColor=050A15)](https://creativecommons.org/licenses/by/4.0/)
65
+ [![Python](https://img.shields.io/badge/python-3.10+-00D4FF?style=flat-square&labelColor=050A15&logo=python&logoColor=white)](https://www.python.org/)
66
+ [![Tests](https://img.shields.io/badge/tests-176_passing-9BFFE8?style=flat-square&labelColor=050A15)](#status)
67
+ [![Backend](https://img.shields.io/badge/backend-Cassandra_T1.5-FFD93D?style=flat-square&labelColor=050A15)](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model)
68
+
69
+ **Declarative spec language for token-level deterministic generation in masked-diffusion LMs**
70
+
71
+ [Spec](https://sophiaxt.com/lens-x-spec.pdf) · [Research](https://sophiaxt.com/research/anchor-token-masking) · [Cassandra T1](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model) · [SOPHIA XT](https://sophiaxt.com)
72
+
73
+ </div>
74
+
75
+ ---
76
+
77
+ A `.lensx` document specifies **position-locked content, retrieval sources, adapter selection, and validation rules**. The runtime resolves the spec into a forced-anchor-decoded generation against the chosen backend. Locked positions are excluded from the unmasking loop — they cannot be overwritten across denoising steps.
78
+
79
+ ```yaml
80
+ # medical_basic.lensx
81
+ version: "0.1"
82
+ base:
83
+ model: "cassandra-t1.5"
84
+ locks:
85
+ - range: [0, auto]
86
+ source: locus("medical:cardiology:nitroglycerin:standard_dose")
87
+ generation:
88
+ total_length: 192
89
+ ```
90
+
91
+ ```bash
92
+ lensx run medical_basic.lensx
93
+ ```
94
+
95
+ The locked content appears at the exact positions you specified — *guaranteed by construction* on masked-diffusion backends, best-effort with logit-bias on autoregressive APIs.
96
+
97
+ ---
98
+
99
+ ## Why this exists
100
+
101
+ Existing approaches to constrained generation are imperative or grammar-based:
102
+
103
+ | Approach | What it constrains | Guarantee level |
104
+ |---|---|---|
105
+ | Prompt engineering | natural-language hints | **none** |
106
+ | OpenAI structured outputs / JSON mode | schema fields | type-level |
107
+ | Outlines / LMQL / Guidance | regex/CFG over output | type-level |
108
+ | JSON Schema validation | post-hoc check | retry on failure |
109
+ | **LENS-XT** | **token positions in the answer slot** | **DETERMINISTIC on MDLM, best-effort on API** |
110
+
111
+ LENS-XT separates *what to constrain* (the spec, CC BY 4.0) from *how to enforce it* (the runtime, Apache 2.0).
112
+
113
+ ## Status
114
+
115
+ > v0.1.0a1 — alpha. Runtime works end-to-end against the real Cassandra T1.5 model (`anchor_preservation_rate: 1.000`, DETERMINISTIC guarantee preserved). API surfaces may shift before v0.1.0.
116
+
117
+ | Component | Status |
118
+ |---|---|
119
+ | YAML parser + AST | ✅ shipped |
120
+ | Static validator | ✅ shipped |
121
+ | Lock resolver (literal / locus / retrieval / compose) | ✅ shipped |
122
+ | LTMi-XT keyword retrieval (v0.1) | ✅ shipped |
123
+ | LTMi-XT lattice-walk retrieval (v0.2 — BLAKE2b spec §2.4 compliant) | ✅ shipped |
124
+ | Reasoning scaffold runtime (multi-stage) | ✅ shipped |
125
+ | Local MDLM backend (Cassandra T1.5) | ✅ shipped |
126
+ | OpenAI API backend (logit-bias + retry, BEST_EFFORT guarantee) | ✅ shipped |
127
+ | Runtime orchestrator + CLI | ✅ shipped |
128
+ | Specification document | ✅ [Read the spec](https://sophiaxt.com/lens-x-spec.pdf) |
129
+ | Python SDK three-line drop-in | ✅ shipped |
130
+ | TypeScript SDK (`@sophiaxt/lens-xt`) | ✅ shipped |
131
+ | HTTP API server (FastAPI) | ✅ shipped |
132
+ | Anthropic API backend | 📋 planned |
133
+ | Mercury 2 native backend | 📋 pending Inception API support |
134
+
135
+ **Tests:** 168 unit + 8 backend tests passing, including a live integration against Cassandra T1.5 with `anchor_preservation_rate=1.0`.
136
+
137
+ ## Install
138
+
139
+ ```bash
140
+ pip install lens-xt # core (parser, validator, runtime)
141
+ pip install lens-xt[local] # adds torch + tokenizers for Cassandra backend
142
+ pip install lens-xt[all] # everything
143
+ ```
144
+
145
+ > Not on PyPI yet — install from source: `pip install -e .` from a clone of this repo.
146
+
147
+ ## Quick start
148
+
149
+ ```bash
150
+ # Validate a spec without running it
151
+ lensx validate examples/medical_basic.lensx
152
+
153
+ # Show a human-readable breakdown of the spec
154
+ lensx explain examples/medical_basic.lensx
155
+
156
+ # Run end-to-end against Cassandra T1.5
157
+ lensx run examples/medical_basic.lensx --var user_input="What's the dose?" --show-provenance
158
+ ```
159
+
160
+ Programmatic:
161
+
162
+ ```python
163
+ from lensx import run
164
+
165
+ result = run("examples/medical_basic.lensx", variables={"user_input": "..."})
166
+ print(result.text) # generated output
167
+ print(result.locked_positions_preserved) # True
168
+ print(result.achieved_guarantee) # GuaranteeLevel.DETERMINISTIC
169
+ print(result.metrics["anchor_preservation_rate"]) # 1.0
170
+ ```
171
+
172
+ ## Concepts
173
+
174
+ ### Locks
175
+
176
+ A *lock* is a contiguous range of token positions whose values are deterministically set by the spec, not the model. Lock content can come from:
177
+
178
+ - `literal("...")` — explicit text
179
+ - `locus("topic:subtopic:concept:slot")` — looked up by breadcrumb in an LTMi-XT bundle
180
+ - `retrieval[N]` — references the Nth retrieved locus from the `retrieval:` block
181
+ - `lensx_compose(path)` — composes another spec's output
182
+
183
+ Range types: `[start, end]` explicit; `[start, auto]` left-aligned auto-sized; `head(N)` / `tail(N)` / `at(N)` aligned-and-sized; mix freely.
184
+
185
+ ### Backends
186
+
187
+ The same `.lensx` file works across backends with different guarantee levels — the runtime picks the strongest available:
188
+
189
+ | Backend | Where it runs | Guarantee |
190
+ |---|---|---|
191
+ | Local MDLM | Cassandra T1.5, LLaDA, DiffuLLaMA (self-hosted) | **DETERMINISTIC** |
192
+ | API-compatible | OpenAI / Anthropic / Mercury 2 standard API | **BEST_EFFORT** (~99% via logit-bias + retry) |
193
+ | API-native | Future Mercury 2 with native lensx | **DETERMINISTIC** |
194
+ | Hybrid | API surround + local locked positions | **DETERMINISTIC** |
195
+
196
+ ### Retrieval — LTMi-XT lattice walk
197
+
198
+ LENS-XT's retrieval scorer uses the LTMi-XT lattice topology: loci sharing a *k*-prefix in their breadcrumb hierarchy share *k* lattice coordinates (BLAKE2b-derived per [LTMi-XT spec §2.4](https://sophiaxt.com/ltmi-xt-spec.pdf)). The `lattice` mode walks outward from keyword seeds in lattice space, surfacing topical neighbors that don't share enough surface keywords with the query but are spatially adjacent.
199
+
200
+ ```yaml
201
+ retrieval:
202
+ bundles: ["corpora/cardiology.ltmi"]
203
+ query: "${user_input}"
204
+ top_k: 3
205
+ scoring:
206
+ mode: lattice # or "keyword" for v0.1 behavior
207
+ ```
208
+
209
+ ### Adapters
210
+
211
+ LENS-XT works best with V/O-only anchor-token-masked LoRA adapters trained per domain. The methodology is empirically validated — **1.67× pooled OOD generalization advantage** over standard masking, with mechanism causally tested via V/O ablation.
212
+
213
+ → Read the visualized research: **[sophiaxt.com/research/anchor-token-masking](https://sophiaxt.com/research/anchor-token-masking)** *(or download the [PDF · 14 pp](https://sophiaxt.com/anchor-token-masking-arxiv.pdf))*
214
+
215
+ ## License
216
+
217
+ - **Reference runtime** (this repository): [Apache 2.0](LICENSE)
218
+ - **Specification document**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
219
+ - **Adapters**: community adapters under Apache 2.0; premium domain-specific adapters under commercial license
220
+
221
+ ## Citation
222
+
223
+ ```bibtex
224
+ @techreport{garren2026lensx,
225
+ author = {Garren, Thomas},
226
+ title = {LENS-XT v0.1: A Declarative Specification Language for
227
+ Deterministically Constrained Generation in
228
+ Discrete-Sequence Diffusion Models},
229
+ institution = {SOPHIA XT LLC},
230
+ year = {2026},
231
+ month = {May},
232
+ url = {https://sophiaxt.com/lens-x-spec}
233
+ }
234
+ ```
235
+
236
+ ## Related work
237
+
238
+ - [Cassandra T1](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model) — reference 1.3B masked-diffusion language model · Apache 2.0
239
+ - [LTMi-XT](https://sophiaxt.com/research/ltmi-xt) — retrieval format with hash-derived topological indexing · Apache 2.0
240
+ - [Anchor-Token Masking](https://sophiaxt.com/research/anchor-token-masking) — training methodology for V/O-only anchor-token-masked LoRA adapters · Apache 2.0
241
+
242
+ ## Maintainer
243
+
244
+ Thomas Garren · SOPHIA XT LLC · `thomas@sophiaxt.com` · [sophiaxt.com](https://sophiaxt.com)
@@ -0,0 +1,188 @@
1
+ <div align="center">
2
+
3
+ <img src="assets/lens-xt-banner.svg" alt="LENS-XT — declarative constrained generation for masked-diffusion language models" width="100%">
4
+
5
+ &nbsp;
6
+
7
+ [![License](https://img.shields.io/badge/runtime-Apache_2.0-00D4FF?style=flat-square&labelColor=050A15)](LICENSE)
8
+ [![Spec](https://img.shields.io/badge/spec-CC_BY_4.0-FFD93D?style=flat-square&labelColor=050A15)](https://creativecommons.org/licenses/by/4.0/)
9
+ [![Python](https://img.shields.io/badge/python-3.10+-00D4FF?style=flat-square&labelColor=050A15&logo=python&logoColor=white)](https://www.python.org/)
10
+ [![Tests](https://img.shields.io/badge/tests-176_passing-9BFFE8?style=flat-square&labelColor=050A15)](#status)
11
+ [![Backend](https://img.shields.io/badge/backend-Cassandra_T1.5-FFD93D?style=flat-square&labelColor=050A15)](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model)
12
+
13
+ **Declarative spec language for token-level deterministic generation in masked-diffusion LMs**
14
+
15
+ [Spec](https://sophiaxt.com/lens-x-spec.pdf) · [Research](https://sophiaxt.com/research/anchor-token-masking) · [Cassandra T1](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model) · [SOPHIA XT](https://sophiaxt.com)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ A `.lensx` document specifies **position-locked content, retrieval sources, adapter selection, and validation rules**. The runtime resolves the spec into a forced-anchor-decoded generation against the chosen backend. Locked positions are excluded from the unmasking loop — they cannot be overwritten across denoising steps.
22
+
23
+ ```yaml
24
+ # medical_basic.lensx
25
+ version: "0.1"
26
+ base:
27
+ model: "cassandra-t1.5"
28
+ locks:
29
+ - range: [0, auto]
30
+ source: locus("medical:cardiology:nitroglycerin:standard_dose")
31
+ generation:
32
+ total_length: 192
33
+ ```
34
+
35
+ ```bash
36
+ lensx run medical_basic.lensx
37
+ ```
38
+
39
+ The locked content appears at the exact positions you specified — *guaranteed by construction* on masked-diffusion backends, best-effort with logit-bias on autoregressive APIs.
40
+
41
+ ---
42
+
43
+ ## Why this exists
44
+
45
+ Existing approaches to constrained generation are imperative or grammar-based:
46
+
47
+ | Approach | What it constrains | Guarantee level |
48
+ |---|---|---|
49
+ | Prompt engineering | natural-language hints | **none** |
50
+ | OpenAI structured outputs / JSON mode | schema fields | type-level |
51
+ | Outlines / LMQL / Guidance | regex/CFG over output | type-level |
52
+ | JSON Schema validation | post-hoc check | retry on failure |
53
+ | **LENS-XT** | **token positions in the answer slot** | **DETERMINISTIC on MDLM, best-effort on API** |
54
+
55
+ LENS-XT separates *what to constrain* (the spec, CC BY 4.0) from *how to enforce it* (the runtime, Apache 2.0).
56
+
57
+ ## Status
58
+
59
+ > v0.1.0a1 — alpha. Runtime works end-to-end against the real Cassandra T1.5 model (`anchor_preservation_rate: 1.000`, DETERMINISTIC guarantee preserved). API surfaces may shift before v0.1.0.
60
+
61
+ | Component | Status |
62
+ |---|---|
63
+ | YAML parser + AST | ✅ shipped |
64
+ | Static validator | ✅ shipped |
65
+ | Lock resolver (literal / locus / retrieval / compose) | ✅ shipped |
66
+ | LTMi-XT keyword retrieval (v0.1) | ✅ shipped |
67
+ | LTMi-XT lattice-walk retrieval (v0.2 — BLAKE2b spec §2.4 compliant) | ✅ shipped |
68
+ | Reasoning scaffold runtime (multi-stage) | ✅ shipped |
69
+ | Local MDLM backend (Cassandra T1.5) | ✅ shipped |
70
+ | OpenAI API backend (logit-bias + retry, BEST_EFFORT guarantee) | ✅ shipped |
71
+ | Runtime orchestrator + CLI | ✅ shipped |
72
+ | Specification document | ✅ [Read the spec](https://sophiaxt.com/lens-x-spec.pdf) |
73
+ | Python SDK three-line drop-in | ✅ shipped |
74
+ | TypeScript SDK (`@sophiaxt/lens-xt`) | ✅ shipped |
75
+ | HTTP API server (FastAPI) | ✅ shipped |
76
+ | Anthropic API backend | 📋 planned |
77
+ | Mercury 2 native backend | 📋 pending Inception API support |
78
+
79
+ **Tests:** 168 unit + 8 backend tests passing, including a live integration against Cassandra T1.5 with `anchor_preservation_rate=1.0`.
80
+
81
+ ## Install
82
+
83
+ ```bash
84
+ pip install lens-xt # core (parser, validator, runtime)
85
+ pip install lens-xt[local] # adds torch + tokenizers for Cassandra backend
86
+ pip install lens-xt[all] # everything
87
+ ```
88
+
89
+ > Not on PyPI yet — install from source: `pip install -e .` from a clone of this repo.
90
+
91
+ ## Quick start
92
+
93
+ ```bash
94
+ # Validate a spec without running it
95
+ lensx validate examples/medical_basic.lensx
96
+
97
+ # Show a human-readable breakdown of the spec
98
+ lensx explain examples/medical_basic.lensx
99
+
100
+ # Run end-to-end against Cassandra T1.5
101
+ lensx run examples/medical_basic.lensx --var user_input="What's the dose?" --show-provenance
102
+ ```
103
+
104
+ Programmatic:
105
+
106
+ ```python
107
+ from lensx import run
108
+
109
+ result = run("examples/medical_basic.lensx", variables={"user_input": "..."})
110
+ print(result.text) # generated output
111
+ print(result.locked_positions_preserved) # True
112
+ print(result.achieved_guarantee) # GuaranteeLevel.DETERMINISTIC
113
+ print(result.metrics["anchor_preservation_rate"]) # 1.0
114
+ ```
115
+
116
+ ## Concepts
117
+
118
+ ### Locks
119
+
120
+ A *lock* is a contiguous range of token positions whose values are deterministically set by the spec, not the model. Lock content can come from:
121
+
122
+ - `literal("...")` — explicit text
123
+ - `locus("topic:subtopic:concept:slot")` — looked up by breadcrumb in an LTMi-XT bundle
124
+ - `retrieval[N]` — references the Nth retrieved locus from the `retrieval:` block
125
+ - `lensx_compose(path)` — composes another spec's output
126
+
127
+ Range types: `[start, end]` explicit; `[start, auto]` left-aligned auto-sized; `head(N)` / `tail(N)` / `at(N)` aligned-and-sized; mix freely.
128
+
129
+ ### Backends
130
+
131
+ The same `.lensx` file works across backends with different guarantee levels — the runtime picks the strongest available:
132
+
133
+ | Backend | Where it runs | Guarantee |
134
+ |---|---|---|
135
+ | Local MDLM | Cassandra T1.5, LLaDA, DiffuLLaMA (self-hosted) | **DETERMINISTIC** |
136
+ | API-compatible | OpenAI / Anthropic / Mercury 2 standard API | **BEST_EFFORT** (~99% via logit-bias + retry) |
137
+ | API-native | Future Mercury 2 with native lensx | **DETERMINISTIC** |
138
+ | Hybrid | API surround + local locked positions | **DETERMINISTIC** |
139
+
140
+ ### Retrieval — LTMi-XT lattice walk
141
+
142
+ LENS-XT's retrieval scorer uses the LTMi-XT lattice topology: loci sharing a *k*-prefix in their breadcrumb hierarchy share *k* lattice coordinates (BLAKE2b-derived per [LTMi-XT spec §2.4](https://sophiaxt.com/ltmi-xt-spec.pdf)). The `lattice` mode walks outward from keyword seeds in lattice space, surfacing topical neighbors that don't share enough surface keywords with the query but are spatially adjacent.
143
+
144
+ ```yaml
145
+ retrieval:
146
+ bundles: ["corpora/cardiology.ltmi"]
147
+ query: "${user_input}"
148
+ top_k: 3
149
+ scoring:
150
+ mode: lattice # or "keyword" for v0.1 behavior
151
+ ```
152
+
153
+ ### Adapters
154
+
155
+ LENS-XT works best with V/O-only anchor-token-masked LoRA adapters trained per domain. The methodology is empirically validated — **1.67× pooled OOD generalization advantage** over standard masking, with mechanism causally tested via V/O ablation.
156
+
157
+ → Read the visualized research: **[sophiaxt.com/research/anchor-token-masking](https://sophiaxt.com/research/anchor-token-masking)** *(or download the [PDF · 14 pp](https://sophiaxt.com/anchor-token-masking-arxiv.pdf))*
158
+
159
+ ## License
160
+
161
+ - **Reference runtime** (this repository): [Apache 2.0](LICENSE)
162
+ - **Specification document**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
163
+ - **Adapters**: community adapters under Apache 2.0; premium domain-specific adapters under commercial license
164
+
165
+ ## Citation
166
+
167
+ ```bibtex
168
+ @techreport{garren2026lensx,
169
+ author = {Garren, Thomas},
170
+ title = {LENS-XT v0.1: A Declarative Specification Language for
171
+ Deterministically Constrained Generation in
172
+ Discrete-Sequence Diffusion Models},
173
+ institution = {SOPHIA XT LLC},
174
+ year = {2026},
175
+ month = {May},
176
+ url = {https://sophiaxt.com/lens-x-spec}
177
+ }
178
+ ```
179
+
180
+ ## Related work
181
+
182
+ - [Cassandra T1](https://github.com/Chorozion/Casandra-t1-diffusion-edge-model) — reference 1.3B masked-diffusion language model · Apache 2.0
183
+ - [LTMi-XT](https://sophiaxt.com/research/ltmi-xt) — retrieval format with hash-derived topological indexing · Apache 2.0
184
+ - [Anchor-Token Masking](https://sophiaxt.com/research/anchor-token-masking) — training methodology for V/O-only anchor-token-masked LoRA adapters · Apache 2.0
185
+
186
+ ## Maintainer
187
+
188
+ Thomas Garren · SOPHIA XT LLC · `thomas@sophiaxt.com` · [sophiaxt.com](https://sophiaxt.com)
@@ -0,0 +1,18 @@
1
+ """``lens_xt`` — PEP-8 import alias for the ``lensx`` package.
2
+
3
+ Both spellings work and resolve to the same module:
4
+
5
+ from lens_xt import LensX # PEP-8 form (matches `lens-xt` distribution name)
6
+ from lensx import LensX # short form (matches CLI binary name)
7
+
8
+ This shim re-exports everything from ``lensx`` so any future additions to
9
+ the public API stay in sync without code changes here.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import lensx as _lensx
14
+ from lensx import * # noqa: F401, F403 -- re-export every public name
15
+
16
+ # Mirror metadata for tools that introspect __version__ via the alias name
17
+ __version__ = _lensx.__version__
18
+ __all__ = list(_lensx.__all__)