structuremappingmemory 1.0.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 (136) hide show
  1. structuremappingmemory-1.0.0/LICENSE +204 -0
  2. structuremappingmemory-1.0.0/PKG-INFO +190 -0
  3. structuremappingmemory-1.0.0/README.md +136 -0
  4. structuremappingmemory-1.0.0/pyproject.toml +91 -0
  5. structuremappingmemory-1.0.0/setup.cfg +4 -0
  6. structuremappingmemory-1.0.0/sma/__init__.py +5 -0
  7. structuremappingmemory-1.0.0/sma/__main__.py +5 -0
  8. structuremappingmemory-1.0.0/sma/agent/__init__.py +5 -0
  9. structuremappingmemory-1.0.0/sma/agent/adapter_draft.py +217 -0
  10. structuremappingmemory-1.0.0/sma/agent/api.py +67 -0
  11. structuremappingmemory-1.0.0/sma/agent/comparison.py +591 -0
  12. structuremappingmemory-1.0.0/sma/agent/llm.py +280 -0
  13. structuremappingmemory-1.0.0/sma/agent/policies.py +21 -0
  14. structuremappingmemory-1.0.0/sma/agent/service.py +95 -0
  15. structuremappingmemory-1.0.0/sma/cli.py +65 -0
  16. structuremappingmemory-1.0.0/sma/encoders/__init__.py +38 -0
  17. structuremappingmemory-1.0.0/sma/encoders/agentobs.py +27 -0
  18. structuremappingmemory-1.0.0/sma/encoders/base.py +23 -0
  19. structuremappingmemory-1.0.0/sma/encoders/code_treesitter.py +64 -0
  20. structuremappingmemory-1.0.0/sma/encoders/coverage.py +80 -0
  21. structuremappingmemory-1.0.0/sma/encoders/draft_adapter.py +183 -0
  22. structuremappingmemory-1.0.0/sma/encoders/healthcare.py +207 -0
  23. structuremappingmemory-1.0.0/sma/encoders/logs_drain.py +142 -0
  24. structuremappingmemory-1.0.0/sma/encoders/prose_tier1.py +57 -0
  25. structuremappingmemory-1.0.0/sma/encoders/structured.py +57 -0
  26. structuremappingmemory-1.0.0/sma/encoders/traces.py +45 -0
  27. structuremappingmemory-1.0.0/sma/eval/__init__.py +2 -0
  28. structuremappingmemory-1.0.0/sma/eval/agentic/__init__.py +35 -0
  29. structuremappingmemory-1.0.0/sma/eval/agentic/arms/__init__.py +0 -0
  30. structuremappingmemory-1.0.0/sma/eval/agentic/arms/cyber.py +48 -0
  31. structuremappingmemory-1.0.0/sma/eval/agentic/arms/discovery.py +35 -0
  32. structuremappingmemory-1.0.0/sma/eval/agentic/arms/finance.py +38 -0
  33. structuremappingmemory-1.0.0/sma/eval/agentic/arms/legal.py +74 -0
  34. structuremappingmemory-1.0.0/sma/eval/agentic/arms/medicine.py +45 -0
  35. structuremappingmemory-1.0.0/sma/eval/agentic/harness.py +275 -0
  36. structuremappingmemory-1.0.0/sma/eval/agentic/memories.py +308 -0
  37. structuremappingmemory-1.0.0/sma/eval/agentic/metrics.py +82 -0
  38. structuremappingmemory-1.0.0/sma/eval/agentic_qa/__init__.py +27 -0
  39. structuremappingmemory-1.0.0/sma/eval/agentic_qa/agent.py +383 -0
  40. structuremappingmemory-1.0.0/sma/eval/agentic_qa/metrics.py +239 -0
  41. structuremappingmemory-1.0.0/sma/eval/agentic_qa/pools.py +197 -0
  42. structuremappingmemory-1.0.0/sma/eval/arn.py +65 -0
  43. structuremappingmemory-1.0.0/sma/eval/baselines/__init__.py +6 -0
  44. structuremappingmemory-1.0.0/sma/eval/baselines/bge_dense.py +54 -0
  45. structuremappingmemory-1.0.0/sma/eval/baselines/bm25.py +18 -0
  46. structuremappingmemory-1.0.0/sma/eval/baselines/dense.py +42 -0
  47. structuremappingmemory-1.0.0/sma/eval/baselines/hipporag.py +235 -0
  48. structuremappingmemory-1.0.0/sma/eval/baselines/hybrid_rrf.py +30 -0
  49. structuremappingmemory-1.0.0/sma/eval/baselines/longcontext_llm.py +124 -0
  50. structuremappingmemory-1.0.0/sma/eval/baselines/rerank.py +41 -0
  51. structuremappingmemory-1.0.0/sma/eval/baselines/splade.py +77 -0
  52. structuremappingmemory-1.0.0/sma/eval/baselines/wl_kernel.py +163 -0
  53. structuremappingmemory-1.0.0/sma/eval/bugsinpy.py +358 -0
  54. structuremappingmemory-1.0.0/sma/eval/bugsinpy_families.py +164 -0
  55. structuremappingmemory-1.0.0/sma/eval/crossdomain.py +89 -0
  56. structuremappingmemory-1.0.0/sma/eval/diabetes.py +61 -0
  57. structuremappingmemory-1.0.0/sma/eval/drift_env.py +26 -0
  58. structuremappingmemory-1.0.0/sma/eval/drift_metrics.py +24 -0
  59. structuremappingmemory-1.0.0/sma/eval/family_labels.py +167 -0
  60. structuremappingmemory-1.0.0/sma/eval/fraud_elliptic/__init__.py +29 -0
  61. structuremappingmemory-1.0.0/sma/eval/fraud_elliptic/encoder.py +279 -0
  62. structuremappingmemory-1.0.0/sma/eval/fraud_elliptic/eval.py +269 -0
  63. structuremappingmemory-1.0.0/sma/eval/fraud_elliptic/test_encoder.py +123 -0
  64. structuremappingmemory-1.0.0/sma/eval/ieee_cis.py +66 -0
  65. structuremappingmemory-1.0.0/sma/eval/loghub.py +16 -0
  66. structuremappingmemory-1.0.0/sma/eval/loghub_eval.py +480 -0
  67. structuremappingmemory-1.0.0/sma/eval/longmemeval.py +51 -0
  68. structuremappingmemory-1.0.0/sma/eval/memory_backends/__init__.py +2 -0
  69. structuremappingmemory-1.0.0/sma/eval/memory_backends/base.py +22 -0
  70. structuremappingmemory-1.0.0/sma/eval/memory_backends/context_only.py +14 -0
  71. structuremappingmemory-1.0.0/sma/eval/memory_backends/rag_notes.py +17 -0
  72. structuremappingmemory-1.0.0/sma/eval/memory_backends/shared_llm.py +30 -0
  73. structuremappingmemory-1.0.0/sma/eval/memory_backends/sma_memory.py +54 -0
  74. structuremappingmemory-1.0.0/sma/eval/memory_backends/zep_graphiti.py +33 -0
  75. structuremappingmemory-1.0.0/sma/eval/metrics.py +32 -0
  76. structuremappingmemory-1.0.0/sma/eval/ontology_bench.py +219 -0
  77. structuremappingmemory-1.0.0/sma/eval/report.py +573 -0
  78. structuremappingmemory-1.0.0/sma/eval/ssb_eval.py +216 -0
  79. structuremappingmemory-1.0.0/sma/eval/ssb_generator.py +116 -0
  80. structuremappingmemory-1.0.0/sma/eval/stats.py +108 -0
  81. structuremappingmemory-1.0.0/sma/eval/transfer_eval.py +844 -0
  82. structuremappingmemory-1.0.0/sma/index/__init__.py +15 -0
  83. structuremappingmemory-1.0.0/sma/index/ann.py +21 -0
  84. structuremappingmemory-1.0.0/sma/index/content_vectors.py +60 -0
  85. structuremappingmemory-1.0.0/sma/index/inverted.py +63 -0
  86. structuremappingmemory-1.0.0/sma/index/macfac.py +174 -0
  87. structuremappingmemory-1.0.0/sma/ir/__init__.py +22 -0
  88. structuremappingmemory-1.0.0/sma/ir/canon.py +106 -0
  89. structuremappingmemory-1.0.0/sma/ir/schema.py +165 -0
  90. structuremappingmemory-1.0.0/sma/ir/sexpr.py +86 -0
  91. structuremappingmemory-1.0.0/sma/ir/signatures.py +76 -0
  92. structuremappingmemory-1.0.0/sma/match/__init__.py +20 -0
  93. structuremappingmemory-1.0.0/sma/match/conflicts.py +46 -0
  94. structuremappingmemory-1.0.0/sma/match/engine.py +60 -0
  95. structuremappingmemory-1.0.0/sma/match/explain.py +59 -0
  96. structuremappingmemory-1.0.0/sma/match/infer.py +54 -0
  97. structuremappingmemory-1.0.0/sma/match/kernels.py +54 -0
  98. structuremappingmemory-1.0.0/sma/match/mdl.py +30 -0
  99. structuremappingmemory-1.0.0/sma/match/merge_cpsat.py +77 -0
  100. structuremappingmemory-1.0.0/sma/match/merge_greedy.py +15 -0
  101. structuremappingmemory-1.0.0/sma/match/mh.py +177 -0
  102. structuremappingmemory-1.0.0/sma/match/ses.py +84 -0
  103. structuremappingmemory-1.0.0/sma/match/types.py +115 -0
  104. structuremappingmemory-1.0.0/sma/match/verifier.py +27 -0
  105. structuremappingmemory-1.0.0/sma/ontology/__init__.py +45 -0
  106. structuremappingmemory-1.0.0/sma/ontology/attack.py +134 -0
  107. structuremappingmemory-1.0.0/sma/ontology/cpc.py +69 -0
  108. structuremappingmemory-1.0.0/sma/ontology/graph.py +58 -0
  109. structuremappingmemory-1.0.0/sma/ontology/loader.py +262 -0
  110. structuremappingmemory-1.0.0/sma/ontology/mitre_xml.py +67 -0
  111. structuremappingmemory-1.0.0/sma/ontology/mount.py +101 -0
  112. structuremappingmemory-1.0.0/sma/ontology/rdf_loader.py +75 -0
  113. structuremappingmemory-1.0.0/sma/ontology/registry.py +115 -0
  114. structuremappingmemory-1.0.0/sma/ontology/router.py +69 -0
  115. structuremappingmemory-1.0.0/sma/ontology/usgaap.py +73 -0
  116. structuremappingmemory-1.0.0/sma/sage/__init__.py +6 -0
  117. structuremappingmemory-1.0.0/sma/sage/assimilate.py +12 -0
  118. structuremappingmemory-1.0.0/sma/sage/pools.py +105 -0
  119. structuremappingmemory-1.0.0/sma/sage/probabilities.py +10 -0
  120. structuremappingmemory-1.0.0/sma/store/__init__.py +6 -0
  121. structuremappingmemory-1.0.0/sma/store/lmdb_store.py +78 -0
  122. structuremappingmemory-1.0.0/sma/store/registry.py +26 -0
  123. structuremappingmemory-1.0.0/sma/store/wal.py +26 -0
  124. structuremappingmemory-1.0.0/sma/ui/app.py +642 -0
  125. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/PKG-INFO +190 -0
  126. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/SOURCES.txt +134 -0
  127. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/dependency_links.txt +1 -0
  128. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/entry_points.txt +2 -0
  129. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/requires.txt +36 -0
  130. structuremappingmemory-1.0.0/structuremappingmemory.egg-info/top_level.txt +1 -0
  131. structuremappingmemory-1.0.0/tests/test_bugsinpy_t3.py +95 -0
  132. structuremappingmemory-1.0.0/tests/test_drift.py +184 -0
  133. structuremappingmemory-1.0.0/tests/test_gates.py +246 -0
  134. structuremappingmemory-1.0.0/tests/test_hipporag.py +75 -0
  135. structuremappingmemory-1.0.0/tests/test_production_loop.py +256 -0
  136. structuremappingmemory-1.0.0/tests/test_stats.py +131 -0
@@ -0,0 +1,204 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ Copyright 2026 Ayaz Khan and SMA-1 contributors
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: structuremappingmemory
3
+ Version: 1.0.0
4
+ Summary: SMA-1: Structure-Mapping Agentic Memory — a structure-mapping retrieval memory that grounds language models in curated ontologies
5
+ Author-email: Ayaz Khan <aak2259@columbia.edu>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ayazkhan27/SMA-1
8
+ Project-URL: Repository, https://github.com/ayazkhan27/SMA-1
9
+ Project-URL: Issues, https://github.com/ayazkhan27/SMA-1/issues
10
+ Keywords: structure-mapping,analogical-retrieval,ontology,retrieval-augmented-generation,abstention,novelty-detection,trustworthy-ai,knowledge-graph
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: blake3>=0.4
21
+ Requires-Dist: fastapi>=0.110
22
+ Requires-Dist: gradio>=4.44
23
+ Requires-Dist: hnswlib>=0.8
24
+ Requires-Dist: lmdb>=1.4
25
+ Requires-Dist: numpy>=1.26
26
+ Requires-Dist: ortools>=9.10
27
+ Requires-Dist: pydantic>=2
28
+ Requires-Dist: pytest>=8
29
+ Requires-Dist: hypothesis>=6
30
+ Requires-Dist: rank-bm25>=0.2.2
31
+ Requires-Dist: regex>=2024.5.15
32
+ Requires-Dist: scikit-learn>=1.5
33
+ Requires-Dist: typer>=0.12
34
+ Requires-Dist: zstandard>=0.22
35
+ Provides-Extra: encoders
36
+ Requires-Dist: drain3>=0.9.11; extra == "encoders"
37
+ Requires-Dist: tree-sitter>=0.23; extra == "encoders"
38
+ Requires-Dist: tree-sitter-language-pack>=0.7; extra == "encoders"
39
+ Requires-Dist: nltk>=3.9; extra == "encoders"
40
+ Requires-Dist: stanza>=1.8; extra == "encoders"
41
+ Provides-Extra: eval
42
+ Requires-Dist: langchain>=0.2; extra == "eval"
43
+ Requires-Dist: langchain-community>=0.2; extra == "eval"
44
+ Requires-Dist: rank-bm25>=0.2.2; extra == "eval"
45
+ Requires-Dist: ranx>=0.3.20; extra == "eval"
46
+ Requires-Dist: sentence-transformers>=3; extra == "eval"
47
+ Requires-Dist: statsmodels>=0.14; extra == "eval"
48
+ Requires-Dist: kuzu>=0.6; extra == "eval"
49
+ Requires-Dist: networkx>=3; extra == "eval"
50
+ Provides-Extra: local-llm
51
+ Requires-Dist: huggingface-hub>=0.23; extra == "local-llm"
52
+ Requires-Dist: llama-cpp-python>=0.2.90; extra == "local-llm"
53
+ Dynamic: license-file
54
+
55
+ # SMA-1: Structure-Mapping Agentic Memory
56
+
57
+ [![CI](https://github.com/ayazkhan27/SMA-1/actions/workflows/ci.yml/badge.svg)](https://github.com/ayazkhan27/SMA-1/actions/workflows/ci.yml)
58
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
59
+ [![HF Space](https://img.shields.io/badge/%F0%9F%A4%97%20Demo-Space-orange)](https://huggingface.co/spaces/zephyr27/SMA-1-demo)
60
+
61
+ **Structure-mapping memory grounds language models in curated ontologies.** SMA is
62
+ a retrieval *memory* that grounds a generalist LLM in a **curated,
63
+ expert-maintained ontology**, retrieving by **logical structure** — subsumption
64
+ (is-a) and higher-order relations — that vector RAG and knowledge graphs discard. Holding the language model and prompt fixed and swapping
65
+ only the memory, the SMA-grounded agent becomes **more accurate, more selective,
66
+ and more structurally attributable** than vector RAG: it cites its evidence
67
+ structurally, abstains when nothing grounds the case, and flags novelty —
68
+ capabilities flat retrievers structurally lack. On the real-domain benchmarks the
69
+ measured advantage is carried by bounded is-a subsumption plus information-content
70
+ weighting (the higher-order relational machinery is decisive only on a synthetic
71
+ structure-only control), and it vanishes where no discriminative ontology applies.
72
+
73
+ ![SMA process tour](docs/assets/sma_tour.gif)
74
+
75
+ > A structure-mapping memory over a curated ontology grounds a generalist LLM by
76
+ > the subsumption hierarchy and rarity weighting that flat retrievers wash out —
77
+ > and the structural alignment itself is what survives when there is no surface
78
+ > signal at all.
79
+
80
+ ---
81
+
82
+ ## What it does
83
+
84
+ | Capability | SMA | Vector RAG | Knowledge graph |
85
+ |---|:--:|:--:|:--:|
86
+ | Rare / long-tail retrieval (rarity-weighted) | ✅ | ✗ averages rarity away | ✗ |
87
+ | Cross-vocabulary / zero-lexical-overlap match | ✅ | ✗ | partial |
88
+ | Subsumption (is-a) reasoning | ✅ | ✗ | ✗ no ascension |
89
+ | Structural citation (checkable provenance) | ✅ | ✗ | partial |
90
+ | Calibrated abstention | ✅ | ✗ cosine always "high" | ✗ |
91
+ | Novelty / expectation-violation flag | ✅ | ✗ | partial |
92
+
93
+ One **universal loader** ingests any open OBO/OWL/STIX/CPC ontology (is-a hierarchy
94
+ plus typed relations, no OWL reasoning); a **registry + domain router** select
95
+ across domains. We mount eleven ontologies spanning seven knowledge areas
96
+ (≈594,000 concepts) behind one shared retrieval core plus thin per-domain data
97
+ adapters.
98
+
99
+ ![SMA system overview](docs/assets/fig1_overview.png)
100
+
101
+ ## Headline results (honest)
102
+
103
+ On a **memory-swap benchmark** where only the retriever varies, SMA beats a strong
104
+ RAG + KG baseline suite on the rare/long-tail slice across five domains:
105
+
106
+ | Domain | SMA tail top-5 | best RAG | Δ | Holm-significant |
107
+ |---|:--:|:--:|:--:|:--:|
108
+ | Medicine (HPO/MONDO) | 0.949 | 0.606 | **+0.333** | yes |
109
+ | Finance (US-GAAP) | 0.418 | 0.231 | **+0.167** | yes |
110
+ | Genomics (GO) | 0.849 | 0.682 | **+0.156** | yes |
111
+ | Legal (CPC, all-query) | 0.941 | 0.870 | **+0.064** | yes |
112
+ | Cyber (ATT&CK) | 0.766 | 0.749 | +0.073 | directional* |
113
+
114
+ \* Cyber survives Holm across domains but not a conservative
115
+ Bonferroni-over-baselines selection correction (p=0.035 → 0.17); reported as
116
+ directional. End to end (medicine, LLM-in-the-loop), the SMA-grounded agent is the
117
+ most accurate (0.342 vs dense 0.100 vs closed-book 0.017), most faithful in
118
+ citation, and uniquely separates known from unknown entities (grounding AUROC 0.79
119
+ vs vector RAG's near-chance 0.55).
120
+
121
+ **Where it does not help (reported, not hidden):** SMA *ties* a bespoke ontology
122
+ information-content oracle (Phenomizer) rather than beating it; and on
123
+ **flat single-record tabular prediction** (hospital readmission, credit-card
124
+ fraud, the Elliptic Bitcoin graph-fraud probe) there is no discriminative
125
+ subsumption ontology to mount, so SMA reaches only parity and a flat
126
+ logistic-regression baseline wins. The advantage is specific to structure.
127
+
128
+ ## How it works
129
+
130
+ ![SMA architecture](docs/assets/architecture.png)
131
+
132
+ 1. **Adapter** — a universal loader parses any open ontology into a normalized
133
+ graph, **mounts** the is-a hierarchy as an *ascension lattice* (specific terms
134
+ match general ones with penalty ρ^dist) and the typed relations as higher-order
135
+ cases, and registers them behind a per-query domain router.
136
+ 2. **Matcher** — a case (functors over a subject) is screened by a certified
137
+ **MAC** admissible-content bound, aligned by best-first structure-mapping
138
+ (**FAC/SME**), and scored by a rarity-weighted **information-content** (−log₂ p)
139
+ surprisal scorer.
140
+ 3. **Decision** — the alignment yields a **structural citation**, a **calibrated
141
+ abstention**, or a **novelty flag** (SAGE expectation violation).
142
+
143
+ ## Quick start
144
+
145
+ ```bash
146
+ python -m venv .venv && . .venv/bin/activate
147
+ pip install -e ".[encoders,eval]"
148
+ pytest -m "gate_G0 or gate_G1 or gate_G2 or gate_G3 or gate_G4 or gate_G5 or gate_G6"
149
+ sma ui # FastAPI + Gradio demo
150
+ ```
151
+
152
+ Raw datasets are not tracked. Fetch checksum-verified external data with:
153
+
154
+ ```bash
155
+ python scripts/fetch_datasets.py --manifest data/manifests/datasets.json
156
+ ```
157
+
158
+ Reproduce the confirmatory tables/figures from committed CSVs:
159
+
160
+ ```bash
161
+ python scripts/figures_paper.py # main-text figures
162
+ python scripts/figures_ed.py # Extended Data figures
163
+ ```
164
+
165
+ All result numbers in the paper trace to `reports/confirmatory/*.csv`; runs are
166
+ deterministic (`PYTHONHASHSEED=0`, paired bootstrap seeded at 12345).
167
+
168
+ ## Repository layout
169
+
170
+ | Path | Contents |
171
+ |---|---|
172
+ | `sma/ontology/` | universal ontology adapter (loaders, mount, registry, router) — **frozen `adapter-v1`** |
173
+ | `sma/eval/agentic/` | memory-swap retrieval harness + baseline arms |
174
+ | `sma/eval/agentic_qa/` | end-to-end LLM-QA agent (pre-registration v2) |
175
+ | `scripts/` | dataset fetch, figure/table generators, ablations |
176
+ | `reports/confirmatory/` | all result CSVs (every paper number sources here) |
177
+ | `paper/manuscript/` | `sma_nature_mi.tex` — the manuscript (Nature `sn-jnl` template) |
178
+ | `release/` | model card, dataset card, HuggingFace Space |
179
+
180
+ ## Paper & citation
181
+
182
+ The manuscript (`paper/manuscript/sma_nature_mi.tex`, intended for *Nature Machine
183
+ Intelligence*) is built on the official Springer Nature `sn-jnl` template. To cite
184
+ this software, see [`CITATION.cff`](CITATION.cff).
185
+
186
+ ## License
187
+
188
+ Apache-2.0. All mounted ontologies are openly licensed and version-pinned; we
189
+ redistribute only derived gold labels, never restricted source records (see
190
+ Extended Data and `release/model_card.md`).
@@ -0,0 +1,136 @@
1
+ # SMA-1: Structure-Mapping Agentic Memory
2
+
3
+ [![CI](https://github.com/ayazkhan27/SMA-1/actions/workflows/ci.yml/badge.svg)](https://github.com/ayazkhan27/SMA-1/actions/workflows/ci.yml)
4
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
5
+ [![HF Space](https://img.shields.io/badge/%F0%9F%A4%97%20Demo-Space-orange)](https://huggingface.co/spaces/zephyr27/SMA-1-demo)
6
+
7
+ **Structure-mapping memory grounds language models in curated ontologies.** SMA is
8
+ a retrieval *memory* that grounds a generalist LLM in a **curated,
9
+ expert-maintained ontology**, retrieving by **logical structure** — subsumption
10
+ (is-a) and higher-order relations — that vector RAG and knowledge graphs discard. Holding the language model and prompt fixed and swapping
11
+ only the memory, the SMA-grounded agent becomes **more accurate, more selective,
12
+ and more structurally attributable** than vector RAG: it cites its evidence
13
+ structurally, abstains when nothing grounds the case, and flags novelty —
14
+ capabilities flat retrievers structurally lack. On the real-domain benchmarks the
15
+ measured advantage is carried by bounded is-a subsumption plus information-content
16
+ weighting (the higher-order relational machinery is decisive only on a synthetic
17
+ structure-only control), and it vanishes where no discriminative ontology applies.
18
+
19
+ ![SMA process tour](docs/assets/sma_tour.gif)
20
+
21
+ > A structure-mapping memory over a curated ontology grounds a generalist LLM by
22
+ > the subsumption hierarchy and rarity weighting that flat retrievers wash out —
23
+ > and the structural alignment itself is what survives when there is no surface
24
+ > signal at all.
25
+
26
+ ---
27
+
28
+ ## What it does
29
+
30
+ | Capability | SMA | Vector RAG | Knowledge graph |
31
+ |---|:--:|:--:|:--:|
32
+ | Rare / long-tail retrieval (rarity-weighted) | ✅ | ✗ averages rarity away | ✗ |
33
+ | Cross-vocabulary / zero-lexical-overlap match | ✅ | ✗ | partial |
34
+ | Subsumption (is-a) reasoning | ✅ | ✗ | ✗ no ascension |
35
+ | Structural citation (checkable provenance) | ✅ | ✗ | partial |
36
+ | Calibrated abstention | ✅ | ✗ cosine always "high" | ✗ |
37
+ | Novelty / expectation-violation flag | ✅ | ✗ | partial |
38
+
39
+ One **universal loader** ingests any open OBO/OWL/STIX/CPC ontology (is-a hierarchy
40
+ plus typed relations, no OWL reasoning); a **registry + domain router** select
41
+ across domains. We mount eleven ontologies spanning seven knowledge areas
42
+ (≈594,000 concepts) behind one shared retrieval core plus thin per-domain data
43
+ adapters.
44
+
45
+ ![SMA system overview](docs/assets/fig1_overview.png)
46
+
47
+ ## Headline results (honest)
48
+
49
+ On a **memory-swap benchmark** where only the retriever varies, SMA beats a strong
50
+ RAG + KG baseline suite on the rare/long-tail slice across five domains:
51
+
52
+ | Domain | SMA tail top-5 | best RAG | Δ | Holm-significant |
53
+ |---|:--:|:--:|:--:|:--:|
54
+ | Medicine (HPO/MONDO) | 0.949 | 0.606 | **+0.333** | yes |
55
+ | Finance (US-GAAP) | 0.418 | 0.231 | **+0.167** | yes |
56
+ | Genomics (GO) | 0.849 | 0.682 | **+0.156** | yes |
57
+ | Legal (CPC, all-query) | 0.941 | 0.870 | **+0.064** | yes |
58
+ | Cyber (ATT&CK) | 0.766 | 0.749 | +0.073 | directional* |
59
+
60
+ \* Cyber survives Holm across domains but not a conservative
61
+ Bonferroni-over-baselines selection correction (p=0.035 → 0.17); reported as
62
+ directional. End to end (medicine, LLM-in-the-loop), the SMA-grounded agent is the
63
+ most accurate (0.342 vs dense 0.100 vs closed-book 0.017), most faithful in
64
+ citation, and uniquely separates known from unknown entities (grounding AUROC 0.79
65
+ vs vector RAG's near-chance 0.55).
66
+
67
+ **Where it does not help (reported, not hidden):** SMA *ties* a bespoke ontology
68
+ information-content oracle (Phenomizer) rather than beating it; and on
69
+ **flat single-record tabular prediction** (hospital readmission, credit-card
70
+ fraud, the Elliptic Bitcoin graph-fraud probe) there is no discriminative
71
+ subsumption ontology to mount, so SMA reaches only parity and a flat
72
+ logistic-regression baseline wins. The advantage is specific to structure.
73
+
74
+ ## How it works
75
+
76
+ ![SMA architecture](docs/assets/architecture.png)
77
+
78
+ 1. **Adapter** — a universal loader parses any open ontology into a normalized
79
+ graph, **mounts** the is-a hierarchy as an *ascension lattice* (specific terms
80
+ match general ones with penalty ρ^dist) and the typed relations as higher-order
81
+ cases, and registers them behind a per-query domain router.
82
+ 2. **Matcher** — a case (functors over a subject) is screened by a certified
83
+ **MAC** admissible-content bound, aligned by best-first structure-mapping
84
+ (**FAC/SME**), and scored by a rarity-weighted **information-content** (−log₂ p)
85
+ surprisal scorer.
86
+ 3. **Decision** — the alignment yields a **structural citation**, a **calibrated
87
+ abstention**, or a **novelty flag** (SAGE expectation violation).
88
+
89
+ ## Quick start
90
+
91
+ ```bash
92
+ python -m venv .venv && . .venv/bin/activate
93
+ pip install -e ".[encoders,eval]"
94
+ pytest -m "gate_G0 or gate_G1 or gate_G2 or gate_G3 or gate_G4 or gate_G5 or gate_G6"
95
+ sma ui # FastAPI + Gradio demo
96
+ ```
97
+
98
+ Raw datasets are not tracked. Fetch checksum-verified external data with:
99
+
100
+ ```bash
101
+ python scripts/fetch_datasets.py --manifest data/manifests/datasets.json
102
+ ```
103
+
104
+ Reproduce the confirmatory tables/figures from committed CSVs:
105
+
106
+ ```bash
107
+ python scripts/figures_paper.py # main-text figures
108
+ python scripts/figures_ed.py # Extended Data figures
109
+ ```
110
+
111
+ All result numbers in the paper trace to `reports/confirmatory/*.csv`; runs are
112
+ deterministic (`PYTHONHASHSEED=0`, paired bootstrap seeded at 12345).
113
+
114
+ ## Repository layout
115
+
116
+ | Path | Contents |
117
+ |---|---|
118
+ | `sma/ontology/` | universal ontology adapter (loaders, mount, registry, router) — **frozen `adapter-v1`** |
119
+ | `sma/eval/agentic/` | memory-swap retrieval harness + baseline arms |
120
+ | `sma/eval/agentic_qa/` | end-to-end LLM-QA agent (pre-registration v2) |
121
+ | `scripts/` | dataset fetch, figure/table generators, ablations |
122
+ | `reports/confirmatory/` | all result CSVs (every paper number sources here) |
123
+ | `paper/manuscript/` | `sma_nature_mi.tex` — the manuscript (Nature `sn-jnl` template) |
124
+ | `release/` | model card, dataset card, HuggingFace Space |
125
+
126
+ ## Paper & citation
127
+
128
+ The manuscript (`paper/manuscript/sma_nature_mi.tex`, intended for *Nature Machine
129
+ Intelligence*) is built on the official Springer Nature `sn-jnl` template. To cite
130
+ this software, see [`CITATION.cff`](CITATION.cff).
131
+
132
+ ## License
133
+
134
+ Apache-2.0. All mounted ontologies are openly licensed and version-pinned; we
135
+ redistribute only derived gold labels, never restricted source records (see
136
+ Extended Data and `release/model_card.md`).
@@ -0,0 +1,91 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ # PyPI distribution name (the import name stays `sma`); `sma` is taken on PyPI.
7
+ name = "structuremappingmemory"
8
+ version = "1.0.0"
9
+ description = "SMA-1: Structure-Mapping Agentic Memory — a structure-mapping retrieval memory that grounds language models in curated ontologies"
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ license = {text = "Apache-2.0"}
13
+ authors = [{name = "Ayaz Khan", email = "aak2259@columbia.edu"}]
14
+ keywords = ["structure-mapping", "analogical-retrieval", "ontology", "retrieval-augmented-generation", "abstention", "novelty-detection", "trustworthy-ai", "knowledge-graph"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ ]
23
+ dependencies = [
24
+ "blake3>=0.4",
25
+ "fastapi>=0.110",
26
+ "gradio>=4.44",
27
+ "hnswlib>=0.8",
28
+ "lmdb>=1.4",
29
+ "numpy>=1.26",
30
+ "ortools>=9.10",
31
+ "pydantic>=2",
32
+ "pytest>=8",
33
+ "hypothesis>=6",
34
+ "rank-bm25>=0.2.2",
35
+ "regex>=2024.5.15",
36
+ "scikit-learn>=1.5",
37
+ "typer>=0.12",
38
+ "zstandard>=0.22"
39
+ ]
40
+
41
+ [project.optional-dependencies]
42
+ encoders = [
43
+ "drain3>=0.9.11",
44
+ "tree-sitter>=0.23",
45
+ "tree-sitter-language-pack>=0.7",
46
+ "nltk>=3.9",
47
+ "stanza>=1.8"
48
+ ]
49
+ eval = [
50
+ "langchain>=0.2",
51
+ "langchain-community>=0.2",
52
+ "rank-bm25>=0.2.2",
53
+ "ranx>=0.3.20",
54
+ "sentence-transformers>=3",
55
+ "statsmodels>=0.14",
56
+ "kuzu>=0.6",
57
+ "networkx>=3"
58
+ ]
59
+ local-llm = [
60
+ "huggingface-hub>=0.23",
61
+ "llama-cpp-python>=0.2.90"
62
+ ]
63
+
64
+ [project.urls]
65
+ Homepage = "https://github.com/ayazkhan27/SMA-1"
66
+ Repository = "https://github.com/ayazkhan27/SMA-1"
67
+ Issues = "https://github.com/ayazkhan27/SMA-1/issues"
68
+
69
+ [project.scripts]
70
+ sma = "sma.cli:main"
71
+
72
+ [tool.setuptools.packages.find]
73
+ include = ["sma*"]
74
+
75
+ [tool.pytest.ini_options]
76
+ addopts = "-q"
77
+ testpaths = ["tests"]
78
+ markers = [
79
+ "gate_G0: bootstrap and artifact checks",
80
+ "gate_G1: IR and store checks",
81
+ "gate_G2: matcher checks",
82
+ "gate_G3: encoder checks",
83
+ "gate_G4: retrieval checks",
84
+ "gate_G5: API and provenance policy checks",
85
+ "gate_G6: SAGE checks",
86
+ "slow: long-running checks"
87
+ ]
88
+
89
+ [tool.ruff]
90
+ line-length = 100
91
+ target-version = "py311"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """SMA-1: Structure-Mapping Agentic Memory MVP."""
2
+
3
+ __all__ = ["__version__"]
4
+ __version__ = "0.1.0"
5
+
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
5
+
@@ -0,0 +1,5 @@
1
+ from .policies import reject_free_text_facts, require_provenance
2
+ from .service import MemoryService
3
+
4
+ __all__ = ["MemoryService", "reject_free_text_facts", "require_provenance"]
5
+