MemShan 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. memshan-2.0.0/MemShan.egg-info/PKG-INFO +503 -0
  2. memshan-2.0.0/MemShan.egg-info/SOURCES.txt +48 -0
  3. memshan-2.0.0/MemShan.egg-info/dependency_links.txt +1 -0
  4. memshan-2.0.0/MemShan.egg-info/entry_points.txt +2 -0
  5. memshan-2.0.0/MemShan.egg-info/requires.txt +23 -0
  6. memshan-2.0.0/MemShan.egg-info/top_level.txt +1 -0
  7. memshan-2.0.0/PKG-INFO +503 -0
  8. memshan-2.0.0/README.md +463 -0
  9. memshan-2.0.0/pyproject.toml +59 -0
  10. memshan-2.0.0/setup.cfg +4 -0
  11. memshan-2.0.0/src/__init__.py +0 -0
  12. memshan-2.0.0/src/base/__init__.py +1 -0
  13. memshan-2.0.0/src/base/embedder.py +57 -0
  14. memshan-2.0.0/src/base/loci_store.py +183 -0
  15. memshan-2.0.0/src/config.py +128 -0
  16. memshan-2.0.0/src/layers/__init__.py +1 -0
  17. memshan-2.0.0/src/layers/major_system/__init__.py +1 -0
  18. memshan-2.0.0/src/layers/major_system/phonetic_encoder.py +107 -0
  19. memshan-2.0.0/src/layers/pao/__init__.py +1 -0
  20. memshan-2.0.0/src/layers/pao/snapshot.py +243 -0
  21. memshan-2.0.0/src/layers/songlines/__init__.py +1 -0
  22. memshan-2.0.0/src/layers/songlines/knowledge_graph.py +135 -0
  23. memshan-2.0.0/src/llm/__init__.py +1 -0
  24. memshan-2.0.0/src/llm/anthropic_client.py +82 -0
  25. memshan-2.0.0/src/llm/client.py +48 -0
  26. memshan-2.0.0/src/llm/gemini_client.py +83 -0
  27. memshan-2.0.0/src/llm/ollama_client.py +98 -0
  28. memshan-2.0.0/src/llm/openai_client.py +81 -0
  29. memshan-2.0.0/src/pipeline/__init__.py +1 -0
  30. memshan-2.0.0/src/pipeline/retrieval.py +270 -0
  31. memshan-2.0.0/src/server.py +108 -0
  32. memshan-2.0.0/src/tools/__init__.py +1 -0
  33. memshan-2.0.0/src/tools/mcp_tools.py +546 -0
  34. memshan-2.0.0/tests/test_anthropic_client.py +93 -0
  35. memshan-2.0.0/tests/test_config.py +235 -0
  36. memshan-2.0.0/tests/test_embedder.py +136 -0
  37. memshan-2.0.0/tests/test_gemini_client.py +83 -0
  38. memshan-2.0.0/tests/test_gemini_live.py +84 -0
  39. memshan-2.0.0/tests/test_knowledge_graph.py +285 -0
  40. memshan-2.0.0/tests/test_llm_client.py +34 -0
  41. memshan-2.0.0/tests/test_loci_store.py +202 -0
  42. memshan-2.0.0/tests/test_main.py +55 -0
  43. memshan-2.0.0/tests/test_mcp_tools.py +594 -0
  44. memshan-2.0.0/tests/test_ollama_client.py +99 -0
  45. memshan-2.0.0/tests/test_ollama_live.py +106 -0
  46. memshan-2.0.0/tests/test_openai_client.py +97 -0
  47. memshan-2.0.0/tests/test_phonetic_encoder.py +184 -0
  48. memshan-2.0.0/tests/test_pipeline.py +569 -0
  49. memshan-2.0.0/tests/test_server.py +210 -0
  50. memshan-2.0.0/tests/test_snapshot.py +507 -0
@@ -0,0 +1,503 @@
1
+ Metadata-Version: 2.4
2
+ Name: MemShan
3
+ Version: 2.0.0
4
+ Summary: MCP memory server combining Method of Loci, Major System, Songlines, and PAO mnemonic layers
5
+ Author-email: Shan Konduru <shan.konduru@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ShanKonduru/MemSh-n
8
+ Project-URL: Repository, https://github.com/ShanKonduru/MemSh-n
9
+ Project-URL: Issues, https://github.com/ShanKonduru/MemSh-n/issues
10
+ Keywords: mcp,memory,ai,chromadb,knowledge-graph,ollama
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: mcp[cli]
20
+ Requires-Dist: chromadb
21
+ Requires-Dist: sentence-transformers
22
+ Requires-Dist: networkx
23
+ Requires-Dist: spacy
24
+ Requires-Dist: httpx
25
+ Requires-Dist: openai>=1.0.0
26
+ Requires-Dist: google-genai
27
+ Requires-Dist: anthropic
28
+ Requires-Dist: python-dotenv
29
+ Requires-Dist: pydantic>=2.0
30
+ Requires-Dist: pydantic-settings
31
+ Requires-Dist: rich
32
+ Requires-Dist: mempalace
33
+ Provides-Extra: demo
34
+ Requires-Dist: streamlit; extra == "demo"
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest; extra == "dev"
37
+ Requires-Dist: pytest-html; extra == "dev"
38
+ Requires-Dist: pytest-cov; extra == "dev"
39
+ Requires-Dist: pytest-mock; extra == "dev"
40
+
41
+ <p align="center">
42
+ <img src="logo/MemShānLogo.png" alt="MemShān Logo" width="600"/>
43
+ </p>
44
+
45
+ <h1 align="center">MemShān</h1>
46
+ <p align="center"><em>Memory &amp; Context Manager for AI</em></p>
47
+
48
+ <p align="center">
49
+ <img src="https://img.shields.io/badge/python-3.11+-blue?logo=python" alt="Python 3.11+"/>
50
+ <img src="https://img.shields.io/badge/MCP-Model%20Context%20Protocol-blueviolet" alt="MCP"/>
51
+ <img src="https://img.shields.io/badge/LLM-Ollama%20%7C%20OpenAI%20%7C%20Gemini%20%7C%20Anthropic-orange" alt="LLM Providers"/>
52
+ <img src="https://img.shields.io/badge/vector%20store-ChromaDB-green" alt="ChromaDB"/>
53
+ <img src="https://img.shields.io/badge/graph-NetworkX-red" alt="NetworkX"/>
54
+ </p>
55
+
56
+ ---
57
+
58
+ ## What is MemShān?
59
+
60
+ MemShān is a Python-based **MCP (Model Context Protocol) memory server** that gives AI assistants
61
+ a structured, multi-layered long-term memory. It combines four proven cognitive mnemonic techniques
62
+ into a single retrieval pipeline:
63
+
64
+ | Layer | Cognitive Technique | What It Does |
65
+ |---|---|---|
66
+ | **Base** | Method of Loci | ChromaDB **Wings** and **Rooms** — spatial memory palace for semantic search |
67
+ | **Layer 1** | Major System | Converts numbers in text to phonetic tags for precise numeric lookup |
68
+ | **Layer 2** | Songlines | NetworkX **Knowledge Graph** records context trails between memory chunks |
69
+ | **Layer 3** | PAO System | Compresses session logs into **Subject-Action-Object triplets** for long-term archival |
70
+
71
+ ---
72
+
73
+ ## Architecture
74
+
75
+ See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design, data-flow diagrams, and technology decisions.
76
+ See [TASK_EXECUTION_PLAN.md](TASK_EXECUTION_PLAN.md) for the phase-by-phase build plan.
77
+
78
+ ---
79
+
80
+ ## MCP Tools
81
+
82
+ | Tool | Description |
83
+ |---|---|
84
+ | `store_memory` | Store text into a Wing/Room; all layers run automatically |
85
+ | `retrieve_memory` | Unified query: semantic search + graph expansion + numeric tag matching |
86
+ | `add_context_trail` | Manually link two memory chunks in the Songlines graph |
87
+ | `get_context_trail` | Return the narrative path between two concept nodes |
88
+ | `snapshot_session` | Compress a session log into SAO triplets → long-term storage |
89
+ | `list_rooms` | List all Wings and Rooms in the memory palace |
90
+
91
+ ---
92
+
93
+ ## LLM Provider Support
94
+
95
+ MemShān defaults to **Ollama (local, fully offline)**. Switch providers via a single env var — no code changes required.
96
+
97
+ | Provider | `LLM_PROVIDER` value | Requires |
98
+ |---|---|---|
99
+ | **Ollama** *(default)* | `ollama` | Ollama running locally |
100
+ | OpenAI | `openai` | `OPENAI_API_KEY` in `.env` |
101
+ | Google Gemini | `gemini` | `GEMINI_API_KEY` in `.env` |
102
+ | Anthropic Claude | `anthropic` | `ANTHROPIC_API_KEY` in `.env` |
103
+
104
+ ---
105
+
106
+ ## Installation
107
+
108
+ ### Prerequisites
109
+
110
+ - Python 3.11+
111
+ - [Ollama](https://ollama.com) installed and running (for default local LLM)
112
+ - Windows: batch scripts provided (`.bat`)
113
+ - Linux / macOS: shell scripts provided (`.sh`) — make executable with `chmod +x *.sh`
114
+
115
+ ### Windows Quick Start
116
+
117
+ ```bat
118
+ REM 1. Initialize git
119
+ 000_init.bat
120
+
121
+ REM 2. Create virtual environment
122
+ 001_env.bat
123
+
124
+ REM 3. Activate virtual environment
125
+ 002_activate.bat
126
+
127
+ REM 4. Install dependencies
128
+ 003_setup.bat
129
+ ```
130
+
131
+ ### Linux / macOS Quick Start
132
+
133
+ ```bash
134
+ # Make scripts executable (one-time)
135
+ chmod +x *.sh
136
+
137
+ # 1. Initialize git
138
+ ./000_init.sh
139
+
140
+ # 2. Create virtual environment
141
+ ./001_env.sh
142
+
143
+ # 3. Activate virtual environment (must be sourced)
144
+ source 002_activate.sh
145
+
146
+ # 4. Install dependencies
147
+ ./003_setup.sh
148
+ ```
149
+
150
+ ### Manual (inside activated venv)
151
+
152
+ ```bash
153
+ pip install -r requirements.txt
154
+ ```
155
+
156
+ ### Configure `.env`
157
+
158
+ Copy and edit the environment file:
159
+
160
+ ```env
161
+ # LLM Provider (default: ollama)
162
+ LLM_PROVIDER=ollama
163
+ OLLAMA_BASE_URL=http://localhost:11434
164
+ OLLAMA_MODEL=llama3.2
165
+
166
+ # Optional providers (uncomment and add keys to switch)
167
+ # LLM_PROVIDER=openai
168
+ # OPENAI_API_KEY=sk-...
169
+
170
+ # ChromaDB storage
171
+ CHROMA_PERSIST_DIR=./data/chroma
172
+
173
+ # Embeddings
174
+ EMBEDDING_MODEL=all-MiniLM-L6-v2
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Usage
180
+
181
+ ```bat
182
+ REM Windows — Run the MCP server
183
+ 004_run.bat
184
+ ```
185
+
186
+ ```bash
187
+ # Linux / macOS
188
+ ./004_run.sh
189
+ ```
190
+
191
+ ```powershell
192
+ # Equivalent (inside activated venv)
193
+ python main.py
194
+ ```
195
+
196
+ ---
197
+
198
+ ## Testing
199
+
200
+ ```bat
201
+ REM Windows
202
+ 005_run_test.bat
203
+ 005_run_code_cov.bat
204
+ ```
205
+
206
+ ```bash
207
+ # Linux / macOS
208
+ ./005_run_test.sh
209
+ ./005_run_code_cov.sh
210
+ ```
211
+
212
+ ```powershell
213
+ # Equivalent inside activated venv (Windows)
214
+ .venv\Scripts\pytest tests/ -v
215
+ .venv\Scripts\pytest tests/ --cov=src --cov-report=term-missing
216
+ ```
217
+
218
+ ```bash
219
+ # Equivalent inside activated venv (Linux / macOS)
220
+ .venv/bin/pytest tests/ -v
221
+ .venv/bin/pytest tests/ --cov=src --cov-report=term-missing
222
+ ```
223
+
224
+ Coverage target: **100% line AND branch coverage per module** — no exceptions.
225
+
226
+ ---
227
+
228
+ ## Security Scanning
229
+
230
+ MemShān enforces a **zero-tolerance vulnerability policy** on the `main` branch.
231
+ All 90 transitive dependencies are audited via [pip-audit](https://pypi.org/project/pip-audit/)
232
+ before every commit that changes `requirements.txt`.
233
+
234
+ ### Run the security scan
235
+
236
+ ```bat
237
+ REM Windows — Full scan: requirements + installed environment → JSON + HTML reports
238
+ 006_pip_audit.bat
239
+ ```
240
+
241
+ ```bash
242
+ # Linux / macOS
243
+ ./006_pip_audit.sh
244
+ ```
245
+
246
+ The script runs **two passes**:
247
+
248
+ | Pass | Scope | Output |
249
+ |---|---|---|
250
+ | Requirements scan | Direct deps + full transitive tree (as pip resolves) | `security_reports\pip_audit_<TS>.json` + `.html` |
251
+ | Environment scan | Everything installed in the venv | `security_reports\pip_audit_env_<TS>.json` + `.html` |
252
+
253
+ Both JSON files are converted automatically to self-contained, dark-themed HTML
254
+ reports with package tables, CVE details, and a filter bar.
255
+
256
+ ### Utility script
257
+
258
+ `tools/pip_audit_to_html.py` — reusable converter. Accepts pip-audit JSON from a
259
+ file or stdin and writes a timestamped HTML report.
260
+
261
+ ```powershell
262
+ # Pipe directly
263
+ $env:PYTHONUTF8="1"
264
+ python -m pip_audit -r requirements.txt --format json 2>$null |
265
+ python tools/pip_audit_to_html.py
266
+
267
+ # From a saved file
268
+ python tools/pip_audit_to_html.py security_reports/audit.json
269
+
270
+ # Custom output path
271
+ python tools/pip_audit_to_html.py audit.json --output reports/my_report.html
272
+ ```
273
+
274
+ ### Copilot prompt
275
+
276
+ Use the `/pip-audit` prompt in GitHub Copilot Chat to run the full scan interactively:
277
+ `.github/prompts/pip-audit.prompt.md`
278
+
279
+ ### Policy
280
+
281
+ - Run `006_pip_audit.bat` (Windows) or `./006_pip_audit.sh` (Linux / macOS) before every commit that adds or changes dependencies.
282
+ - Resolve **ALL** findings before pushing to `main`.
283
+ - Reports are gitignored — only the scripts and prompt are committed.
284
+
285
+ Every test file must cover three scenario groups:
286
+
287
+ ```python
288
+ @pytest.mark.positive # happy path
289
+ @pytest.mark.negative # error / failure conditions
290
+ @pytest.mark.edge # boundary values, empty inputs, None, single-item collections
291
+ ```
292
+
293
+ ---
294
+
295
+ ## Script Reference
296
+
297
+ ### Core Scripts
298
+
299
+ | Windows (`.bat`) | Linux / macOS (`.sh`) | Purpose |
300
+ |---|---|---|
301
+ | `000_init.bat` | `000_init.sh` | Initializes git and sets user name / email |
302
+ | `001_env.bat` | `001_env.sh` | Creates a `.venv` virtual environment |
303
+ | `002_activate.bat` | `source 002_activate.sh` | Activates the virtual environment |
304
+ | `003_setup.bat` | `003_setup.sh` | Installs `requirements.txt` and initialises MemPalace |
305
+ | `004_run.bat` | `004_run.sh` | Runs the MCP server (`main.py`) |
306
+ | `005_run_test.bat` | `005_run_test.sh` | Runs the full pytest suite with HTML report |
307
+ | `005_run_code_cov.bat` | `005_run_code_cov.sh` | Runs tests with HTML coverage report |
308
+ | `006_pip_audit.bat` | `006_pip_audit.sh` | pip-audit security scan → JSON + HTML reports |
309
+ | `008_deactivate.bat` | `source 008_deactivate.sh` | Deactivates the virtual environment |
310
+
311
+ ### MemPalace Utility Scripts
312
+
313
+ | Windows (`.bat`) | Linux / macOS (`.sh`) | Purpose |
314
+ |---|---|---|
315
+ | `007_mp_mine.bat` | `007_mp_mine.sh` | Mine workspace files into MemPalace |
316
+ | `007_mp_status.bat` | `007_mp_status.sh` | Show palace drawer counts and status |
317
+ | `007_mp_search.bat` | `007_mp_search.sh` | Search the palace with optional wing/room filters |
318
+ | `007_mp_compress.bat` | `007_mp_compress.sh` | Compress drawers using AAAK Dialect (~30× token reduction) |
319
+ | `007_mp_diary.bat` | `007_mp_diary.sh` | Read or write agent diary entries |
320
+ | `007_mp_wakeup.bat` | `007_mp_wakeup.sh` | Output L0 + L1 context (~600-900 tokens) for session start |
321
+ | `007_mp_repair.bat` | `007_mp_repair.sh` | Rebuild vector index after corruption or abrupt exit |
322
+
323
+ > **Linux / macOS note:** All `.sh` scripts must be made executable once: `chmod +x *.sh`
324
+ > `002_activate.sh` and `008_deactivate.sh` must be **sourced** (`source <script>`), not executed.
325
+
326
+ ---
327
+
328
+ ## Project Structure
329
+
330
+ ### Implemented
331
+
332
+ ```
333
+ src/
334
+ ├── config.py # ✅ Pydantic BaseSettings — all env config + LLM factory
335
+ ├── llm/ # ✅ LLM provider adapters
336
+ │ ├── client.py # LLMClient ABC
337
+ │ ├── ollama_client.py # Ollama (default, fully offline)
338
+ │ ├── openai_client.py # OpenAI
339
+ │ ├── gemini_client.py # Google Gemini
340
+ │ └── anthropic_client.py # Anthropic Claude
341
+ ├── base/ # ✅ Method of Loci — Base Layer
342
+ │ ├── loci_store.py # ChromaDB Wings/Rooms abstraction
343
+ │ └── embedder.py # sentence-transformers wrapper
344
+ └── layers/
345
+ ├── major_system/ # ✅ Layer 1 — Numerical Precision
346
+ │ └── phonetic_encoder.py # Numbers → phonetic consonant tags
347
+ └── songlines/ # ✅ Layer 2 — Contextual Continuity
348
+ └── knowledge_graph.py # NetworkX directed graph; Context Trails; GraphML persistence
349
+ ```
350
+
351
+ ### Planned (upcoming phases)
352
+
353
+ ```
354
+ src/
355
+ ├── server.py # 🔲 MCP server entry point (FastMCP) — Phase 9
356
+ └── layers/
357
+ ├── pao/ # 🔲 Layer 3 — Episodic Compression (SAO triplets) — Phase 6
358
+ │ └── snapshot.py
359
+ ├── pipeline/ # 🔲 Unified retrieval pipeline — Phase 7
360
+ │ └── retrieval.py
361
+ └── tools/ # 🔲 MCP tool definitions — Phase 8
362
+ └── mcp_tools.py
363
+ ```
364
+
365
+ ---
366
+
367
+ ## Success Metrics & Observability
368
+
369
+ MemShān measures intelligence *density*, not just retrieval correctness. The scorecard below
370
+ bridges technical performance of the mnemonic layers with enterprise engineering goals.
371
+
372
+ ### 1. Key Performance Indicators (KPIs)
373
+
374
+ *How the server runs — quantified technical efficiency per retrieval layer.*
375
+
376
+ | Category | KPI | Target | Rationale |
377
+ |---|---|---|---|
378
+ | **Retrieval Quality** | Faithfulness / Groundedness | > 95% | Prevents hallucinated context when traversing a Songline trail |
379
+ | **Numerical Precision** | Numerical Recall Accuracy | 100% | Validates the Major System phonetic-tag pipeline for stats and dates |
380
+ | **Compression** | Context Compression Ratio | ≥ 5 : 1 | Measures how efficiently the PAO System converts raw session logs to actionable SAO triplets |
381
+ | **Latency** | P99 Retrieval Latency | < 200 ms | Loci lookups must not throttle the agent's reasoning loop |
382
+ | **Observability** | PulseGuard Hit Rate | 100% of queries | Ensures every retrieval event is logged and validated for semantic drift |
383
+
384
+ ---
385
+
386
+ ### 2. Key Result Areas (KRAs)
387
+
388
+ *What MemShān achieves — enterprise-level value domains.*
389
+
390
+ #### KRA 1 — Amnesia-Proof Persistence
391
+
392
+ > **Metric: Context Retention Span**
393
+
394
+ Measure how many consecutive sessions an agent maintains perfect continuity on a complex,
395
+ multi-phase project without requiring a re-prompt or context refresh.
396
+
397
+ - **Baseline:** standard zero-shot / short-context agent — continuity typically breaks after 1–2 sessions.
398
+ - **MemShān target:** ≥ 10 sessions with no loss of project state.
399
+
400
+ #### KRA 2 — Quality Engineering Modernisation
401
+
402
+ > **Metric: Defect Detection Velocity**
403
+
404
+ Measure how much faster AI-assisted QE reviews identify architectural flaws when MemShān provides
405
+ accumulated project memory versus cold zero-shot prompts.
406
+
407
+ - **Baseline:** cold-prompt review time per module (measured in minutes).
408
+ - **MemShān target:** ≥ 40% reduction in time-to-defect-detection.
409
+
410
+ #### KRA 3 — Resource Optimisation
411
+
412
+ > **Metric: Token-to-Knowledge Density (TKD)**
413
+
414
+ $$\text{TKD} = \frac{\text{Relevant facts delivered to model}}{\text{Tokens consumed from context window}}$$
415
+
416
+ High TKD means MemShān surfaces more signal within the model's 128k / 200k token budget.
417
+
418
+ - **Target:** TKD ≥ 3× vs. naive full-log injection.
419
+
420
+ ---
421
+
422
+ ### 3. Layer-Specific Experimental Metrics
423
+
424
+ *Proving that each mnemonic addition (beyond standard vector RAG) earns its place.*
425
+
426
+ #### Songlines — Narrative Coherence
427
+
428
+ **Test:** Ask the AI to reconstruct a project's event history from Songline graph traversal.
429
+
430
+ | Metric | Description | Pass Threshold |
431
+ |---|---|---|
432
+ | **Temporal Accuracy** | Events retrieved in correct causal / chronological order | ≥ 95% |
433
+ | **Sequence Drift** | Compared against standard vector-only RAG (which frequently reorders events) | Songlines must outperform by ≥ 20 pp |
434
+
435
+ #### PAO System — Reconstruction Fidelity
436
+
437
+ **Test:** Compress a session log into SAO triplets, then ask the AI to reconstruct the full system state from triplets alone.
438
+
439
+ | Metric | Description | Pass Threshold |
440
+ |---|---|---|
441
+ | **Reconstruction Fidelity** | Facts present in original log that survive compression → decompression | ≥ 98% |
442
+ | **Data Leakage Rate** | Critical facts lost during PAO snapshot | 0% for facts tagged `critical` |
443
+
444
+ #### Major System — Numeric Round-Trip
445
+
446
+ **Test:** Store text containing numerical data, query using rephrased numeric context.
447
+
448
+ | Metric | Description | Pass Threshold |
449
+ |---|---|---|
450
+ | **Phonetic Tag Recall** | Correct chunk retrieved via phonetic tag alone | 100% |
451
+ | **False Positive Rate** | Unrelated numeric chunks surfaced in results | < 2% |
452
+
453
+ ---
454
+
455
+ ### 4. Observability Dashboard Checklist
456
+
457
+ *Recommended metrics to surface in Grafana / a custom VeredianAI UI.*
458
+
459
+ | Signal | What to Track | Alert Condition |
460
+ |---|---|---|
461
+ | **Memory Growth Rate** | Wing/Room document count over time | Sudden spike > 3× daily average |
462
+ | **Room Utilisation** | Query hit-count per Room (hot vs. cold context) | Room unutilised for > 30 days → archive candidate |
463
+ | **Semantic Drift Alarm** | Distance between query embedding and retrieved chunk | Cosine distance > 0.4 → PulseGuard flag |
464
+ | **Hallucination Rate** | % of responses where retrieved chunk was not used by model | Target < 5% |
465
+ | **LLM Fallback Rate** | % of PAO extractions that fell back from spaCy to LLM | Target < 20% (high rate = spaCy model needs retraining) |
466
+ | **P99 / P95 Latency** | Per-layer breakdown: embed → query → graph expand → merge | P99 > 200 ms → alert |
467
+ | **Provider Error Rate** | Per LLM provider: 4xx / 5xx / timeout rate | Any provider > 1% error rate → alert |
468
+
469
+ ---
470
+
471
+ ## Engineering Standards
472
+
473
+ | Standard | Requirement |
474
+ |---|---|
475
+ | **SOLID** | Every production class in `src/` must demonstrably satisfy all five SOLID principles |
476
+ | **OOP** | Encapsulation, composition over inheritance, constructor injection throughout |
477
+ | **Test Coverage** | **100% line AND branch** coverage per module — no exceptions |
478
+ | **Test Scenarios** | Every test file: `@pytest.mark.positive` + `@pytest.mark.negative` + `@pytest.mark.edge` |
479
+ | **Database Changes** | All schema changes via Alembic migration — never mutate schema directly |
480
+ | **Security Scanning** | `pip-audit -r requirements.txt` before every commit with dependency changes |
481
+ | **Session Close** | Write MemPalace diary entry + update `Session_N.md` + commit & push every session |
482
+ | **Drift Review** | Compare implementation vs architecture docs every 3 sessions |
483
+
484
+ See [`.github/copilot-instructions.md`](.github/copilot-instructions.md) for full details.
485
+
486
+ ---
487
+
488
+ ## Contributing
489
+
490
+ Contributions are welcome. Please read [ARCHITECTURE.md](ARCHITECTURE.md) and
491
+ [TASK_EXECUTION_PLAN.md](TASK_EXECUTION_PLAN.md) before submitting a PR.
492
+
493
+ 1. Fork the repository
494
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
495
+ 3. Commit your changes: `git commit -m "feat: add my feature"`
496
+ 4. Push to the branch: `git push origin feature/my-feature`
497
+ 5. Open a Pull Request
498
+
499
+ ---
500
+
501
+ ## License
502
+
503
+ MIT License — see [LICENSE](LICENSE) for details.
@@ -0,0 +1,48 @@
1
+ README.md
2
+ pyproject.toml
3
+ MemShan.egg-info/PKG-INFO
4
+ MemShan.egg-info/SOURCES.txt
5
+ MemShan.egg-info/dependency_links.txt
6
+ MemShan.egg-info/entry_points.txt
7
+ MemShan.egg-info/requires.txt
8
+ MemShan.egg-info/top_level.txt
9
+ src/__init__.py
10
+ src/config.py
11
+ src/server.py
12
+ src/base/__init__.py
13
+ src/base/embedder.py
14
+ src/base/loci_store.py
15
+ src/layers/__init__.py
16
+ src/layers/major_system/__init__.py
17
+ src/layers/major_system/phonetic_encoder.py
18
+ src/layers/pao/__init__.py
19
+ src/layers/pao/snapshot.py
20
+ src/layers/songlines/__init__.py
21
+ src/layers/songlines/knowledge_graph.py
22
+ src/llm/__init__.py
23
+ src/llm/anthropic_client.py
24
+ src/llm/client.py
25
+ src/llm/gemini_client.py
26
+ src/llm/ollama_client.py
27
+ src/llm/openai_client.py
28
+ src/pipeline/__init__.py
29
+ src/pipeline/retrieval.py
30
+ src/tools/__init__.py
31
+ src/tools/mcp_tools.py
32
+ tests/test_anthropic_client.py
33
+ tests/test_config.py
34
+ tests/test_embedder.py
35
+ tests/test_gemini_client.py
36
+ tests/test_gemini_live.py
37
+ tests/test_knowledge_graph.py
38
+ tests/test_llm_client.py
39
+ tests/test_loci_store.py
40
+ tests/test_main.py
41
+ tests/test_mcp_tools.py
42
+ tests/test_ollama_client.py
43
+ tests/test_ollama_live.py
44
+ tests/test_openai_client.py
45
+ tests/test_phonetic_encoder.py
46
+ tests/test_pipeline.py
47
+ tests/test_server.py
48
+ tests/test_snapshot.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ memshan = src.server:run
@@ -0,0 +1,23 @@
1
+ mcp[cli]
2
+ chromadb
3
+ sentence-transformers
4
+ networkx
5
+ spacy
6
+ httpx
7
+ openai>=1.0.0
8
+ google-genai
9
+ anthropic
10
+ python-dotenv
11
+ pydantic>=2.0
12
+ pydantic-settings
13
+ rich
14
+ mempalace
15
+
16
+ [demo]
17
+ streamlit
18
+
19
+ [dev]
20
+ pytest
21
+ pytest-html
22
+ pytest-cov
23
+ pytest-mock
@@ -0,0 +1 @@
1
+ src