ucde 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. ucde-0.2.0/LICENSE +202 -0
  2. ucde-0.2.0/PKG-INFO +171 -0
  3. ucde-0.2.0/README.md +142 -0
  4. ucde-0.2.0/pyproject.toml +66 -0
  5. ucde-0.2.0/python/ucde/__init__.py +20 -0
  6. ucde-0.2.0/python/ucde/__main__.py +7 -0
  7. ucde-0.2.0/python/ucde/archive.py +109 -0
  8. ucde-0.2.0/python/ucde/chain.py +222 -0
  9. ucde-0.2.0/python/ucde/chain_audit.py +210 -0
  10. ucde-0.2.0/python/ucde/cli.py +363 -0
  11. ucde-0.2.0/python/ucde/crate.py +98 -0
  12. ucde-0.2.0/python/ucde/mcp_server.py +230 -0
  13. ucde-0.2.0/python/ucde/model.py +192 -0
  14. ucde-0.2.0/python/ucde/ollama.py +183 -0
  15. ucde-0.2.0/python/ucde/packet.py +250 -0
  16. ucde-0.2.0/python/ucde/provenance.py +101 -0
  17. ucde-0.2.0/python/ucde/py.typed +0 -0
  18. ucde-0.2.0/python/ucde/ranking.py +98 -0
  19. ucde-0.2.0/python/ucde/store.py +729 -0
  20. ucde-0.2.0/python/ucde.egg-info/PKG-INFO +171 -0
  21. ucde-0.2.0/python/ucde.egg-info/SOURCES.txt +43 -0
  22. ucde-0.2.0/python/ucde.egg-info/dependency_links.txt +1 -0
  23. ucde-0.2.0/python/ucde.egg-info/entry_points.txt +3 -0
  24. ucde-0.2.0/python/ucde.egg-info/requires.txt +3 -0
  25. ucde-0.2.0/python/ucde.egg-info/top_level.txt +1 -0
  26. ucde-0.2.0/setup.cfg +4 -0
  27. ucde-0.2.0/tests/test_agicam.py +72 -0
  28. ucde-0.2.0/tests/test_archive_export.py +81 -0
  29. ucde-0.2.0/tests/test_archive_verification.py +108 -0
  30. ucde-0.2.0/tests/test_benchmark.py +62 -0
  31. ucde-0.2.0/tests/test_chain_audit.py +169 -0
  32. ucde-0.2.0/tests/test_chain_integration.py +194 -0
  33. ucde-0.2.0/tests/test_chain_writer.py +134 -0
  34. ucde-0.2.0/tests/test_cli.py +676 -0
  35. ucde-0.2.0/tests/test_crate.py +76 -0
  36. ucde-0.2.0/tests/test_integrity.py +204 -0
  37. ucde-0.2.0/tests/test_jarvis_pilot.py +118 -0
  38. ucde-0.2.0/tests/test_mcp.py +219 -0
  39. ucde-0.2.0/tests/test_memory.py +244 -0
  40. ucde-0.2.0/tests/test_ollama.py +160 -0
  41. ucde-0.2.0/tests/test_packet.py +210 -0
  42. ucde-0.2.0/tests/test_provenance.py +97 -0
  43. ucde-0.2.0/tests/test_real_data_evaluate.py +101 -0
  44. ucde-0.2.0/tests/test_release_batches.py +94 -0
  45. ucde-0.2.0/tests/test_release_replay.py +97 -0
ucde-0.2.0/LICENSE ADDED
@@ -0,0 +1,202 @@
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 {yyyy} {name of copyright owner}
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.
202
+
ucde-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: ucde
3
+ Version: 0.2.0
4
+ Summary: Local experimental evidence memory with repeatable historical search
5
+ Author: Muhammad Q Farooqi
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/mqfarooqi1/ucde
8
+ Project-URL: Changelog, https://github.com/mqfarooqi1/ucde/blob/main/CHANGELOG.md
9
+ Keywords: research data,provenance,evidence retrieval,plant breeding,sqlite,mcp
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: mcp
27
+ Requires-Dist: mcp==2.3.0; extra == "mcp"
28
+ Dynamic: license-file
29
+
30
+ # Universal Cognitive Data Engine
31
+
32
+ UCDE is a local evidence ledger and search engine for experimental research. It helps a researcher recover the observation behind a result, see which version was available at a past cutoff, and filter to the genotype or sample, variable, method, scale and conditions that make the observation relevant.
33
+
34
+ The first workflow uses plant breeding records. The same schema supports assay-method records, as demonstrated with a fictional nonpatient example. UCDE preserves independent observations even when they disagree, keeps corrections and retractions in history, and returns source references and ranking components. Python and SQLite store and search evidence without model inference or network calls.
35
+
36
+ ## Run locally
37
+
38
+ Use Python 3.11+ with SQLite built with FTS5 and JSON functions. From this folder, `python -m pip install .` installs the core library and `ucde` command. It can fetch the pinned build dependency when needed. If `build` and setuptools 81.0.0 are already available, build and install entirely offline with `python -m build --no-isolation --wheel` followed by `python -m pip install --no-index --no-deps --find-links dist ucde==0.2.0`. The wheel has no runtime dependencies.
39
+
40
+ ```powershell
41
+ ucde --db evidence.db init
42
+ python examples/evidence_walkthrough.py
43
+ python examples/agicam_wheat.py --wheat spring --variety 9 --sensor AG13 --vi NDVI --through 2022-06-10
44
+ python -m unittest discover -s tests -v
45
+ python -m benchmarks.run_memory --output my-memory-benchmark.json
46
+ ```
47
+
48
+ From a source checkout without an install, set `$env:PYTHONPATH = 'python'` in PowerShell or `export PYTHONPATH=python` in a POSIX shell. Use `python -m ucde` as the CLI command in that case. The walkthroughs use temporary databases. The AGIcam example returns the original CSV line and measurement context from a small published dataset excerpt. [Dataset and licence](https://zenodo.org/records/17970104).
49
+
50
+ ## Store and retrieve an observation
51
+
52
+ ```python
53
+ from ucde import Evidence, MemoryStore
54
+
55
+ store = MemoryStore("breeding-evidence.db")
56
+ observation = Evidence(
57
+ id="north-2025-plot-18", subject="W-017", variable="plant height",
58
+ method="ruler-v1", scale="cm", observed_at="2025-09-05T05:30:00Z",
59
+ text="W-017 measured 81 cm in plot 18.",
60
+ source="north-2025-fieldbook.csv", locator="csv-row:18",
61
+ context={"site": "north", "treatment": "rainfed", "trial": "2025"},
62
+ )
63
+ store.put(observation)
64
+ result = store.search("plant height", subject="W-017", method="ruler-v1",
65
+ scale="cm", context={"site": "north", "treatment": "rainfed"})
66
+ for hit in result.hits:
67
+ print(hit.revision.evidence.source, hit.revision.evidence.locator, hit.score)
68
+ ```
69
+
70
+ The write above expects a new observation ID. Keep the returned revision and pass its `revision` to `store.put(corrected, expected_revision=...)` when correcting the observation. Use `known_at` to reconstruct which revision was available at a cutoff, and `observed_after` and `observed_before` to constrain when the measurement happened. Both observation endpoints are inclusive. `target_at` adds a soft date preference under adaptive ranking. Use `strategy="nearest"` with `target_at` when closeness in observation time should take priority over lexical relevance. See `ucde search --help` for the corresponding CLI options.
71
+
72
+ ```python
73
+ store.search(
74
+ "plant height", subject="W-017", method="ruler-v1", scale="cm",
75
+ observed_after="2025-09-01T00:00:00Z", observed_before="2025-09-08T00:00:00Z",
76
+ target_at="2025-09-05T00:00:00Z", strategy="nearest",
77
+ )
78
+ ```
79
+
80
+ Source locators and optional checksums are provided by the caller. The engine does not resolve source content.
81
+
82
+ ## Load and replay dataset releases
83
+
84
+ Use `store.apply_batch(...)` to commit a complete set of changes as one event. Pass `EvidenceWrite` for new or corrected records and `EvidenceRetraction` for records that should cease to be active. Each change carries the current expected revision, with `0` for a new identifier. All revisions in a batch share one `recorded_at`. `store.get(id, known_at=cutoff)` returns the active revision by ID using the recording cutoff alone. Earlier revisions remain available through `store.history(id)`.
85
+
86
+ The [JARVIS release replay](benchmarks/real_data/README.md#replay-two-published-jarvis-releases) applies these operations to two checksummed public archives. Its recording clock uses each publisher release instant to reconstruct historical availability.
87
+
88
+ ## Export a historical evidence packet
89
+
90
+ Use `ucde export` to save a scoped text search, its recording cutoff, and the exact results with citations and revision numbers. A collaborator can read the JSON and verify the packet offline.
91
+
92
+ ```powershell
93
+ $cutoff = (Get-Date).ToUniversalTime().ToString("o")
94
+ ucde --db breeding-evidence.db export "plant height" --subject W-017 --known-at $cutoff --output height-packet.json
95
+ ucde verify-packet height-packet.json
96
+ ```
97
+
98
+ The export prints a SHA-256 receipt. To compare a copy against a digest received separately, pass that digest to `ucde verify-packet` with `--expected-sha256`. The Python SDK also provides `export_packet` and `verify_packet`. [Public examples and attribution](examples/README.md#portable-packets-from-published-datasets).
99
+
100
+ ### Compare two packets
101
+
102
+ ```powershell
103
+ ucde compare earlier-packet.json later-packet.json
104
+ ```
105
+
106
+ The report matches records by evidence ID and shows changes to the evidence, citation, revision, and ranking. It also shows differences in search settings and the effective observation cutoff for each packet. A record present in just one result can reflect the query, the result limit, or the ledger state. Supply `--before-sha256` and `--after-sha256` to check the files against digests received separately. The SDK equivalent is `compare_packets`.
107
+
108
+ ### Replay a packet against a ledger
109
+
110
+ ```powershell
111
+ ucde --db breeding-evidence.db replay height-packet.json
112
+ ```
113
+
114
+ Replay runs the saved query and selectors at the packet's recording cutoff. It opens the ledger read-only and reports whether the new result has the same digest. A difference report includes changes to returned records, citations, ranking, and search candidate counts. The command exits 0 for a match and 1 for a difference or invalid packet. To supply a separately obtained digest, use `--expected-sha256`. The SDK equivalent is `replay_packet`.
115
+
116
+ ## Check a ledger
117
+
118
+ `ucde --db evidence.db verify` audits a file without changing it. It runs SQLite's integrity check, then confirms each ledger invariant against the stored payloads, for example that an observation's revisions are consecutive, that recording times stay in order, and that every search entry matches the payload it indexes. It prints a JSON report and exits 1 when it finds a problem, so it can gate a backup, a restore or a scheduled job. `MemoryStore.verify()` returns the same report in Python. Every open also refuses a file whose schema UCDE did not create, such as one that defines a trigger or view.
119
+
120
+ ### Save and check a ledger checkpoint
121
+
122
+ ```powershell
123
+ $checkpoint = ucde --db evidence.db checkpoint | ConvertFrom-Json
124
+ ucde --db evidence.db checkpoint --known-at $checkpoint.known_at --expected-sha256 $checkpoint.sha256
125
+ ```
126
+
127
+ Save the reported cutoff and SHA-256 separately from the ledger, for example in a lab notebook. Rechecking compares every retained revision through that cutoff, including retractions. Commits recorded after the cutoff preserve the checkpoint. A purge of covered history or a change to a covered citation produces a mismatch and exit code 1. The CLI opens the ledger read-only and returns the digest and counts. The Python SDK provides the same check through `MemoryStore.checkpoint()`.
128
+
129
+ ### Enable and verify a persistent ledger chain
130
+
131
+ ```powershell
132
+ ucde --db evidence.db enable-chain --output evidence-v3.db
133
+ ucde --db evidence-v3.db chain-head | Set-Content -Encoding utf8 trusted-head.json
134
+ ucde --db evidence-v3.db verify --head-file trusted-head.json
135
+ ```
136
+
137
+ `enable-chain` audits and upgrades a new SQLite copy. The source remains the schema 2 backup when upgrading from schema 2. Save the chain head separately from the database. Verification checks the saved prefix and every commit that follows it, so later valid writes preserve the check and an older backup fails it. A purge retains opaque commitments and commit coordinates while removing the payload and nonce from the ledger. The SDK provides `MemoryStore.enable_chain()`, `chain_head()`, and `verify(expected_head=...)`. [Schema 3 format and migration](specifications/ledger-chaining-v3.md).
138
+
139
+ ### Export a portable history archive
140
+
141
+ ```powershell
142
+ $receipt = ucde --db evidence.db archive --output evidence-history.jsonl | ConvertFrom-Json
143
+ ucde verify-archive evidence-history.jsonl --expected-sha256 $receipt.sha256
144
+ ```
145
+
146
+ The archive contains the full stored payload for every retained revision through its recording cutoff, including earlier versions, retractions, and stored vectors. Use `--known-at` to select a specific cutoff. The archive bytes hash to the same SHA-256 as a checkpoint at that cutoff. A recipient can verify the file offline using the digest you saved separately. The verifier returns exit 1 if the digest differs or the archive is malformed. Python applications can use `MemoryStore.export_archive()` and `verify_archive()`.
147
+
148
+ ### Package an archive for research exchange
149
+
150
+ ```powershell
151
+ ucde crate evidence-history.jsonl --expected-sha256 $receipt.sha256 --output research-crate --name "Study evidence" --description "Retained measurement revisions" --date-published 2026-12-05 --license "Internal research use"
152
+ ucde verify-archive research-crate/history.jsonl --expected-sha256 $receipt.sha256
153
+ ```
154
+
155
+ `ucde crate` validates the archive before packaging it with its checkpoint receipt, RO-Crate metadata, and a JSON-LD provenance graph. The graph records source locators and digests, revision links, and recording and observation times. Supply the title, description, publication date, and licence or terms that apply to your package. The Python equivalent is `create_crate()`. [RO-Crate 1.2](https://www.researchobject.org/ro-crate/specification/1.2/) · [W3C PROV-O](https://www.w3.org/TR/prov-o/).
156
+
157
+ ## Optional interoperability
158
+
159
+ - Install `python -m pip install ".[mcp]"` and register `ucde-mcp --db <absolute-path-to-existing-db>` as a local stdio MCP server. The two evidence tools have read-only access to that file. The server uses the MCP Python SDK 2.3 and accepts both the initialize handshake (protocol 2025-11-25) and the per-request protocol (2026-07-28). Its instructions tell clients to cite source and locator and to treat evidence text as data. Use `python -m ucde.mcp_server --db …` in a source environment with the MCP SDK installed.
160
+ - `ucde models` and `ucde generate --model <installed-model> --prompt "Example"` connect to an already running Ollama daemon on numeric loopback. `ucde.ollama.OllamaClient.embed` computes an embedding explicitly. Use one pinned embedding space for compatible vectors. The ledger and MCP server never send retrieved evidence to Ollama. Disable cloud features and block outbound connectivity in offline deployments. [Ollama FAQ](https://docs.ollama.com/faq).
161
+ - With Docker Compose, `docker compose run --rm ucde` initializes a named volume in an isolated container. Pass CLI arguments after `ucde` for subsequent runs. The image contains the core CLI only and builds using the Docker base image and the pinned build backend. CI builds it and round-trips evidence with no network and a read-only root file system.
162
+
163
+ ## Project status
164
+
165
+ Start with the [Phase 0 assessment](research/phase-0-assessment.md), [algorithm specification](specifications/evidence-memory-v1.md), and [benchmark](benchmarks/README.md). The [development status](DEVELOPMENT_STATUS.md) records verified results, current limits and the next research milestone. The [threat model](security/THREAT_MODEL.md) explains the local trust boundary. Use separate files and OS permissions for different principals. The prototype is intended for research evidence and has no clinical workflow or enterprise service.
166
+
167
+ ## Licence
168
+
169
+ Apache-2.0. See [LICENSE](LICENSE). To cite UCDE, use [CITATION.cff](CITATION.cff).
170
+
171
+ Created and maintained by [Muhammad Q Farooqi](https://github.com/mqfarooqi1).
ucde-0.2.0/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # Universal Cognitive Data Engine
2
+
3
+ UCDE is a local evidence ledger and search engine for experimental research. It helps a researcher recover the observation behind a result, see which version was available at a past cutoff, and filter to the genotype or sample, variable, method, scale and conditions that make the observation relevant.
4
+
5
+ The first workflow uses plant breeding records. The same schema supports assay-method records, as demonstrated with a fictional nonpatient example. UCDE preserves independent observations even when they disagree, keeps corrections and retractions in history, and returns source references and ranking components. Python and SQLite store and search evidence without model inference or network calls.
6
+
7
+ ## Run locally
8
+
9
+ Use Python 3.11+ with SQLite built with FTS5 and JSON functions. From this folder, `python -m pip install .` installs the core library and `ucde` command. It can fetch the pinned build dependency when needed. If `build` and setuptools 81.0.0 are already available, build and install entirely offline with `python -m build --no-isolation --wheel` followed by `python -m pip install --no-index --no-deps --find-links dist ucde==0.2.0`. The wheel has no runtime dependencies.
10
+
11
+ ```powershell
12
+ ucde --db evidence.db init
13
+ python examples/evidence_walkthrough.py
14
+ python examples/agicam_wheat.py --wheat spring --variety 9 --sensor AG13 --vi NDVI --through 2022-06-10
15
+ python -m unittest discover -s tests -v
16
+ python -m benchmarks.run_memory --output my-memory-benchmark.json
17
+ ```
18
+
19
+ From a source checkout without an install, set `$env:PYTHONPATH = 'python'` in PowerShell or `export PYTHONPATH=python` in a POSIX shell. Use `python -m ucde` as the CLI command in that case. The walkthroughs use temporary databases. The AGIcam example returns the original CSV line and measurement context from a small published dataset excerpt. [Dataset and licence](https://zenodo.org/records/17970104).
20
+
21
+ ## Store and retrieve an observation
22
+
23
+ ```python
24
+ from ucde import Evidence, MemoryStore
25
+
26
+ store = MemoryStore("breeding-evidence.db")
27
+ observation = Evidence(
28
+ id="north-2025-plot-18", subject="W-017", variable="plant height",
29
+ method="ruler-v1", scale="cm", observed_at="2025-09-05T05:30:00Z",
30
+ text="W-017 measured 81 cm in plot 18.",
31
+ source="north-2025-fieldbook.csv", locator="csv-row:18",
32
+ context={"site": "north", "treatment": "rainfed", "trial": "2025"},
33
+ )
34
+ store.put(observation)
35
+ result = store.search("plant height", subject="W-017", method="ruler-v1",
36
+ scale="cm", context={"site": "north", "treatment": "rainfed"})
37
+ for hit in result.hits:
38
+ print(hit.revision.evidence.source, hit.revision.evidence.locator, hit.score)
39
+ ```
40
+
41
+ The write above expects a new observation ID. Keep the returned revision and pass its `revision` to `store.put(corrected, expected_revision=...)` when correcting the observation. Use `known_at` to reconstruct which revision was available at a cutoff, and `observed_after` and `observed_before` to constrain when the measurement happened. Both observation endpoints are inclusive. `target_at` adds a soft date preference under adaptive ranking. Use `strategy="nearest"` with `target_at` when closeness in observation time should take priority over lexical relevance. See `ucde search --help` for the corresponding CLI options.
42
+
43
+ ```python
44
+ store.search(
45
+ "plant height", subject="W-017", method="ruler-v1", scale="cm",
46
+ observed_after="2025-09-01T00:00:00Z", observed_before="2025-09-08T00:00:00Z",
47
+ target_at="2025-09-05T00:00:00Z", strategy="nearest",
48
+ )
49
+ ```
50
+
51
+ Source locators and optional checksums are provided by the caller. The engine does not resolve source content.
52
+
53
+ ## Load and replay dataset releases
54
+
55
+ Use `store.apply_batch(...)` to commit a complete set of changes as one event. Pass `EvidenceWrite` for new or corrected records and `EvidenceRetraction` for records that should cease to be active. Each change carries the current expected revision, with `0` for a new identifier. All revisions in a batch share one `recorded_at`. `store.get(id, known_at=cutoff)` returns the active revision by ID using the recording cutoff alone. Earlier revisions remain available through `store.history(id)`.
56
+
57
+ The [JARVIS release replay](benchmarks/real_data/README.md#replay-two-published-jarvis-releases) applies these operations to two checksummed public archives. Its recording clock uses each publisher release instant to reconstruct historical availability.
58
+
59
+ ## Export a historical evidence packet
60
+
61
+ Use `ucde export` to save a scoped text search, its recording cutoff, and the exact results with citations and revision numbers. A collaborator can read the JSON and verify the packet offline.
62
+
63
+ ```powershell
64
+ $cutoff = (Get-Date).ToUniversalTime().ToString("o")
65
+ ucde --db breeding-evidence.db export "plant height" --subject W-017 --known-at $cutoff --output height-packet.json
66
+ ucde verify-packet height-packet.json
67
+ ```
68
+
69
+ The export prints a SHA-256 receipt. To compare a copy against a digest received separately, pass that digest to `ucde verify-packet` with `--expected-sha256`. The Python SDK also provides `export_packet` and `verify_packet`. [Public examples and attribution](examples/README.md#portable-packets-from-published-datasets).
70
+
71
+ ### Compare two packets
72
+
73
+ ```powershell
74
+ ucde compare earlier-packet.json later-packet.json
75
+ ```
76
+
77
+ The report matches records by evidence ID and shows changes to the evidence, citation, revision, and ranking. It also shows differences in search settings and the effective observation cutoff for each packet. A record present in just one result can reflect the query, the result limit, or the ledger state. Supply `--before-sha256` and `--after-sha256` to check the files against digests received separately. The SDK equivalent is `compare_packets`.
78
+
79
+ ### Replay a packet against a ledger
80
+
81
+ ```powershell
82
+ ucde --db breeding-evidence.db replay height-packet.json
83
+ ```
84
+
85
+ Replay runs the saved query and selectors at the packet's recording cutoff. It opens the ledger read-only and reports whether the new result has the same digest. A difference report includes changes to returned records, citations, ranking, and search candidate counts. The command exits 0 for a match and 1 for a difference or invalid packet. To supply a separately obtained digest, use `--expected-sha256`. The SDK equivalent is `replay_packet`.
86
+
87
+ ## Check a ledger
88
+
89
+ `ucde --db evidence.db verify` audits a file without changing it. It runs SQLite's integrity check, then confirms each ledger invariant against the stored payloads, for example that an observation's revisions are consecutive, that recording times stay in order, and that every search entry matches the payload it indexes. It prints a JSON report and exits 1 when it finds a problem, so it can gate a backup, a restore or a scheduled job. `MemoryStore.verify()` returns the same report in Python. Every open also refuses a file whose schema UCDE did not create, such as one that defines a trigger or view.
90
+
91
+ ### Save and check a ledger checkpoint
92
+
93
+ ```powershell
94
+ $checkpoint = ucde --db evidence.db checkpoint | ConvertFrom-Json
95
+ ucde --db evidence.db checkpoint --known-at $checkpoint.known_at --expected-sha256 $checkpoint.sha256
96
+ ```
97
+
98
+ Save the reported cutoff and SHA-256 separately from the ledger, for example in a lab notebook. Rechecking compares every retained revision through that cutoff, including retractions. Commits recorded after the cutoff preserve the checkpoint. A purge of covered history or a change to a covered citation produces a mismatch and exit code 1. The CLI opens the ledger read-only and returns the digest and counts. The Python SDK provides the same check through `MemoryStore.checkpoint()`.
99
+
100
+ ### Enable and verify a persistent ledger chain
101
+
102
+ ```powershell
103
+ ucde --db evidence.db enable-chain --output evidence-v3.db
104
+ ucde --db evidence-v3.db chain-head | Set-Content -Encoding utf8 trusted-head.json
105
+ ucde --db evidence-v3.db verify --head-file trusted-head.json
106
+ ```
107
+
108
+ `enable-chain` audits and upgrades a new SQLite copy. The source remains the schema 2 backup when upgrading from schema 2. Save the chain head separately from the database. Verification checks the saved prefix and every commit that follows it, so later valid writes preserve the check and an older backup fails it. A purge retains opaque commitments and commit coordinates while removing the payload and nonce from the ledger. The SDK provides `MemoryStore.enable_chain()`, `chain_head()`, and `verify(expected_head=...)`. [Schema 3 format and migration](specifications/ledger-chaining-v3.md).
109
+
110
+ ### Export a portable history archive
111
+
112
+ ```powershell
113
+ $receipt = ucde --db evidence.db archive --output evidence-history.jsonl | ConvertFrom-Json
114
+ ucde verify-archive evidence-history.jsonl --expected-sha256 $receipt.sha256
115
+ ```
116
+
117
+ The archive contains the full stored payload for every retained revision through its recording cutoff, including earlier versions, retractions, and stored vectors. Use `--known-at` to select a specific cutoff. The archive bytes hash to the same SHA-256 as a checkpoint at that cutoff. A recipient can verify the file offline using the digest you saved separately. The verifier returns exit 1 if the digest differs or the archive is malformed. Python applications can use `MemoryStore.export_archive()` and `verify_archive()`.
118
+
119
+ ### Package an archive for research exchange
120
+
121
+ ```powershell
122
+ ucde crate evidence-history.jsonl --expected-sha256 $receipt.sha256 --output research-crate --name "Study evidence" --description "Retained measurement revisions" --date-published 2026-12-05 --license "Internal research use"
123
+ ucde verify-archive research-crate/history.jsonl --expected-sha256 $receipt.sha256
124
+ ```
125
+
126
+ `ucde crate` validates the archive before packaging it with its checkpoint receipt, RO-Crate metadata, and a JSON-LD provenance graph. The graph records source locators and digests, revision links, and recording and observation times. Supply the title, description, publication date, and licence or terms that apply to your package. The Python equivalent is `create_crate()`. [RO-Crate 1.2](https://www.researchobject.org/ro-crate/specification/1.2/) · [W3C PROV-O](https://www.w3.org/TR/prov-o/).
127
+
128
+ ## Optional interoperability
129
+
130
+ - Install `python -m pip install ".[mcp]"` and register `ucde-mcp --db <absolute-path-to-existing-db>` as a local stdio MCP server. The two evidence tools have read-only access to that file. The server uses the MCP Python SDK 2.3 and accepts both the initialize handshake (protocol 2025-11-25) and the per-request protocol (2026-07-28). Its instructions tell clients to cite source and locator and to treat evidence text as data. Use `python -m ucde.mcp_server --db …` in a source environment with the MCP SDK installed.
131
+ - `ucde models` and `ucde generate --model <installed-model> --prompt "Example"` connect to an already running Ollama daemon on numeric loopback. `ucde.ollama.OllamaClient.embed` computes an embedding explicitly. Use one pinned embedding space for compatible vectors. The ledger and MCP server never send retrieved evidence to Ollama. Disable cloud features and block outbound connectivity in offline deployments. [Ollama FAQ](https://docs.ollama.com/faq).
132
+ - With Docker Compose, `docker compose run --rm ucde` initializes a named volume in an isolated container. Pass CLI arguments after `ucde` for subsequent runs. The image contains the core CLI only and builds using the Docker base image and the pinned build backend. CI builds it and round-trips evidence with no network and a read-only root file system.
133
+
134
+ ## Project status
135
+
136
+ Start with the [Phase 0 assessment](research/phase-0-assessment.md), [algorithm specification](specifications/evidence-memory-v1.md), and [benchmark](benchmarks/README.md). The [development status](DEVELOPMENT_STATUS.md) records verified results, current limits and the next research milestone. The [threat model](security/THREAT_MODEL.md) explains the local trust boundary. Use separate files and OS permissions for different principals. The prototype is intended for research evidence and has no clinical workflow or enterprise service.
137
+
138
+ ## Licence
139
+
140
+ Apache-2.0. See [LICENSE](LICENSE). To cite UCDE, use [CITATION.cff](CITATION.cff).
141
+
142
+ Created and maintained by [Muhammad Q Farooqi](https://github.com/mqfarooqi1).
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools==81.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ucde"
7
+ dynamic = ["version"]
8
+ description = "Local experimental evidence memory with repeatable historical search"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Muhammad Q Farooqi" }]
14
+ keywords = ["research data", "provenance", "evidence retrieval", "plant breeding", "sqlite", "mcp"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Science/Research",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Programming Language :: Python :: 3.15",
26
+ "Topic :: Database",
27
+ "Topic :: Scientific/Engineering",
28
+ "Typing :: Typed",
29
+ ]
30
+ dependencies = []
31
+
32
+ [project.urls]
33
+ Repository = "https://github.com/mqfarooqi1/ucde"
34
+ Changelog = "https://github.com/mqfarooqi1/ucde/blob/main/CHANGELOG.md"
35
+
36
+ [project.optional-dependencies]
37
+ mcp = ["mcp==2.3.0"]
38
+
39
+ [project.scripts]
40
+ ucde = "ucde.cli:main"
41
+ ucde-mcp = "ucde.mcp_server:main"
42
+
43
+ [tool.setuptools.dynamic]
44
+ version = { attr = "ucde.__version__" }
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["python"]
48
+
49
+ [tool.setuptools.package-data]
50
+ ucde = ["py.typed"]
51
+
52
+ [tool.ruff]
53
+ target-version = "py311"
54
+ line-length = 120
55
+
56
+ [tool.ruff.lint]
57
+ # Errors and bug-prone patterns only; the code keeps its own import order and formatting.
58
+ select = ["E4", "E7", "E9", "F", "B"]
59
+
60
+ [tool.ruff.lint.per-file-ignores]
61
+ # question() is called inside the loop iteration that defines it.
62
+ "benchmarks/fixtures.py" = ["B023"]
63
+
64
+ [tool.mypy]
65
+ python_version = "3.11"
66
+ files = ["python/ucde"]
@@ -0,0 +1,20 @@
1
+ """Local experimental evidence memory for Python applications."""
2
+
3
+ from .archive import verify_archive
4
+ from .crate import create_crate
5
+ from .model import (
6
+ ConflictError, Evidence, EvidenceRetraction, EvidenceWrite, LedgerCheckpoint, LedgerHead, Revision,
7
+ SearchHit, SearchResult,
8
+ ValidationError, VerificationReport,
9
+ )
10
+ from .packet import compare_packets, export_packet, replay_packet, verify_packet
11
+ from .store import MemoryStore
12
+
13
+ __version__ = "0.2.0"
14
+
15
+ __all__ = [
16
+ "ConflictError", "Evidence", "EvidenceRetraction", "EvidenceWrite", "LedgerCheckpoint", "LedgerHead", "MemoryStore",
17
+ "Revision",
18
+ "SearchHit", "SearchResult", "ValidationError", "VerificationReport", "__version__",
19
+ "compare_packets", "create_crate", "export_packet", "replay_packet", "verify_archive", "verify_packet",
20
+ ]
@@ -0,0 +1,7 @@
1
+ """Allow running the UCDE CLI as a Python module."""
2
+
3
+ from .cli import main
4
+
5
+
6
+ if __name__ == "__main__":
7
+ raise SystemExit(main())