vismriti 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.
vismriti-0.1.0/LICENSE ADDED
@@ -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,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: vismriti
3
+ Version: 0.1.0
4
+ Summary: DPDP-ready consent, purpose limitation and right-to-erasure for RAG and AI agents
5
+ Author: Malaya Kumar Swain
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Malaya-kumar-swain/vismriti
8
+ Project-URL: Source, https://github.com/Malaya-kumar-swain/vismriti
9
+ Project-URL: Issues, https://github.com/Malaya-kumar-swain/vismriti/issues
10
+ Keywords: dpdp,privacy,consent,rag,llm,ai-agents,mcp,right-to-erasure,india
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Security
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: mcp
18
+ Requires-Dist: mcp>=1.2; extra == "mcp"
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=8; extra == "dev"
21
+ Requires-Dist: mcp>=1.2; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # Vismriti
25
+
26
+ **Consent, purpose limitation and right-to-erasure for RAG and AI agents, built for India's DPDP Act.**
27
+
28
+ *Vismriti (विस्मृति) is Sanskrit for "forgetting". Under the DPDP Act, your AI has to learn how.*
29
+
30
+ [![ci](https://github.com/Malaya-kumar-swain/vismriti/actions/workflows/ci.yml/badge.svg)](https://github.com/Malaya-kumar-swain/vismriti/actions)
31
+ ![python](https://img.shields.io/badge/python-3.10%2B-blue) ![license](https://img.shields.io/badge/license-Apache--2.0-green) ![deps](https://img.shields.io/badge/core%20dependencies-0-brightgreen)
32
+
33
+ ---
34
+
35
+ ## The problem
36
+
37
+ Indian companies are putting customer data into GenAI systems: support copilots, KYC assistants, sales agents. The Digital Personal Data Protection Act 2023 and the DPDP Rules 2025 now ask three questions those systems were never designed to answer:
38
+
39
+ 1. **Was this person's data allowed to be used for *this* purpose?** RAG retrieves whatever is semantically closest, not what the customer consented to.
40
+ 2. **When a customer withdraws consent or asks for erasure, is their data gone *everywhere*?** In an AI stack it sits in the vector index, the response cache, the agent's memory and the prompt logs.
41
+ 3. **Can you prove it?** To the customer, your DPO and the Data Protection Board.
42
+
43
+ Masking Aadhaar and PAN numbers is necessary but not sufficient, and several good libraries already do it. Vismriti handles the part after masking: **consent-aware retrieval, erasure that propagates, and evidence you can hand to an auditor.**
44
+
45
+ ## What it does
46
+
47
+ | | |
48
+ |---|---|
49
+ | 🧾 **Consent ledger** | Who agreed to which purpose, under which notice version, and when they withdrew. Hash-chained and tamper-evident. Retention periods lapse consent automatically. |
50
+ | 🎯 **Purpose-bound retrieval** | A chunk reaches the model only if it was collected for the request's purpose **and every person in it** has active consent. Joint accounts and group chats included. |
51
+ | 🧹 **Erasure that propagates** | One call withdraws consent, erases the person from the vector index, response cache, agent memory and logs, re-checks that nothing remains, and returns a **signed deletion certificate**. |
52
+ | 🔍 **Right to access** | `access_summary()` lists purposes, consent history and items held per store, without exposing raw data. |
53
+ | 📋 **Evidence pack** | Every allow, deny, withdrawal and erasure goes into a hash-chained log with a Markdown report mapped to DPDP sections. The log never stores raw personal data. |
54
+ | 🇮🇳 **Indian PII masking** | Aadhaar (Verhoeff-checksum validated), PAN, GSTIN, IFSC, UPI, Indian mobile and email, including digits written in Devanagari, Odia, Bengali, Tamil, Telugu, Kannada, Gujarati and Gurmukhi. Bring your own detector through a one-method interface. |
55
+ | 🤖 **MCP server** | Agents can call `check_purpose`, `record_consent`, `retrieve`, `access_summary` and `erase_principal` before they touch personal data. |
56
+
57
+ Zero runtime dependencies in the core. The MCP server is an optional extra.
58
+
59
+ ## How it fits
60
+
61
+ ```mermaid
62
+ flowchart LR
63
+ U[User / Agent request<br/>+ purpose] --> R[Purpose-bound retriever]
64
+ R -->|search| V[(Vector index)]
65
+ R -->|check each chunk| L[Consent ledger]
66
+ R -->|allowed chunks| M[PII masking] --> LLM[LLM]
67
+ R -.->|allow / deny| E[(Evidence log)]
68
+ X[Erase request] --> C[Erasure coordinator]
69
+ C --> V & K[(Response cache)] & A[(Agent memory)] & G[(App logs)]
70
+ C --> L
71
+ C --> CERT[Signed deletion certificate]
72
+ C -.-> E
73
+ ```
74
+
75
+ ## Quick start
76
+
77
+ Install the library with `pip install vismriti` (or `pip install "vismriti[mcp]"` for the MCP server). To run the demo and tests, use the source:
78
+
79
+ ```bash
80
+ git clone https://github.com/Malaya-kumar-swain/vismriti && cd vismriti
81
+ pip install -e ".[dev]"
82
+ python examples/bank_assistant_demo.py
83
+ pytest -q
84
+ ```
85
+
86
+ ```python
87
+ from vismriti import Purpose, Vismriti
88
+
89
+ v = Vismriti(
90
+ purposes=[Purpose("kyc", "Verify identity", retention_days=3650),
91
+ Purpose("support", "Answer service requests", retention_days=365)],
92
+ signing_key=b"load-this-from-your-secret-manager",
93
+ )
94
+
95
+ v.grant("cust-asha", "support", notice_version="2026-10")
96
+ v.ingest("ticket-1", "Asha asked to raise her UPI limit, UPI id asha.rao@okhdfcbank.",
97
+ principals=["cust-asha"], purposes=["support"])
98
+
99
+ v.retrieve("UPI limit", purpose="support") # → ticket-1, with the UPI id masked
100
+ v.retrieve("UPI limit", purpose="marketing") # → ValueError: unknown purpose (not declared)
101
+
102
+ cert = v.erase("cust-asha") # vector index, cache, memory, logs, consents
103
+ assert cert.complete and v.verify_certificate(cert)
104
+ print(v.report("cust-asha")) # evidence pack for the DPO
105
+ ```
106
+
107
+ ### Demo output (abridged)
108
+
109
+ ```
110
+ ── 1. Support agent asks about UPI limits (purpose = support)
111
+ ✔ ticket-asha: Asha Rao asked to raise her UPI limit; UPI id [UPI]. Prefers Hindi.
112
+ ✘ ticket-ravi was withheld: Ravi never consented to 'support'.
113
+ ── 2. Marketing team tries the same data (purpose = marketing)
114
+ results: [] ← nothing leaks
115
+ ── 4. Asha withdraws consent and asks for erasure (DPDP s.6(4), s.12)
116
+ vector_index found 2 erased 2 remaining 0
117
+ response_cache found 1 erased 1 remaining 0
118
+ agent_memory found 1 erased 1 remaining 0
119
+ app_logs found 1 erased 1 remaining 0
120
+ complete=True signature valid=True
121
+ ```
122
+
123
+ ## Use with AI agents (MCP)
124
+
125
+ ```bash
126
+ pip install "vismriti[mcp]"
127
+ VISMRITI_KEY=<32+ random characters> VISMRITI_PURPOSES=kyc,support python -m vismriti.mcp_server
128
+ ```
129
+
130
+ Add it to any MCP client (Claude Desktop, IDE agents, your own) as a stdio server. The agent then gets tools to check purpose, record or withdraw consent, run purpose-bound retrieval, mask text, produce an access summary and erase a person.
131
+
132
+ ## Plug in your own stack
133
+
134
+ Anything that holds personal data can join erasure by implementing two methods:
135
+
136
+ ```python
137
+ class MyPgVectorStore:
138
+ name = "pgvector"
139
+ def find(self, principal_id: str) -> list[str]: ...
140
+ def erase(self, principal_id: str) -> int: ...
141
+
142
+ v = Vismriti(purposes, key, extra_stores=[MyPgVectorStore(), MyRedisCache(), MyBackupIndex()])
143
+ ```
144
+
145
+ Detectors work the same way: anything with `detect(text) -> list[Finding]` (Presidio, bharat-pii, an NER model) can replace the built-in one.
146
+
147
+ ## DPDP mapping
148
+
149
+ See [docs/dpdp-mapping.md](https://github.com/Malaya-kumar-swain/vismriti/blob/main/docs/dpdp-mapping.md) for a section-by-section table of what is covered, what is partial and what is not yet. Limits are listed honestly in [docs/threat-model.md](https://github.com/Malaya-kumar-swain/vismriti/blob/main/docs/threat-model.md); for example, erasure covers stores, not data already baked into fine-tuned model weights.
150
+
151
+ ## Roadmap
152
+
153
+ - [ ] Adapters: Chroma, pgvector, Qdrant, Redis, OpenSearch
154
+ - [ ] Consent-manager integration (DPDP Rules, consent artefacts)
155
+ - [ ] Ed25519 certificates and key rotation
156
+ - [ ] Breach-intimation workflow (s.8(6)) and grievance tracking (s.13)
157
+ - [ ] Right to correction (s.12) with re-embedding
158
+ - [ ] LangChain / LlamaIndex retriever wrappers
159
+ - [ ] Name and address detection for Indian languages via pluggable NER
160
+
161
+ ## Disclaimer
162
+
163
+ Vismriti is an engineering aid, not legal advice. It helps you implement and evidence controls; whether a system complies with the DPDP Act depends on far more than code. All names and numbers in this repository are synthetic.
164
+
165
+ ## Author
166
+
167
+ Built by **Malaya Kumar Swain**, AI technology leader working on agentic and voice AI, responsible AI and data platforms. · [Portfolio](https://malayakumarswain.com) · [LinkedIn](https://www.linkedin.com/in/malayakumarswain)
168
+
169
+ Licensed under [Apache 2.0](https://github.com/Malaya-kumar-swain/vismriti/blob/main/LICENSE).
@@ -0,0 +1,146 @@
1
+ # Vismriti
2
+
3
+ **Consent, purpose limitation and right-to-erasure for RAG and AI agents, built for India's DPDP Act.**
4
+
5
+ *Vismriti (विस्मृति) is Sanskrit for "forgetting". Under the DPDP Act, your AI has to learn how.*
6
+
7
+ [![ci](https://github.com/Malaya-kumar-swain/vismriti/actions/workflows/ci.yml/badge.svg)](https://github.com/Malaya-kumar-swain/vismriti/actions)
8
+ ![python](https://img.shields.io/badge/python-3.10%2B-blue) ![license](https://img.shields.io/badge/license-Apache--2.0-green) ![deps](https://img.shields.io/badge/core%20dependencies-0-brightgreen)
9
+
10
+ ---
11
+
12
+ ## The problem
13
+
14
+ Indian companies are putting customer data into GenAI systems: support copilots, KYC assistants, sales agents. The Digital Personal Data Protection Act 2023 and the DPDP Rules 2025 now ask three questions those systems were never designed to answer:
15
+
16
+ 1. **Was this person's data allowed to be used for *this* purpose?** RAG retrieves whatever is semantically closest, not what the customer consented to.
17
+ 2. **When a customer withdraws consent or asks for erasure, is their data gone *everywhere*?** In an AI stack it sits in the vector index, the response cache, the agent's memory and the prompt logs.
18
+ 3. **Can you prove it?** To the customer, your DPO and the Data Protection Board.
19
+
20
+ Masking Aadhaar and PAN numbers is necessary but not sufficient, and several good libraries already do it. Vismriti handles the part after masking: **consent-aware retrieval, erasure that propagates, and evidence you can hand to an auditor.**
21
+
22
+ ## What it does
23
+
24
+ | | |
25
+ |---|---|
26
+ | 🧾 **Consent ledger** | Who agreed to which purpose, under which notice version, and when they withdrew. Hash-chained and tamper-evident. Retention periods lapse consent automatically. |
27
+ | 🎯 **Purpose-bound retrieval** | A chunk reaches the model only if it was collected for the request's purpose **and every person in it** has active consent. Joint accounts and group chats included. |
28
+ | 🧹 **Erasure that propagates** | One call withdraws consent, erases the person from the vector index, response cache, agent memory and logs, re-checks that nothing remains, and returns a **signed deletion certificate**. |
29
+ | 🔍 **Right to access** | `access_summary()` lists purposes, consent history and items held per store, without exposing raw data. |
30
+ | 📋 **Evidence pack** | Every allow, deny, withdrawal and erasure goes into a hash-chained log with a Markdown report mapped to DPDP sections. The log never stores raw personal data. |
31
+ | 🇮🇳 **Indian PII masking** | Aadhaar (Verhoeff-checksum validated), PAN, GSTIN, IFSC, UPI, Indian mobile and email, including digits written in Devanagari, Odia, Bengali, Tamil, Telugu, Kannada, Gujarati and Gurmukhi. Bring your own detector through a one-method interface. |
32
+ | 🤖 **MCP server** | Agents can call `check_purpose`, `record_consent`, `retrieve`, `access_summary` and `erase_principal` before they touch personal data. |
33
+
34
+ Zero runtime dependencies in the core. The MCP server is an optional extra.
35
+
36
+ ## How it fits
37
+
38
+ ```mermaid
39
+ flowchart LR
40
+ U[User / Agent request<br/>+ purpose] --> R[Purpose-bound retriever]
41
+ R -->|search| V[(Vector index)]
42
+ R -->|check each chunk| L[Consent ledger]
43
+ R -->|allowed chunks| M[PII masking] --> LLM[LLM]
44
+ R -.->|allow / deny| E[(Evidence log)]
45
+ X[Erase request] --> C[Erasure coordinator]
46
+ C --> V & K[(Response cache)] & A[(Agent memory)] & G[(App logs)]
47
+ C --> L
48
+ C --> CERT[Signed deletion certificate]
49
+ C -.-> E
50
+ ```
51
+
52
+ ## Quick start
53
+
54
+ Install the library with `pip install vismriti` (or `pip install "vismriti[mcp]"` for the MCP server). To run the demo and tests, use the source:
55
+
56
+ ```bash
57
+ git clone https://github.com/Malaya-kumar-swain/vismriti && cd vismriti
58
+ pip install -e ".[dev]"
59
+ python examples/bank_assistant_demo.py
60
+ pytest -q
61
+ ```
62
+
63
+ ```python
64
+ from vismriti import Purpose, Vismriti
65
+
66
+ v = Vismriti(
67
+ purposes=[Purpose("kyc", "Verify identity", retention_days=3650),
68
+ Purpose("support", "Answer service requests", retention_days=365)],
69
+ signing_key=b"load-this-from-your-secret-manager",
70
+ )
71
+
72
+ v.grant("cust-asha", "support", notice_version="2026-10")
73
+ v.ingest("ticket-1", "Asha asked to raise her UPI limit, UPI id asha.rao@okhdfcbank.",
74
+ principals=["cust-asha"], purposes=["support"])
75
+
76
+ v.retrieve("UPI limit", purpose="support") # → ticket-1, with the UPI id masked
77
+ v.retrieve("UPI limit", purpose="marketing") # → ValueError: unknown purpose (not declared)
78
+
79
+ cert = v.erase("cust-asha") # vector index, cache, memory, logs, consents
80
+ assert cert.complete and v.verify_certificate(cert)
81
+ print(v.report("cust-asha")) # evidence pack for the DPO
82
+ ```
83
+
84
+ ### Demo output (abridged)
85
+
86
+ ```
87
+ ── 1. Support agent asks about UPI limits (purpose = support)
88
+ ✔ ticket-asha: Asha Rao asked to raise her UPI limit; UPI id [UPI]. Prefers Hindi.
89
+ ✘ ticket-ravi was withheld: Ravi never consented to 'support'.
90
+ ── 2. Marketing team tries the same data (purpose = marketing)
91
+ results: [] ← nothing leaks
92
+ ── 4. Asha withdraws consent and asks for erasure (DPDP s.6(4), s.12)
93
+ vector_index found 2 erased 2 remaining 0
94
+ response_cache found 1 erased 1 remaining 0
95
+ agent_memory found 1 erased 1 remaining 0
96
+ app_logs found 1 erased 1 remaining 0
97
+ complete=True signature valid=True
98
+ ```
99
+
100
+ ## Use with AI agents (MCP)
101
+
102
+ ```bash
103
+ pip install "vismriti[mcp]"
104
+ VISMRITI_KEY=<32+ random characters> VISMRITI_PURPOSES=kyc,support python -m vismriti.mcp_server
105
+ ```
106
+
107
+ Add it to any MCP client (Claude Desktop, IDE agents, your own) as a stdio server. The agent then gets tools to check purpose, record or withdraw consent, run purpose-bound retrieval, mask text, produce an access summary and erase a person.
108
+
109
+ ## Plug in your own stack
110
+
111
+ Anything that holds personal data can join erasure by implementing two methods:
112
+
113
+ ```python
114
+ class MyPgVectorStore:
115
+ name = "pgvector"
116
+ def find(self, principal_id: str) -> list[str]: ...
117
+ def erase(self, principal_id: str) -> int: ...
118
+
119
+ v = Vismriti(purposes, key, extra_stores=[MyPgVectorStore(), MyRedisCache(), MyBackupIndex()])
120
+ ```
121
+
122
+ Detectors work the same way: anything with `detect(text) -> list[Finding]` (Presidio, bharat-pii, an NER model) can replace the built-in one.
123
+
124
+ ## DPDP mapping
125
+
126
+ See [docs/dpdp-mapping.md](https://github.com/Malaya-kumar-swain/vismriti/blob/main/docs/dpdp-mapping.md) for a section-by-section table of what is covered, what is partial and what is not yet. Limits are listed honestly in [docs/threat-model.md](https://github.com/Malaya-kumar-swain/vismriti/blob/main/docs/threat-model.md); for example, erasure covers stores, not data already baked into fine-tuned model weights.
127
+
128
+ ## Roadmap
129
+
130
+ - [ ] Adapters: Chroma, pgvector, Qdrant, Redis, OpenSearch
131
+ - [ ] Consent-manager integration (DPDP Rules, consent artefacts)
132
+ - [ ] Ed25519 certificates and key rotation
133
+ - [ ] Breach-intimation workflow (s.8(6)) and grievance tracking (s.13)
134
+ - [ ] Right to correction (s.12) with re-embedding
135
+ - [ ] LangChain / LlamaIndex retriever wrappers
136
+ - [ ] Name and address detection for Indian languages via pluggable NER
137
+
138
+ ## Disclaimer
139
+
140
+ Vismriti is an engineering aid, not legal advice. It helps you implement and evidence controls; whether a system complies with the DPDP Act depends on far more than code. All names and numbers in this repository are synthetic.
141
+
142
+ ## Author
143
+
144
+ Built by **Malaya Kumar Swain**, AI technology leader working on agentic and voice AI, responsible AI and data platforms. · [Portfolio](https://malayakumarswain.com) · [LinkedIn](https://www.linkedin.com/in/malayakumarswain)
145
+
146
+ Licensed under [Apache 2.0](https://github.com/Malaya-kumar-swain/vismriti/blob/main/LICENSE).
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vismriti"
7
+ version = "0.1.0"
8
+ description = "DPDP-ready consent, purpose limitation and right-to-erasure for RAG and AI agents"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Malaya Kumar Swain" }]
13
+ requires-python = ">=3.10"
14
+ dependencies = []
15
+ keywords = ["dpdp", "privacy", "consent", "rag", "llm", "ai-agents", "mcp", "right-to-erasure", "india"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Security",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ mcp = ["mcp>=1.2"]
24
+ dev = ["pytest>=8", "mcp>=1.2"]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/Malaya-kumar-swain/vismriti"
28
+ Source = "https://github.com/Malaya-kumar-swain/vismriti"
29
+ Issues = "https://github.com/Malaya-kumar-swain/vismriti/issues"
30
+
31
+ [tool.setuptools.packages.find]
32
+ include = ["vismriti*"]
33
+
34
+ [tool.pytest.ini_options]
35
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,61 @@
1
+ import json
2
+ from datetime import datetime, timedelta, timezone
3
+
4
+ import pytest
5
+
6
+ from vismriti import ConsentLedger, EvidenceLog, Purpose
7
+ from vismriti.consent import UnknownPurpose
8
+
9
+ PURPOSES = [Purpose("kyc", "KYC"), Purpose("support", "Support", retention_days=30)]
10
+
11
+
12
+ def test_grant_and_withdraw():
13
+ led = ConsentLedger(PURPOSES)
14
+ led.grant("p1", "kyc", "v1")
15
+ led.grant("p1", "support", "v1")
16
+ assert led.active_purposes("p1") == {"kyc", "support"}
17
+ led.withdraw("p1", "support")
18
+ assert led.active_purposes("p1") == {"kyc"}
19
+ led.grant("p1", "support", "v2") # re-consent under a new notice
20
+ assert led.is_permitted("p1", "support")
21
+
22
+
23
+ def test_withdraw_all():
24
+ led = ConsentLedger(PURPOSES)
25
+ led.grant("p1", "kyc", "v1")
26
+ led.grant("p1", "support", "v1")
27
+ assert sorted(r["purpose"] for r in led.withdraw("p1")) == ["kyc", "support"]
28
+ assert led.active_purposes("p1") == set()
29
+
30
+
31
+ def test_unknown_purpose_rejected():
32
+ with pytest.raises(UnknownPurpose):
33
+ ConsentLedger(PURPOSES).grant("p1", "marketing", "v1")
34
+
35
+
36
+ def test_retention_lapses_consent():
37
+ led = ConsentLedger(PURPOSES)
38
+ led.grant("p1", "support", "v1")
39
+ later = datetime.now(timezone.utc) + timedelta(days=31)
40
+ assert "support" not in led.active_purposes("p1", at=later)
41
+
42
+
43
+ def test_ledger_tamper_detected(tmp_path):
44
+ path = tmp_path / "consent.jsonl"
45
+ led = ConsentLedger(PURPOSES, path)
46
+ led.grant("p1", "kyc", "v1")
47
+ led.withdraw("p1", "kyc")
48
+ assert ConsentLedger(PURPOSES, path).verify()
49
+ lines = path.read_text().splitlines()
50
+ rec = json.loads(lines[1])
51
+ rec["type"] = "grant" # someone tries to undo the withdrawal
52
+ lines[1] = json.dumps(rec)
53
+ path.write_text("\n".join(lines) + "\n")
54
+ assert not ConsentLedger(PURPOSES, path).verify()
55
+
56
+
57
+ def test_evidence_report_has_no_raw_text():
58
+ ev = EvidenceLog()
59
+ ev.record("retrieval_denied", principals=["p1"], purpose="marketing", chunk="c1", reason="no consent")
60
+ report = ev.report("p1")
61
+ assert "retrieval_denied" in report and "verified" in report
@@ -0,0 +1,21 @@
1
+ import asyncio
2
+
3
+ import pytest
4
+
5
+ pytest.importorskip("mcp")
6
+
7
+ from vismriti import Purpose, Vismriti # noqa: E402
8
+ from vismriti.mcp_server import build # noqa: E402
9
+
10
+
11
+ def test_tools_registered_and_callable():
12
+ v = Vismriti([Purpose("kyc", "KYC")], b"test-key-0123456789abcdef")
13
+ server = build(v)
14
+ names = {t.name for t in asyncio.run(server.list_tools())}
15
+ assert {"check_purpose", "record_consent", "withdraw_consent", "retrieve",
16
+ "mask_text", "access_summary", "erase_principal"} <= names
17
+
18
+ asyncio.run(server.call_tool("record_consent", {"principal_id": "p1", "purpose": "kyc"}))
19
+ assert v.ledger.is_permitted("p1", "kyc")
20
+ asyncio.run(server.call_tool("erase_principal", {"principal_id": "p1"}))
21
+ assert not v.ledger.is_permitted("p1", "kyc")