contextir 1.0.1__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.
- contextir-1.0.1/.gitignore +10 -0
- contextir-1.0.1/CHANGELOG.md +101 -0
- contextir-1.0.1/LICENSE +201 -0
- contextir-1.0.1/NOTICE +7 -0
- contextir-1.0.1/PKG-INFO +244 -0
- contextir-1.0.1/README.md +209 -0
- contextir-1.0.1/THIRD_PARTY_NOTICES.md +59 -0
- contextir-1.0.1/contextir/__init__.py +23 -0
- contextir-1.0.1/contextir/clients.py +180 -0
- contextir-1.0.1/contextir/dataset.py +121 -0
- contextir-1.0.1/contextir/evaluation/__init__.py +1 -0
- contextir-1.0.1/contextir/evaluation/metrics.py +94 -0
- contextir-1.0.1/contextir/gateway.py +757 -0
- contextir-1.0.1/contextir/models/__init__.py +1 -0
- contextir-1.0.1/contextir/models/baseline_translator.py +26 -0
- contextir-1.0.1/contextir/models/semantic_encoder.py +101 -0
- contextir-1.0.1/contextir/models/semantic_translator.py +74 -0
- contextir-1.0.1/contextir/pipeline.py +336 -0
- contextir-1.0.1/contextir/py.typed +1 -0
- contextir-1.0.1/contextir/schemas/__init__.py +13 -0
- contextir-1.0.1/contextir/schemas/contextir_contract_v2.schema.json +165 -0
- contextir-1.0.1/contextir/sir_dataset_export.py +172 -0
- contextir-1.0.1/contextir/sir_graph.py +155 -0
- contextir-1.0.1/contextir/sir_graph_core.py +261 -0
- contextir-1.0.1/contextir/sir_graph_embedding_core.py +306 -0
- contextir-1.0.1/contextir/sir_ml_core.py +253 -0
- contextir-1.0.1/contextir/sir_neural_kernel.py +287 -0
- contextir-1.0.1/contextir/sir_roundtrip.py +313 -0
- contextir-1.0.1/contextir/sir_runtime.py +543 -0
- contextir-1.0.1/contextir/sir_sources.py +328 -0
- contextir-1.0.1/contextir/tokenizer.py +20 -0
- contextir-1.0.1/contextir/utils/__init__.py +1 -0
- contextir-1.0.1/contextir/utils/config.py +17 -0
- contextir-1.0.1/contextir/utils/seed.py +12 -0
- contextir-1.0.1/pyproject.toml +65 -0
- contextir-1.0.1/tests/test_clients.py +88 -0
- contextir-1.0.1/tests/test_gateway.py +232 -0
- contextir-1.0.1/tests/test_pipeline.py +214 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to ContextIR are documented here.
|
|
4
|
+
|
|
5
|
+
## 1.0.1 - 2026-07-19
|
|
6
|
+
|
|
7
|
+
- added PyPI Trusted Publishing through GitHub Actions OIDC;
|
|
8
|
+
- split release validation, GitHub publication, and PyPI publication into
|
|
9
|
+
separate least-privilege jobs;
|
|
10
|
+
- restricted `id-token: write` to the two-step PyPI job using the protected
|
|
11
|
+
`pypi` GitHub environment;
|
|
12
|
+
- reused one validated artifact for both GitHub and PyPI publication.
|
|
13
|
+
|
|
14
|
+
## 1.0.0 - 2026-07-18
|
|
15
|
+
|
|
16
|
+
- stabilized `ContextPipeline` as the primary model-boundary API while keeping
|
|
17
|
+
the existing per-call invoker compatible;
|
|
18
|
+
- added dependency-free callable `OllamaClient` and `OpenAICompatibleClient`
|
|
19
|
+
transports with normalized usage metadata and endpoint errors;
|
|
20
|
+
- added `contextir run` for one-command local and OpenAI-compatible model
|
|
21
|
+
invocation, including stdin and payload-free JSON trace modes;
|
|
22
|
+
- moved the quick start to the runnable client-plus-pipeline path and documented
|
|
23
|
+
the direct release-wheel install;
|
|
24
|
+
- documented SemVer guarantees, stable exports, contract evolution, and the
|
|
25
|
+
migration from the 0.x API;
|
|
26
|
+
- verified the built wheel in a clean virtual environment and exercised the
|
|
27
|
+
installed CLI against local Ollama;
|
|
28
|
+
- retained the `contextir.v2` contract without a schema migration.
|
|
29
|
+
|
|
30
|
+
## 0.5.0 - 2026-07-18
|
|
31
|
+
|
|
32
|
+
- added strict agent tool-routing and agent-state diagnostics to the existing
|
|
33
|
+
local-model A/B harness;
|
|
34
|
+
- added optional external privacy-corpus evaluation with precision and recall
|
|
35
|
+
gates;
|
|
36
|
+
- added exact-value privacy annotations to the checked-in gateway benchmark;
|
|
37
|
+
- classified payment cards before phone numbers and added Luhn validation;
|
|
38
|
+
- rejected ISO dates, IPv4 values, SSN-shaped values, and short bare numbers
|
|
39
|
+
from the dependency-free phone recognizer;
|
|
40
|
+
- measured `0.8471` precision and `1.0000` recall on 277 supported spans from
|
|
41
|
+
Microsoft Presidio Research's 1,500-row MIT-licensed synthetic corpus;
|
|
42
|
+
- measured identical `0.7272` raw and auto quality on nine Qwen3 8B cases while
|
|
43
|
+
reducing model input by 70.0% and mean latency from `53.8 s` to `2.51 s`.
|
|
44
|
+
|
|
45
|
+
## 0.4.1 - 2026-07-18
|
|
46
|
+
|
|
47
|
+
- changed the product pipeline to compile the candidate first and build a raw
|
|
48
|
+
baseline only when the savings gate needs it;
|
|
49
|
+
- avoided duplicate compilation when auto mode already selects raw;
|
|
50
|
+
- skipped event and numeric-entity extraction for query-aware retrieval, where
|
|
51
|
+
the model receives selected verbatim evidence instead;
|
|
52
|
+
- precompiled hot-path regular expressions and reused normalized token sets;
|
|
53
|
+
- replaced repeated paragraph-owner scans with a linear ownership pass;
|
|
54
|
+
- added deterministic tests for single-pass candidate and exhaustive routing;
|
|
55
|
+
- preserved all 16 sampled contracts and all seven saved model-facing prompt
|
|
56
|
+
token counts exactly.
|
|
57
|
+
|
|
58
|
+
## 0.4.0 - 2026-07-18
|
|
59
|
+
|
|
60
|
+
- added query-aware lexical evidence selection for long document QA;
|
|
61
|
+
- preserved task instructions, output format, paragraph ownership, and queries
|
|
62
|
+
as normal model-facing text rather than exposing the internal IR protocol;
|
|
63
|
+
- routed exhaustive counting and retrieval without adequate evidence to raw;
|
|
64
|
+
- removed redundant protocol rendering when hybrid source spans cover every
|
|
65
|
+
compiled event;
|
|
66
|
+
- reused placeholders for repeated occurrences of the same protected value in
|
|
67
|
+
both built-in and Presidio privacy scrubbers;
|
|
68
|
+
- aligned retrieval and passage-count benchmark scoring with LongBench task
|
|
69
|
+
semantics;
|
|
70
|
+
- added Ollama and LM Studio follow-up reports showing about 69% token reduction
|
|
71
|
+
without aggregate quality loss on the tested subset.
|
|
72
|
+
|
|
73
|
+
## 0.3.0 - 2026-07-18
|
|
74
|
+
|
|
75
|
+
- added `ContextPipeline`, the policy-driven product entry point;
|
|
76
|
+
- added target-tokenizer-aware mode selection with a minimum savings gate;
|
|
77
|
+
- separated normal reasoning verification from strict transform retention;
|
|
78
|
+
- added bounded semantic-to-hybrid-to-raw fallback;
|
|
79
|
+
- rejected unknown, missing, and newly generated PII placeholders;
|
|
80
|
+
- added payload-free public traces and explicit restoration allowlists;
|
|
81
|
+
- fixed repeated-event semantic confidence weighting;
|
|
82
|
+
- promoted product pipeline scenarios into the release benchmark gate.
|
|
83
|
+
|
|
84
|
+
## 0.2.1 - 2026-07-18
|
|
85
|
+
|
|
86
|
+
- installed development dependencies before release validation;
|
|
87
|
+
- updated GitHub Actions to Node.js 24-compatible major versions;
|
|
88
|
+
- pinned Gitleaks 8.30.1 and verified its release checksum in CI.
|
|
89
|
+
|
|
90
|
+
## 0.2.0 - 2026-07-18
|
|
91
|
+
|
|
92
|
+
- renamed the public package and product from SIR Translator to ContextIR;
|
|
93
|
+
- added the `contextir.v2` compact contract and packaged JSON Schema;
|
|
94
|
+
- added adaptive raw, hybrid, semantic, and auto modes;
|
|
95
|
+
- separated public contracts from local PII vaults and source maps;
|
|
96
|
+
- added optional Presidio integration and allowlisted restoration;
|
|
97
|
+
- added event deduplication and structured contract comparison;
|
|
98
|
+
- retained earlier SIR graph and neural work as a research layer;
|
|
99
|
+
- added deterministic tests and a compression/privacy smoke benchmark;
|
|
100
|
+
- added packaged schema resources, CI, secret scanning, release automation,
|
|
101
|
+
benchmark cards, and a production-oriented quick start.
|
contextir-1.0.1/LICENSE
ADDED
|
@@ -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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
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 ContextIR contributors
|
|
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.
|
contextir-1.0.1/NOTICE
ADDED
contextir-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: contextir
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Local-first adaptive context compiler and privacy gateway for language models.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mussolene/contextir
|
|
6
|
+
Project-URL: Documentation, https://github.com/mussolene/contextir#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/mussolene/contextir/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/mussolene/contextir/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Maxim Matvienko
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: agents,compression,context,llm,privacy,semantic-ir
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
26
|
+
Requires-Dist: hatch>=1.14; extra == 'dev'
|
|
27
|
+
Requires-Dist: jsonschema>=4.20; extra == 'dev'
|
|
28
|
+
Requires-Dist: twine>=5.1; extra == 'dev'
|
|
29
|
+
Provides-Extra: privacy
|
|
30
|
+
Requires-Dist: presidio-analyzer>=2.2; extra == 'privacy'
|
|
31
|
+
Provides-Extra: research
|
|
32
|
+
Requires-Dist: numpy>=1.26; extra == 'research'
|
|
33
|
+
Requires-Dist: pyyaml>=6.0; extra == 'research'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# ContextIR
|
|
37
|
+
|
|
38
|
+
ContextIR is a local-first adaptive context compiler and privacy gateway for
|
|
39
|
+
language models. It turns text into a compact, inspectable intermediate
|
|
40
|
+
representation while retaining critical source fragments when a lossy summary
|
|
41
|
+
would be unsafe.
|
|
42
|
+
|
|
43
|
+
Status: **stable 1.0 API**. ContextIR follows semantic versioning for the public
|
|
44
|
+
Python surface and the `contextir.v2` contract. Semantic compression and PII
|
|
45
|
+
detection still require evaluation on each deployment's data.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python3 -m pip install contextir
|
|
51
|
+
ollama pull qwen3:0.6b
|
|
52
|
+
contextir run --model qwen3:0.6b --text "Reply with only READY."
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from contextir import ContextPipeline, OllamaClient
|
|
57
|
+
|
|
58
|
+
pipeline = ContextPipeline(invoke=OllamaClient("qwen3:0.6b"))
|
|
59
|
+
result = pipeline.run(
|
|
60
|
+
"If payment 42 is complete, do not send it again.",
|
|
61
|
+
source_lang="en",
|
|
62
|
+
target_lang="en",
|
|
63
|
+
)
|
|
64
|
+
print(result.answer)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The release wheel avoids a source checkout and Git dependency. A pinned Git
|
|
68
|
+
install remains available for environments that prefer source builds.
|
|
69
|
+
|
|
70
|
+
For a two-minute integration and safe restoration example, see
|
|
71
|
+
[Quick start](docs/QUICKSTART.md).
|
|
72
|
+
|
|
73
|
+
## Why
|
|
74
|
+
|
|
75
|
+
Long agent histories and tool outputs consume model context with repeated facts,
|
|
76
|
+
formatting, and sensitive values. ContextIR provides three explicit modes:
|
|
77
|
+
|
|
78
|
+
- `raw`: masked source text, without protocol overhead;
|
|
79
|
+
- `hybrid`: semantic events plus source fragments containing negation,
|
|
80
|
+
conditions, numbers, quotes, or protected placeholders;
|
|
81
|
+
- `semantic`: compact events only, for callers that accept lossy compression.
|
|
82
|
+
|
|
83
|
+
`auto` first distinguishes exhaustive tasks, document retrieval, and
|
|
84
|
+
operational history. Exhaustive tasks stay raw. Document QA uses local lexical
|
|
85
|
+
retrieval to keep the query, formatting instructions, and evidence spans
|
|
86
|
+
verbatim. Operational history continues to use inspectable events and critical
|
|
87
|
+
source fragments.
|
|
88
|
+
|
|
89
|
+
`ContextPipeline` is the product entry point. It measures candidate prompts
|
|
90
|
+
with a configurable target-model tokenizer, rejects compression without useful
|
|
91
|
+
savings, verifies output safety, and performs bounded fallback from semantic to
|
|
92
|
+
hybrid to raw context.
|
|
93
|
+
|
|
94
|
+
## Install
|
|
95
|
+
|
|
96
|
+
From a checkout:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python3 -m pip install -e .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Optional Presidio integration:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python3 -m pip install -e '.[privacy]'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Advanced Compiler API
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from contextir import ContextIR
|
|
112
|
+
|
|
113
|
+
gateway = ContextIR()
|
|
114
|
+
bundle = gateway.compile_private(
|
|
115
|
+
"If payment 42 is complete, do not send it again. Email person@example.test.",
|
|
116
|
+
source_lang="en",
|
|
117
|
+
target_lang="en",
|
|
118
|
+
mode="hybrid",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
contract = bundle.contract
|
|
122
|
+
model_prompt = gateway.render_prompt(contract)
|
|
123
|
+
|
|
124
|
+
# Restore only placeholders explicitly allowed by the application.
|
|
125
|
+
answer = gateway.restore("Contact PII_EMAIL_1", bundle, allowed={"PII_EMAIL_1"})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`compile()` returns only the public contract. `compile_private()` additionally
|
|
129
|
+
returns the local PII vault and source-reference map. Neither is inserted into
|
|
130
|
+
the model prompt.
|
|
131
|
+
|
|
132
|
+
For model-facing applications, prefer `ContextPipeline` over calling the
|
|
133
|
+
compiler directly. Use `task="transform"` for translation, rewriting, and
|
|
134
|
+
summarization where numbers, negation, constraints, and placeholders must
|
|
135
|
+
survive. Normal reasoning answers are not incorrectly required to echo the
|
|
136
|
+
request.
|
|
137
|
+
|
|
138
|
+
## CLI
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
contextir run \
|
|
142
|
+
--backend ollama \
|
|
143
|
+
--model qwen3:0.6b \
|
|
144
|
+
--text "Summarize the current agent state."
|
|
145
|
+
|
|
146
|
+
contextir compile \
|
|
147
|
+
--text "Если платеж 42 выполнен, не отправляй его повторно." \
|
|
148
|
+
--source-lang ru \
|
|
149
|
+
--target-lang en \
|
|
150
|
+
--mode hybrid \
|
|
151
|
+
--out /tmp/contextir.json
|
|
152
|
+
|
|
153
|
+
contextir render --contract /tmp/contextir.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The source checkout also exposes `python3 scripts/contextir.py`.
|
|
157
|
+
|
|
158
|
+
## Contract
|
|
159
|
+
|
|
160
|
+
ContextIR v2 records:
|
|
161
|
+
|
|
162
|
+
- source and target language;
|
|
163
|
+
- intent and confidence;
|
|
164
|
+
- typed entities and protected placeholders;
|
|
165
|
+
- events with predicate, arguments, polarity, modality, condition, and source
|
|
166
|
+
reference;
|
|
167
|
+
- execution and privacy constraints;
|
|
168
|
+
- optional lexical concepts;
|
|
169
|
+
- included source fragments and unresolved source references;
|
|
170
|
+
- prompt-size and latency statistics.
|
|
171
|
+
|
|
172
|
+
The packaged JSON Schema is available through:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from contextir.schemas import load_contract_schema
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Privacy
|
|
179
|
+
|
|
180
|
+
The default detector is deliberately small and recognizes common emails,
|
|
181
|
+
phones, payment-card-like values, and API-key-like tokens. Presidio can be used
|
|
182
|
+
as an optional detector and extended with project-specific recognizers.
|
|
183
|
+
|
|
184
|
+
Automated PII detection is not a security boundary by itself. Keep the vault
|
|
185
|
+
local, avoid logging prompt bodies, use explicit restoration allowlists, and
|
|
186
|
+
evaluate recognizers on data representative of the deployment.
|
|
187
|
+
|
|
188
|
+
## Current Evidence
|
|
189
|
+
|
|
190
|
+
The checked-in compiler smoke benchmark reports:
|
|
191
|
+
|
|
192
|
+
- 9 compiler and 4 product-pipeline cases;
|
|
193
|
+
- 0 expectation failures;
|
|
194
|
+
- 0 pipeline failures;
|
|
195
|
+
- 0 PII leaks into public contracts or rendered prompts;
|
|
196
|
+
- `0.3627` prompt/source ratio on the one compression-eligible repeated-context
|
|
197
|
+
case.
|
|
198
|
+
|
|
199
|
+
The first model-level A/B exposed a large quality loss in v0.3.0. Query-aware
|
|
200
|
+
routing corrected that failure. On the v0.5.0 nine-case Qwen3 8B run, raw and
|
|
201
|
+
auto both scored `0.7272`, while auto reduced model input by 70.0% and mean
|
|
202
|
+
latency from `53.8 s` to `2.51 s`. An external 1,500-row Presidio Research
|
|
203
|
+
benchmark measured `0.8471` precision and `1.0000` recall for the dependency-free
|
|
204
|
+
email/phone/card profile. These are bounded results, not universal quality or
|
|
205
|
+
privacy claims; broader official tasks and deployment-specific PII evaluation
|
|
206
|
+
remain required.
|
|
207
|
+
|
|
208
|
+
See the [local model A/B card](docs/benchmarks/LOCAL_MODEL_AB.md) and
|
|
209
|
+
[benchmark roadmap](docs/BENCHMARKS.md).
|
|
210
|
+
|
|
211
|
+
## Research Layer
|
|
212
|
+
|
|
213
|
+
The repository retains the earlier RU/EN lexical graph, graph embeddings,
|
|
214
|
+
synthetic translator, checkpoints, and roundtrip experiments. They are not
|
|
215
|
+
loaded by the default package path. Use the `research` extra and source checkout
|
|
216
|
+
for those experiments.
|
|
217
|
+
|
|
218
|
+
The old WordNet keyword roundtrip is preserved as a baseline, not presented as
|
|
219
|
+
the production compiler. See [RESEARCH_HISTORY.md](docs/RESEARCH_HISTORY.md).
|
|
220
|
+
|
|
221
|
+
## Development
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
python3 -m pip install -e '.[dev,research]'
|
|
225
|
+
python3 -m unittest discover -s tests -v
|
|
226
|
+
python3 scripts/evaluate_contextir.py
|
|
227
|
+
python3 -m build
|
|
228
|
+
python3 -m twine check dist/*
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Architecture, scope, contribution, and security guidance:
|
|
232
|
+
|
|
233
|
+
- [Architecture](docs/ARCHITECTURE.md)
|
|
234
|
+
- [Quick start](docs/QUICKSTART.md)
|
|
235
|
+
- [Product scope](docs/PRODUCT_SCOPE.md)
|
|
236
|
+
- [Benchmarks](docs/BENCHMARKS.md)
|
|
237
|
+
- [Contributing](CONTRIBUTING.md)
|
|
238
|
+
- [Security](SECURITY.md)
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
ContextIR code is licensed under Apache-2.0. Research datasets and derived
|
|
243
|
+
lexical artifacts retain their upstream terms. See
|
|
244
|
+
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) before redistributing them.
|