geny-memory-adaptor 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,152 @@
1
+ name: CI — geny-memory-adaptor (library)
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: [main]
7
+ paths:
8
+ - "src/**"
9
+ - "tests/**"
10
+ - "pyproject.toml"
11
+ pull_request:
12
+ branches: [main]
13
+
14
+ concurrency:
15
+ group: ci-lib-${{ github.ref }}
16
+ cancel-in-progress: true
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ lint:
23
+ name: Lint
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+
28
+ - name: Set up Python
29
+ uses: actions/setup-python@v5
30
+ with:
31
+ python-version: "3.11"
32
+
33
+ - name: Install dependencies
34
+ run: pip install ruff
35
+
36
+ - name: Run ruff check
37
+ run: ruff check src/ tests/
38
+
39
+ - name: Run ruff format check
40
+ run: ruff format --check src/ tests/
41
+
42
+ type-check:
43
+ name: Type check (mypy beachhead)
44
+ runs-on: ubuntu-latest
45
+ steps:
46
+ - uses: actions/checkout@v4
47
+
48
+ - name: Set up Python
49
+ uses: actions/setup-python@v5
50
+ with:
51
+ python-version: "3.11"
52
+
53
+ - name: Install dependencies
54
+ run: |
55
+ pip install --upgrade pip
56
+ pip install -e ".[dev]"
57
+
58
+ # Typed-surface beachhead: the package ships `py.typed`, so the
59
+ # surfaces hosts import against (core/ + llm_client/) are gated.
60
+ # Config lives in [tool.mypy] in pyproject.toml — widen the package
61
+ # list there as more modules come clean.
62
+ - name: Run mypy (core + llm_client)
63
+ run: mypy src/geny_executor/core src/geny_executor/llm_client
64
+
65
+ # docs/events.md is generated from the EventTypes catalogue; fail
66
+ # if an event landed without regenerating the doc.
67
+ - name: Check docs/events.md is current
68
+ run: python scripts/gen_event_docs.py --check
69
+
70
+ test:
71
+ name: Test (Python ${{ matrix.python-version }})
72
+ runs-on: ubuntu-latest
73
+ strategy:
74
+ fail-fast: false
75
+ matrix:
76
+ python-version: ["3.11", "3.12", "3.13"]
77
+
78
+ steps:
79
+ - uses: actions/checkout@v4
80
+
81
+ - name: Set up Python ${{ matrix.python-version }}
82
+ uses: actions/setup-python@v5
83
+ with:
84
+ python-version: ${{ matrix.python-version }}
85
+
86
+ - name: Install dependencies
87
+ run: |
88
+ pip install --upgrade pip
89
+ pip install -e ".[dev]"
90
+
91
+ # Full suite — tests/ also contains llm_client/, contract/ and
92
+ # completeness/ beyond unit/ + integration/; running per-directory
93
+ # subsets silently skipped them on 3.12/3.13 (audit 2026-06-09 §completeness).
94
+ - name: Run full test suite
95
+ if: matrix.python-version != '3.11'
96
+ run: pytest --tb=short -q
97
+
98
+ - name: Run full test suite with coverage
99
+ if: matrix.python-version == '3.11'
100
+ run: pytest tests/ --cov=geny_executor --cov-report=term-missing --cov-report=xml
101
+
102
+ - name: Upload coverage
103
+ if: matrix.python-version == '3.11'
104
+ uses: actions/upload-artifact@v4
105
+ with:
106
+ name: coverage-report
107
+ path: coverage.xml
108
+
109
+ security-audit:
110
+ name: Security audit
111
+ runs-on: ubuntu-latest
112
+ steps:
113
+ - uses: actions/checkout@v4
114
+ - uses: actions/setup-python@v5
115
+ with:
116
+ python-version: "3.12"
117
+ - run: pip install --upgrade pip && pip install pip-audit
118
+ - run: pip install -e .
119
+ # CVE-2026-3219 affects pip 26.x itself; the CI runner installs an
120
+ # affected pip and there is no fix release as of this commit.
121
+ # Ignore the single CVE so the audit keeps catching real issues
122
+ # in our dependency tree. Revisit once pip ships a fix.
123
+ - run: pip-audit --ignore-vuln CVE-2026-3219
124
+
125
+ build:
126
+ name: Build package
127
+ runs-on: ubuntu-latest
128
+ needs: [lint, type-check, test, security-audit]
129
+ steps:
130
+ - uses: actions/checkout@v4
131
+
132
+ - name: Set up Python
133
+ uses: actions/setup-python@v5
134
+ with:
135
+ python-version: "3.11"
136
+
137
+ - name: Install build tools
138
+ run: pip install build
139
+
140
+ - name: Build sdist and wheel
141
+ run: python -m build
142
+
143
+ - name: Check package metadata
144
+ run: |
145
+ pip install twine
146
+ twine check dist/*
147
+
148
+ - name: Upload build artifacts
149
+ uses: actions/upload-artifact@v4
150
+ with:
151
+ name: dist
152
+ path: dist/
@@ -0,0 +1,139 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+ inputs:
8
+ target:
9
+ description: "Publish target"
10
+ required: true
11
+ default: "testpypi"
12
+ type: choice
13
+ options:
14
+ - testpypi
15
+ - pypi
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ build:
22
+ name: Build package
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+
27
+ - name: Set up Python
28
+ uses: actions/setup-python@v5
29
+ with:
30
+ python-version: "3.11"
31
+
32
+ # Release gate: every published version must have a CHANGELOG
33
+ # section. 2.1.0 shipped without one (audit 2026-06-09 §3.7) and
34
+ # became the version a host pinned with no record of what it
35
+ # contained — this step makes that mistake impossible to repeat.
36
+ - name: Release gate — CHANGELOG entry for this version
37
+ run: |
38
+ python - <<'EOF'
39
+ import re
40
+ import sys
41
+ import tomllib
42
+
43
+ with open("pyproject.toml", "rb") as f:
44
+ version = tomllib.load(f)["project"]["version"]
45
+ with open("CHANGELOG.md", encoding="utf-8") as f:
46
+ changelog = f.read()
47
+
48
+ # Match '## [<version>]' at line start; separator after the
49
+ # bracket (em-dash / hyphen / nothing) is intentionally free.
50
+ if not re.search(rf"^## \[{re.escape(version)}\]", changelog, re.MULTILINE):
51
+ sys.exit(
52
+ f"RELEASE GATE FAILED: CHANGELOG.md has no '## [{version}]' "
53
+ f"section for pyproject version {version}. Add the entry "
54
+ "before publishing."
55
+ )
56
+ print(f"Release gate OK: CHANGELOG.md documents [{version}].")
57
+ EOF
58
+
59
+ - name: Install build tools
60
+ run: pip install build
61
+
62
+ - name: Build sdist and wheel
63
+ run: python -m build
64
+
65
+ - name: Check package metadata
66
+ run: |
67
+ pip install twine
68
+ twine check dist/*
69
+
70
+ - name: Upload build artifacts
71
+ uses: actions/upload-artifact@v4
72
+ with:
73
+ name: dist
74
+ path: dist/
75
+
76
+ test:
77
+ name: Verify tests pass
78
+ runs-on: ubuntu-latest
79
+ steps:
80
+ - uses: actions/checkout@v4
81
+
82
+ - name: Set up Python
83
+ uses: actions/setup-python@v5
84
+ with:
85
+ python-version: "3.11"
86
+
87
+ - name: Install dependencies
88
+ run: |
89
+ pip install --upgrade pip
90
+ pip install -e ".[dev]"
91
+
92
+ - name: Run tests
93
+ run: pytest --tb=short -q
94
+
95
+ publish-testpypi:
96
+ name: Publish to TestPyPI
97
+ needs: [build, test]
98
+ if: >-
99
+ github.event_name == 'release' ||
100
+ (github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi')
101
+ runs-on: ubuntu-latest
102
+ environment:
103
+ name: testpypi
104
+ url: https://test.pypi.org/p/geny-memory-adaptor
105
+ permissions:
106
+ id-token: write
107
+ steps:
108
+ - name: Download build artifacts
109
+ uses: actions/download-artifact@v4
110
+ with:
111
+ name: dist
112
+ path: dist/
113
+
114
+ - name: Publish to TestPyPI
115
+ uses: pypa/gh-action-pypi-publish@release/v1
116
+ with:
117
+ repository-url: https://test.pypi.org/legacy/
118
+
119
+ publish-pypi:
120
+ name: Publish to PyPI
121
+ needs: [build, test]
122
+ if: >-
123
+ github.event_name == 'release' ||
124
+ (github.event_name == 'workflow_dispatch' && inputs.target == 'pypi')
125
+ runs-on: ubuntu-latest
126
+ environment:
127
+ name: pypi
128
+ url: https://pypi.org/p/geny-memory-adaptor
129
+ permissions:
130
+ id-token: write
131
+ steps:
132
+ - name: Download build artifacts
133
+ uses: actions/download-artifact@v4
134
+ with:
135
+ name: dist
136
+ path: dist/
137
+
138
+ - name: Publish to PyPI
139
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.pyc
3
+ dist/
4
+ build/
5
+ *.egg-info/
6
+ .venv/
7
+ *.db
8
+ *.db-wal
9
+ *.db-shm
10
+ *.emb.npz
11
+ .env
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] — 2026-07-20
4
+
5
+ Initial release — the Synapse engine.
6
+
7
+ - Hybrid retrieval: BM25 (unicode words + char 2/3-grams, Korean-friendly)
8
+ ∪ local static hash embeddings (65,536×256 fp16), RRF-fused seeds.
9
+ - Graph layer: typed edges (LINK / TAG / KNN / CO-ACCESS) with one
10
+ Personalized PageRank per type as ranking features; adjacency cached and
11
+ row-normalized once per mutation.
12
+ - Learning: Hebbian co-access reinforcement with lazy decay; pairwise
13
+ logistic online SGD ranker (14→16→1 MLP, numpy) behind a safety blend
14
+ gate (heuristic performance floor); ε-greedy tail exploration.
15
+ - Distillation: fit the embedding table to caller-provided teacher vectors
16
+ (Adam, geometry-correlation swap gate) — zero API calls ever.
17
+ - One SQLite file (WAL) + fp16 npz table; config via args / GMA_* env / .env.
18
+ - geny-executor duck-typed adapter (SynapseVectorHandle, SynapseRetriever).
19
+ - 17 tests; bench: 0.7 ms/doc indexing, 8.7 ms/query @ 2,000 docs.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: geny-memory-adaptor
3
+ Version: 0.1.0
4
+ Summary: Synapse — a learnable, lightweight graph-traversal memory engine: BM25 + local static embeddings + typed-edge PageRank + an online-learned ranker, in one SQLite file with zero API calls.
5
+ Project-URL: Homepage, https://github.com/CocoRoF/geny-memory-adaptor
6
+ Project-URL: Repository, https://github.com/CocoRoF/geny-memory-adaptor
7
+ Project-URL: Changelog, https://github.com/CocoRoF/geny-memory-adaptor/blob/main/CHANGELOG.md
8
+ Author: CocoRoF
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agent,bm25,embeddings,graph,memory,online-learning,pagerank,retrieval
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: numpy>=1.24
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
23
+ Requires-Dist: pytest>=8; extra == 'dev'
24
+ Requires-Dist: ruff>=0.6; extra == 'dev'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # geny-memory-adaptor
28
+
29
+ **Synapse** — a learnable, lightweight graph-traversal memory engine for AI agents.
30
+
31
+ Semantic search (local static embeddings) **+** keyword search (BM25) **+** graph
32
+ traversal (typed-edge Personalized PageRank), fused by a tiny **online-learned
33
+ ranker** that adapts to how your agent actually uses its memories. Everything
34
+ lives in **one SQLite file**. `numpy` is the only dependency. **Zero API calls,
35
+ zero servers, zero idle cost** — every operation is CPU milliseconds.
36
+
37
+ ```
38
+ pip install geny-memory-adaptor
39
+ ```
40
+
41
+ ## Why
42
+
43
+ Typical agent memory stacks pay an embedding API call per write AND per query,
44
+ need a vector server, and never learn: every ranking weight is a hard-coded
45
+ constant. Synapse inverts all three:
46
+
47
+ | | typical stack | Synapse |
48
+ |---|---|---|
49
+ | query cost | 1 embedding API call + vector store op | **0 API calls, ~3–9 ms CPU** (500–2,000 docs) |
50
+ | write cost | 1 embedding API call + index rebuild | **~0.3–0.7 ms**, incremental SQLite upserts |
51
+ | infrastructure | vector DB / server | **one .db file** (+ a 32 MB fp16 table) |
52
+ | learning | none | **online, per-event, microseconds** |
53
+
54
+ ## Quick start
55
+
56
+ ```python
57
+ from geny_memory_adaptor import SynapseMemory
58
+
59
+ mem = SynapseMemory.open("vault/synapse.db") # or SynapseMemory.from_env()
60
+
61
+ # Write — idempotent by id. Links/tags feed the graph.
62
+ mem.index("note-1", "리듬게임에서 판정을 읽는 건 손이 먼저다",
63
+ title="리듬게임 판정", tags=["게임"], links=["note-0"])
64
+
65
+ # Read — BM25 ∪ cosine seeds → per-type PageRank expansion → learned ranking.
66
+ hits = mem.search("리듬게임 판정", top_k=8)
67
+ for h in hits:
68
+ print(h.id, round(h.score, 3), h.sources) # e.g. ['bm25', 'vector', 'graph']
69
+
70
+ # Learn — tell it which shown memories were actually used.
71
+ mem.feedback(hits[0].query_token, used_ids=["note-1"])
72
+
73
+ # Optionally distill: if you already have better embeddings lying around
74
+ # (e.g. previously paid-for API vectors), hand them in as teachers…
75
+ mem.index("note-2", "text …", teacher_vec=my_stored_api_embedding)
76
+ mem.distill() # bounded batch job; swaps the table ONLY if geometry improves
77
+
78
+ mem.close()
79
+ ```
80
+
81
+ ### Configuration
82
+
83
+ Everything is a constructor argument, an environment variable (`GMA_*`), or a
84
+ `.env` file — in that precedence order:
85
+
86
+ ```python
87
+ from geny_memory_adaptor import SynapseConfig, SynapseMemory
88
+ mem = SynapseMemory(SynapseConfig(path="synapse.db", dim=256, top_k=8))
89
+ # or
90
+ mem = SynapseMemory.from_env(dotenv=".env") # GMA_PATH, GMA_DIM, GMA_TOP_K, …
91
+ ```
92
+
93
+ ## How it works
94
+
95
+ ```
96
+ write ─ tokenize (words + char 2/3-grams; Korean-friendly, no morphology dep)
97
+ ─ BM25 postings + local hash embedding (65,536 × 256 fp16 table)
98
+ ─ typed edges: LINK (explicit) · TAG (IDF-weighted) · KNN (semantic)
99
+
100
+ query ─ ① seeds: BM25 top-k ∪ cosine top-k, RRF-fused
101
+ ─ ② expansion: one Personalized PageRank per edge type
102
+ (LINK / TAG / KNN / CO-ACCESS) → 4 graph features
103
+ ─ ③ ranking: 14 features → Linear(14→16) → GELU → Linear(16→1)
104
+
105
+ learn ─ Hebbian: memories retrieved together AND both used strengthen a
106
+ CO-ACCESS edge (lazy decay, no maintenance jobs)
107
+ ─ ranker: pairwise logistic SGD on used-vs-ignored, with a safety
108
+ blend gate — the learned score only participates once it BEATS the
109
+ built-in heuristic on live online AUC (performance floor guarantee)
110
+ ─ distill: fit the embedding table to caller-provided teacher vectors
111
+ (closed feedback loop with a geometry-improvement gate)
112
+ ```
113
+
114
+ Design notes:
115
+
116
+ - **The heuristic floor.** Scoring starts as a fixed hand-tuned linear
117
+ combination. The MLP's influence (λ) stays 0 until it has ≥100 labelled
118
+ events *and* a better pairwise win-rate — learning can help, never regress.
119
+ - **Per-type PPR instead of a GNN.** Each edge type gets its own PageRank
120
+ feature; the ranker learns the type weights implicitly. No differentiable
121
+ graph machinery, fully interpretable, milliseconds on thousands of nodes.
122
+ - **Derived data only.** The SQLite file is an index, not a store of record —
123
+ delete it any time and re-`index()` from your source of truth.
124
+
125
+ ## geny-executor integration
126
+
127
+ `geny_memory_adaptor.executor_adapter` ships duck-typed handles matching
128
+ geny-executor's memory Protocols (no import of geny-executor):
129
+
130
+ ```python
131
+ from geny_memory_adaptor import SynapseMemory, SynapseVectorHandle
132
+ handle = SynapseVectorHandle(SynapseMemory.open("vault/synapse.db"))
133
+ # → FileMemoryProvider(vector_store=handle) # drop-in local vector layer
134
+ ```
135
+
136
+ ## Benchmarks (single CPU core, this repo's `tests/bench.py`)
137
+
138
+ ```
139
+ index : 500 docs 0.32 ms/doc · 2,000 docs 0.71 ms/doc
140
+ search: 500 docs 3.1 ms · 2,000 docs 8.7 ms
141
+ learn : ambiguous-query demo — mean target rank 7.0 → 2.8 after 80 feedbacks
142
+ distill: 120 pairs, geometry corr 0.975 → 0.983, gate-approved swap, 8.5 s
143
+ ```
144
+
145
+ ## License
146
+
147
+ Apache-2.0