lethe-delete 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.
Files changed (48) hide show
  1. lethe_delete-0.1.0/LICENSE +201 -0
  2. lethe_delete-0.1.0/PKG-INFO +209 -0
  3. lethe_delete-0.1.0/README.md +180 -0
  4. lethe_delete-0.1.0/lethe/__init__.py +5 -0
  5. lethe_delete-0.1.0/lethe/audit.py +83 -0
  6. lethe_delete-0.1.0/lethe/cert_schema.py +82 -0
  7. lethe_delete-0.1.0/lethe/certificate.py +126 -0
  8. lethe_delete-0.1.0/lethe/cli.py +119 -0
  9. lethe_delete-0.1.0/lethe/connectors/__init__.py +0 -0
  10. lethe_delete-0.1.0/lethe/connectors/base.py +14 -0
  11. lethe_delete-0.1.0/lethe/connectors/pgvector.py +33 -0
  12. lethe_delete-0.1.0/lethe/connectors/pinecone.py +59 -0
  13. lethe_delete-0.1.0/lethe/core.py +145 -0
  14. lethe_delete-0.1.0/lethe/guard.py +112 -0
  15. lethe_delete-0.1.0/lethe/hashing.py +11 -0
  16. lethe_delete-0.1.0/lethe/integrations/__init__.py +0 -0
  17. lethe_delete-0.1.0/lethe/integrations/langchain.py +226 -0
  18. lethe_delete-0.1.0/lethe/ledger.py +53 -0
  19. lethe_delete-0.1.0/lethe/mcp.py +356 -0
  20. lethe_delete-0.1.0/lethe/models.py +34 -0
  21. lethe_delete-0.1.0/lethe/schemas/certificate-v1.json +55 -0
  22. lethe_delete-0.1.0/lethe/signing.py +45 -0
  23. lethe_delete-0.1.0/lethe/version.py +1 -0
  24. lethe_delete-0.1.0/lethe_delete.egg-info/PKG-INFO +209 -0
  25. lethe_delete-0.1.0/lethe_delete.egg-info/SOURCES.txt +46 -0
  26. lethe_delete-0.1.0/lethe_delete.egg-info/dependency_links.txt +1 -0
  27. lethe_delete-0.1.0/lethe_delete.egg-info/entry_points.txt +3 -0
  28. lethe_delete-0.1.0/lethe_delete.egg-info/requires.txt +12 -0
  29. lethe_delete-0.1.0/lethe_delete.egg-info/top_level.txt +1 -0
  30. lethe_delete-0.1.0/pyproject.toml +42 -0
  31. lethe_delete-0.1.0/setup.cfg +4 -0
  32. lethe_delete-0.1.0/tests/test_audit.py +67 -0
  33. lethe_delete-0.1.0/tests/test_cert_schema.py +126 -0
  34. lethe_delete-0.1.0/tests/test_certificate.py +128 -0
  35. lethe_delete-0.1.0/tests/test_cli.py +127 -0
  36. lethe_delete-0.1.0/tests/test_core.py +123 -0
  37. lethe_delete-0.1.0/tests/test_forget_loop_audit.py +180 -0
  38. lethe_delete-0.1.0/tests/test_guard.py +103 -0
  39. lethe_delete-0.1.0/tests/test_hashing.py +20 -0
  40. lethe_delete-0.1.0/tests/test_langchain_integration.py +433 -0
  41. lethe_delete-0.1.0/tests/test_ledger.py +32 -0
  42. lethe_delete-0.1.0/tests/test_mcp.py +433 -0
  43. lethe_delete-0.1.0/tests/test_mcp_e2e.py +90 -0
  44. lethe_delete-0.1.0/tests/test_models.py +27 -0
  45. lethe_delete-0.1.0/tests/test_pgvector_connector.py +53 -0
  46. lethe_delete-0.1.0/tests/test_pinecone_connector.py +96 -0
  47. lethe_delete-0.1.0/tests/test_signing.py +22 -0
  48. lethe_delete-0.1.0/tests/test_smoke.py +5 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 BlueTier Operations
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: lethe-delete
3
+ Version: 0.1.0
4
+ Summary: The forget button for AI — provable data-subject deletion for AI memory, with signed deletion certificates.
5
+ Project-URL: Repository, https://github.com/bluetieroperations-create/lethe
6
+ Project-URL: Documentation, https://github.com/bluetieroperations-create/lethe/blob/main/docs/m2m.md
7
+ Keywords: gdpr,ccpa,dsar,right-to-be-forgotten,deletion,vector-database,rag,ai-memory,mcp,compliance
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Topic :: Security
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: psycopg[binary]>=3.1
19
+ Requires-Dist: cryptography>=42
20
+ Requires-Dist: click>=8.1
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8; extra == "dev"
23
+ Requires-Dist: jsonschema>=4.21; extra == "dev"
24
+ Requires-Dist: mcp>=1.9; extra == "dev"
25
+ Provides-Extra: mcp
26
+ Requires-Dist: mcp>=1.9; extra == "mcp"
27
+ Requires-Dist: jsonschema>=4.21; extra == "mcp"
28
+ Dynamic: license-file
29
+
30
+ # Lethe — the forget button for AI
31
+
32
+ **Everyone built AI memory. Nobody built the provable delete.** Lethe deletes a
33
+ person's data from your AI memory (vector store, RAG index, caches, logs) on a
34
+ GDPR/CCPA request — and hands you a **signed certificate** proving it happened.
35
+
36
+ Self-hosted: Lethe runs inside *your* infrastructure. The tool that erases your
37
+ data never becomes a new place your data goes.
38
+
39
+ > **Status:** v0.1, early but real. Connectors: **pgvector** + **Pinecone**.
40
+ > The full delete loop is tested end-to-end against real Postgres (pgvector);
41
+ > the Pinecone connector is unit-tested against a mock `Index`, not live
42
+ > Pinecone. Hardened through four rounds of adversarial self-review (internal,
43
+ > not third-party). Not yet on PyPI.
44
+
45
+ ---
46
+
47
+ ## Why
48
+
49
+ GDPR **Article 17** (right to erasure) covers personal data in agent memory —
50
+ conversation history, retrieved chunks, **and embeddings**. Fines reach 4% of
51
+ global revenue, and the EU's data-protection authorities are actively auditing
52
+ deletion (the EDPB's 2026 sweep checked 764 organizations and found "lack of
53
+ automated deletion mechanisms" almost everywhere). Meanwhile *no vector
54
+ database offers provable deletion* — teams hand-roll it.
55
+
56
+ If you sell AI to enterprises, you've probably hit the sharper version: a
57
+ customer's security review asks *"prove you can delete a user's data from your
58
+ AI,"* and you can't. Lethe is the answer you hand them.
59
+
60
+ ## How it works
61
+
62
+ ```
63
+ tag(subject → record) → forget(subject) → delete from your stores
64
+ → verify the records are gone
65
+ → signed deletion certificate
66
+ → tamper-evident audit entry
67
+ ```
68
+
69
+ You never have to remember to call `tag` everywhere: wrap your vector store
70
+ once and writes tag themselves.
71
+
72
+ ## Quickstart (drop-in)
73
+
74
+ ```bash
75
+ pip install -e . # from source for now (PyPI soon)
76
+ lethe keygen --out lethe_key.bin # one-time: your signing key (prints the public key)
77
+ export DATABASE_URL=... # your own Postgres
78
+ export LETHE_SALT=... # a secret; pseudonymizes subjects in the ledger
79
+ lethe init-db # creates Lethe's ledger + audit tables
80
+ ```
81
+
82
+ Wire Lethe to your store, then **wrap your vector store** so every write is
83
+ tagged for deletion:
84
+
85
+ ```python
86
+ import os, psycopg
87
+ from lethe import Lethe
88
+ from lethe.ledger import Ledger
89
+ from lethe.audit import AuditLog
90
+ from lethe.signing import Signer
91
+ from lethe.connectors.pgvector import PgVectorConnector
92
+ from lethe.integrations.langchain import LetheVectorStore
93
+
94
+ conn = psycopg.connect(os.environ["DATABASE_URL"])
95
+ lethe = Lethe(
96
+ ledger=Ledger(conn),
97
+ audit=AuditLog(conn),
98
+ signer=Signer.from_private_bytes(open("lethe_key.bin", "rb").read()),
99
+ connectors={"pgvector": PgVectorConnector(conn)},
100
+ salt=os.environ["LETHE_SALT"],
101
+ )
102
+
103
+ # Wrap once. Declare which metadata field names the data subject.
104
+ store = LetheVectorStore(
105
+ my_vectorstore, lethe, # any LangChain-style store
106
+ store="pgvector", namespace="docs",
107
+ subject_key="user_id",
108
+ id_key="doc_id", # recommended: bind ids from metadata
109
+ )
110
+
111
+ # Use it like a normal vector store — tagging happens automatically.
112
+ store.add_documents([Document(page_content="...",
113
+ metadata={"user_id": "alice@example.com",
114
+ "doc_id": "doc-123"})])
115
+ ```
116
+
117
+ When a deletion request comes in:
118
+
119
+ ```python
120
+ cert = lethe.forget("alice@example.com") # deletes everywhere + returns the certificate
121
+ ```
122
+
123
+ Verify a certificate (pin the operator's *published* public key — a certificate
124
+ that vouches for itself proves nothing):
125
+
126
+ ```python
127
+ from lethe.certificate import verify_certificate
128
+ assert verify_certificate(cert, trusted_public_key=PUBLISHED_PUBKEY)
129
+ ```
130
+
131
+ ## The certificate
132
+
133
+ Ed25519-signed, tamper-evident, independently verifiable. It states exactly what
134
+ happened and **scopes its claim honestly** — *"deleted across these retrieval
135
+ layers and verified absent,"* never "perfectly erased everywhere" (backups and
136
+ model weights are out of scope by definition). `verified_absent` means Lethe
137
+ re-queried the configured endpoint immediately after deleting and saw the
138
+ records gone *at issue time* — it is not a guarantee against read replicas,
139
+ query caches, or asynchronous propagation (notably Pinecone, whose deletes are
140
+ eventually consistent).
141
+
142
+ ```json
143
+ {
144
+ "all_verified": true,
145
+ "records_deleted": 2,
146
+ "layers": [{"store": "pgvector", "namespace": "docs",
147
+ "deleted_count": 2, "verified_absent": true, "erased": true}],
148
+ "claim": "Deleted across the listed retrieval layers and verified absent. ...",
149
+ "signature": "…", "public_key": "…"
150
+ }
151
+ ```
152
+
153
+ ## CLI
154
+
155
+ | Command | Purpose |
156
+ |---|---|
157
+ | `lethe keygen --out KEY` | Create the Ed25519 signing key (prints the public key to publish) |
158
+ | `lethe init-db` | Create Lethe's ledger + audit tables in your Postgres |
159
+ | `lethe forget SUBJECT` | Delete a subject everywhere; prints the signed certificate |
160
+ | `lethe verify CERT --public-key PUB` | Verify a certificate against the operator's published key |
161
+ | `lethe audit-head` | Print the audit-log tip hash (record it out-of-band) |
162
+ | `lethe verify-audit --expected-head H` | Detect tampering/truncation of the audit log |
163
+
164
+ ## For AI agents (MCP)
165
+
166
+ Lethe ships an MCP server so autonomous agents can execute provable deletion
167
+ and verify certificates machine-to-machine:
168
+
169
+ pip install "lethe-delete[mcp]"
170
+ lethe-mcp
171
+
172
+ Destructive deletes are two-step (preview → confirm token → forget), and any
173
+ agent can verify a certificate with zero infrastructure (you still need the
174
+ operator's published public key to pin against). Full guide:
175
+ [docs/m2m.md](docs/m2m.md).
176
+
177
+ ## Security model & honest limits
178
+
179
+ - **Self-hosted.** The SDK and the provenance ledger run in your own Postgres.
180
+ Lethe-the-project never sees your data. The salt stays in your app.
181
+ - **No raw PII in the ledger.** Subjects are stored as HMAC-SHA256 hashes.
182
+ - **Verify with a pinned key.** An unpinned certificate check only proves
183
+ internal consistency; always pin your published public key.
184
+ - **`verified_absent` is a point-in-time re-query, not a replication proof.**
185
+ For eventually-consistent stores (Pinecone) a delete may not have propagated
186
+ to every replica at issue time. pgvector verifies read-your-writes on one
187
+ connection; a read-replica DSN would reintroduce the gap.
188
+ - **Audit truncation needs an out-of-band head.** Mid-chain edits are caught
189
+ automatically; detecting deletion of the *most recent* entries requires
190
+ recording `lethe audit-head` out-of-band and checking `verify-audit
191
+ --expected-head`.
192
+ - **Coverage = what flows through Lethe.** Writes that bypass the wrapper/`tag`
193
+ aren't tracked. Wrap your store, or tag explicitly.
194
+ - **Pre-existing data** (written before you adopted Lethe) needs retroactive
195
+ discovery — on the roadmap, not in v0.1.
196
+ - **Not erasure from backups or model weights.** Out of scope by design; the
197
+ certificate says so.
198
+
199
+ ## Connectors
200
+
201
+ - **pgvector** (and any Postgres table) — `PgVectorConnector`
202
+ - **Pinecone** — `PineconeConnector` (pass your `Index`). Note: Pinecone
203
+ deletes are eventually consistent, so `verified_absent` is asserted at issue
204
+ time against the queried endpoint, not proven across replicas.
205
+ - Roadmap: Weaviate, Qdrant, Redis, conversation logs.
206
+
207
+ ## License
208
+
209
+ [Apache-2.0](LICENSE) — permissive, with an explicit patent grant.
@@ -0,0 +1,180 @@
1
+ # Lethe — the forget button for AI
2
+
3
+ **Everyone built AI memory. Nobody built the provable delete.** Lethe deletes a
4
+ person's data from your AI memory (vector store, RAG index, caches, logs) on a
5
+ GDPR/CCPA request — and hands you a **signed certificate** proving it happened.
6
+
7
+ Self-hosted: Lethe runs inside *your* infrastructure. The tool that erases your
8
+ data never becomes a new place your data goes.
9
+
10
+ > **Status:** v0.1, early but real. Connectors: **pgvector** + **Pinecone**.
11
+ > The full delete loop is tested end-to-end against real Postgres (pgvector);
12
+ > the Pinecone connector is unit-tested against a mock `Index`, not live
13
+ > Pinecone. Hardened through four rounds of adversarial self-review (internal,
14
+ > not third-party). Not yet on PyPI.
15
+
16
+ ---
17
+
18
+ ## Why
19
+
20
+ GDPR **Article 17** (right to erasure) covers personal data in agent memory —
21
+ conversation history, retrieved chunks, **and embeddings**. Fines reach 4% of
22
+ global revenue, and the EU's data-protection authorities are actively auditing
23
+ deletion (the EDPB's 2026 sweep checked 764 organizations and found "lack of
24
+ automated deletion mechanisms" almost everywhere). Meanwhile *no vector
25
+ database offers provable deletion* — teams hand-roll it.
26
+
27
+ If you sell AI to enterprises, you've probably hit the sharper version: a
28
+ customer's security review asks *"prove you can delete a user's data from your
29
+ AI,"* and you can't. Lethe is the answer you hand them.
30
+
31
+ ## How it works
32
+
33
+ ```
34
+ tag(subject → record) → forget(subject) → delete from your stores
35
+ → verify the records are gone
36
+ → signed deletion certificate
37
+ → tamper-evident audit entry
38
+ ```
39
+
40
+ You never have to remember to call `tag` everywhere: wrap your vector store
41
+ once and writes tag themselves.
42
+
43
+ ## Quickstart (drop-in)
44
+
45
+ ```bash
46
+ pip install -e . # from source for now (PyPI soon)
47
+ lethe keygen --out lethe_key.bin # one-time: your signing key (prints the public key)
48
+ export DATABASE_URL=... # your own Postgres
49
+ export LETHE_SALT=... # a secret; pseudonymizes subjects in the ledger
50
+ lethe init-db # creates Lethe's ledger + audit tables
51
+ ```
52
+
53
+ Wire Lethe to your store, then **wrap your vector store** so every write is
54
+ tagged for deletion:
55
+
56
+ ```python
57
+ import os, psycopg
58
+ from lethe import Lethe
59
+ from lethe.ledger import Ledger
60
+ from lethe.audit import AuditLog
61
+ from lethe.signing import Signer
62
+ from lethe.connectors.pgvector import PgVectorConnector
63
+ from lethe.integrations.langchain import LetheVectorStore
64
+
65
+ conn = psycopg.connect(os.environ["DATABASE_URL"])
66
+ lethe = Lethe(
67
+ ledger=Ledger(conn),
68
+ audit=AuditLog(conn),
69
+ signer=Signer.from_private_bytes(open("lethe_key.bin", "rb").read()),
70
+ connectors={"pgvector": PgVectorConnector(conn)},
71
+ salt=os.environ["LETHE_SALT"],
72
+ )
73
+
74
+ # Wrap once. Declare which metadata field names the data subject.
75
+ store = LetheVectorStore(
76
+ my_vectorstore, lethe, # any LangChain-style store
77
+ store="pgvector", namespace="docs",
78
+ subject_key="user_id",
79
+ id_key="doc_id", # recommended: bind ids from metadata
80
+ )
81
+
82
+ # Use it like a normal vector store — tagging happens automatically.
83
+ store.add_documents([Document(page_content="...",
84
+ metadata={"user_id": "alice@example.com",
85
+ "doc_id": "doc-123"})])
86
+ ```
87
+
88
+ When a deletion request comes in:
89
+
90
+ ```python
91
+ cert = lethe.forget("alice@example.com") # deletes everywhere + returns the certificate
92
+ ```
93
+
94
+ Verify a certificate (pin the operator's *published* public key — a certificate
95
+ that vouches for itself proves nothing):
96
+
97
+ ```python
98
+ from lethe.certificate import verify_certificate
99
+ assert verify_certificate(cert, trusted_public_key=PUBLISHED_PUBKEY)
100
+ ```
101
+
102
+ ## The certificate
103
+
104
+ Ed25519-signed, tamper-evident, independently verifiable. It states exactly what
105
+ happened and **scopes its claim honestly** — *"deleted across these retrieval
106
+ layers and verified absent,"* never "perfectly erased everywhere" (backups and
107
+ model weights are out of scope by definition). `verified_absent` means Lethe
108
+ re-queried the configured endpoint immediately after deleting and saw the
109
+ records gone *at issue time* — it is not a guarantee against read replicas,
110
+ query caches, or asynchronous propagation (notably Pinecone, whose deletes are
111
+ eventually consistent).
112
+
113
+ ```json
114
+ {
115
+ "all_verified": true,
116
+ "records_deleted": 2,
117
+ "layers": [{"store": "pgvector", "namespace": "docs",
118
+ "deleted_count": 2, "verified_absent": true, "erased": true}],
119
+ "claim": "Deleted across the listed retrieval layers and verified absent. ...",
120
+ "signature": "…", "public_key": "…"
121
+ }
122
+ ```
123
+
124
+ ## CLI
125
+
126
+ | Command | Purpose |
127
+ |---|---|
128
+ | `lethe keygen --out KEY` | Create the Ed25519 signing key (prints the public key to publish) |
129
+ | `lethe init-db` | Create Lethe's ledger + audit tables in your Postgres |
130
+ | `lethe forget SUBJECT` | Delete a subject everywhere; prints the signed certificate |
131
+ | `lethe verify CERT --public-key PUB` | Verify a certificate against the operator's published key |
132
+ | `lethe audit-head` | Print the audit-log tip hash (record it out-of-band) |
133
+ | `lethe verify-audit --expected-head H` | Detect tampering/truncation of the audit log |
134
+
135
+ ## For AI agents (MCP)
136
+
137
+ Lethe ships an MCP server so autonomous agents can execute provable deletion
138
+ and verify certificates machine-to-machine:
139
+
140
+ pip install "lethe-delete[mcp]"
141
+ lethe-mcp
142
+
143
+ Destructive deletes are two-step (preview → confirm token → forget), and any
144
+ agent can verify a certificate with zero infrastructure (you still need the
145
+ operator's published public key to pin against). Full guide:
146
+ [docs/m2m.md](docs/m2m.md).
147
+
148
+ ## Security model & honest limits
149
+
150
+ - **Self-hosted.** The SDK and the provenance ledger run in your own Postgres.
151
+ Lethe-the-project never sees your data. The salt stays in your app.
152
+ - **No raw PII in the ledger.** Subjects are stored as HMAC-SHA256 hashes.
153
+ - **Verify with a pinned key.** An unpinned certificate check only proves
154
+ internal consistency; always pin your published public key.
155
+ - **`verified_absent` is a point-in-time re-query, not a replication proof.**
156
+ For eventually-consistent stores (Pinecone) a delete may not have propagated
157
+ to every replica at issue time. pgvector verifies read-your-writes on one
158
+ connection; a read-replica DSN would reintroduce the gap.
159
+ - **Audit truncation needs an out-of-band head.** Mid-chain edits are caught
160
+ automatically; detecting deletion of the *most recent* entries requires
161
+ recording `lethe audit-head` out-of-band and checking `verify-audit
162
+ --expected-head`.
163
+ - **Coverage = what flows through Lethe.** Writes that bypass the wrapper/`tag`
164
+ aren't tracked. Wrap your store, or tag explicitly.
165
+ - **Pre-existing data** (written before you adopted Lethe) needs retroactive
166
+ discovery — on the roadmap, not in v0.1.
167
+ - **Not erasure from backups or model weights.** Out of scope by design; the
168
+ certificate says so.
169
+
170
+ ## Connectors
171
+
172
+ - **pgvector** (and any Postgres table) — `PgVectorConnector`
173
+ - **Pinecone** — `PineconeConnector` (pass your `Index`). Note: Pinecone
174
+ deletes are eventually consistent, so `verified_absent` is asserted at issue
175
+ time against the queried endpoint, not proven across replicas.
176
+ - Roadmap: Weaviate, Qdrant, Redis, conversation logs.
177
+
178
+ ## License
179
+
180
+ [Apache-2.0](LICENSE) — permissive, with an explicit patent grant.
@@ -0,0 +1,5 @@
1
+ from .core import Lethe
2
+ from .models import Certificate, LayerResult, TagRecord
3
+ from .version import __version__
4
+
5
+ __all__ = ["__version__", "Lethe", "Certificate", "LayerResult", "TagRecord"]
@@ -0,0 +1,83 @@
1
+ import hashlib
2
+ import hmac
3
+ import json
4
+
5
+ import psycopg
6
+
7
+ GENESIS = "0" * 64
8
+
9
+ AUDIT_SCHEMA = """
10
+ CREATE TABLE IF NOT EXISTS lethe_audit (
11
+ seq BIGSERIAL PRIMARY KEY,
12
+ entry JSONB NOT NULL,
13
+ prev_hash TEXT NOT NULL,
14
+ entry_hash TEXT NOT NULL,
15
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
16
+ );
17
+ """
18
+
19
+
20
+ def _entry_hash(prev_hash: str, entry: dict) -> str:
21
+ data = prev_hash + json.dumps(entry, sort_keys=True, separators=(",", ":"))
22
+ return hashlib.sha256(data.encode()).hexdigest()
23
+
24
+
25
+ class AuditLog:
26
+ def __init__(self, conn: psycopg.Connection):
27
+ self.conn = conn
28
+
29
+ def init_schema(self) -> None:
30
+ with self.conn.cursor() as cur:
31
+ cur.execute(AUDIT_SCHEMA)
32
+ self.conn.commit()
33
+
34
+ def _last_hash(self) -> str:
35
+ with self.conn.cursor() as cur:
36
+ cur.execute("SELECT entry_hash FROM lethe_audit ORDER BY seq DESC LIMIT 1")
37
+ row = cur.fetchone()
38
+ return row[0] if row else GENESIS
39
+
40
+ def append(self, entry: dict) -> str:
41
+ prev = self._last_hash()
42
+ h = _entry_hash(prev, entry)
43
+ with self.conn.cursor() as cur:
44
+ cur.execute(
45
+ "INSERT INTO lethe_audit (entry, prev_hash, entry_hash) VALUES (%s, %s, %s)",
46
+ (json.dumps(entry), prev, h),
47
+ )
48
+ self.conn.commit()
49
+ return h
50
+
51
+ def head(self) -> str:
52
+ """Current tip hash (GENESIS if the log is empty). Record this
53
+ out-of-band; later pass it to verify_chain(expected_head=...) to detect
54
+ tip-truncation (deletion of the most recent entries)."""
55
+ return self._last_hash()
56
+
57
+ def verify_chain(self, expected_head: str | None = None) -> bool:
58
+ """Verify the hash chain links from genesis to the current tip.
59
+
60
+ SECURITY: an internal walk proves no entry was *altered* or removed from
61
+ the *middle* (that breaks a prev_hash link), but it CANNOT detect tip
62
+ truncation — deleting the most recent entries leaves a self-consistent,
63
+ merely shorter chain. To catch an attacker lopping off the tail (erasing
64
+ evidence of recent erasures), the operator must record the head hash
65
+ out-of-band and pass it as ``expected_head`` — the same pin-it-externally
66
+ discipline the certificate uses for the trusted public key. With no
67
+ entries the head is ``GENESIS``.
68
+ """
69
+ with self.conn.cursor() as cur:
70
+ cur.execute(
71
+ "SELECT entry, prev_hash, entry_hash FROM lethe_audit ORDER BY seq ASC"
72
+ )
73
+ rows = cur.fetchall()
74
+ prev = GENESIS
75
+ for entry, prev_hash, entry_hash in rows:
76
+ if prev_hash != prev:
77
+ return False
78
+ if _entry_hash(prev_hash, entry) != entry_hash:
79
+ return False
80
+ prev = entry_hash
81
+ if expected_head is not None and not hmac.compare_digest(prev, expected_head):
82
+ return False
83
+ return True