reelith 0.0.1__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 (41) hide show
  1. reelith-0.0.1/Cargo.lock +190 -0
  2. reelith-0.0.1/Cargo.toml +13 -0
  3. reelith-0.0.1/LICENSE +21 -0
  4. reelith-0.0.1/PKG-INFO +333 -0
  5. reelith-0.0.1/README.md +309 -0
  6. reelith-0.0.1/crates/reelith-engine/Cargo.toml +18 -0
  7. reelith-0.0.1/crates/reelith-engine/src/engine.rs +385 -0
  8. reelith-0.0.1/crates/reelith-engine/src/fenwick.rs +274 -0
  9. reelith-0.0.1/crates/reelith-engine/src/lib.rs +43 -0
  10. reelith-0.0.1/crates/reelith-engine/src/python.rs +118 -0
  11. reelith-0.0.1/crates/reelith-engine/src/rng.rs +64 -0
  12. reelith-0.0.1/crates/reelith-engine/src/sampler.rs +187 -0
  13. reelith-0.0.1/pyproject.toml +66 -0
  14. reelith-0.0.1/src/reelith/__init__.py +3 -0
  15. reelith-0.0.1/src/reelith/artifact.py +183 -0
  16. reelith-0.0.1/src/reelith/bootstrap.py +198 -0
  17. reelith-0.0.1/src/reelith/context.py +81 -0
  18. reelith-0.0.1/src/reelith/doctor.py +98 -0
  19. reelith-0.0.1/src/reelith/ingest/__init__.py +5 -0
  20. reelith-0.0.1/src/reelith/ingest/archive.py +139 -0
  21. reelith-0.0.1/src/reelith/ingest/fetcher.py +111 -0
  22. reelith-0.0.1/src/reelith/ingest/letterboxd_live.py +94 -0
  23. reelith-0.0.1/src/reelith/ingest/models.py +123 -0
  24. reelith-0.0.1/src/reelith/ingest/rss.py +109 -0
  25. reelith-0.0.1/src/reelith/ingest/scraper.py +241 -0
  26. reelith-0.0.1/src/reelith/oov.py +298 -0
  27. reelith-0.0.1/src/reelith/prep/__init__.py +3 -0
  28. reelith-0.0.1/src/reelith/prep/__main__.py +102 -0
  29. reelith-0.0.1/src/reelith/prep/als.py +72 -0
  30. reelith-0.0.1/src/reelith/prep/build.py +64 -0
  31. reelith-0.0.1/src/reelith/prep/export.py +72 -0
  32. reelith-0.0.1/src/reelith/prep/fetch.py +104 -0
  33. reelith-0.0.1/src/reelith/prep/fixture_gen.py +56 -0
  34. reelith-0.0.1/src/reelith/prep/hilbert.py +41 -0
  35. reelith-0.0.1/src/reelith/prep/letterboxd.py +149 -0
  36. reelith-0.0.1/src/reelith/prep/svd.py +76 -0
  37. reelith-0.0.1/src/reelith/prep/umap_reduce.py +46 -0
  38. reelith-0.0.1/src/reelith/prompts.py +48 -0
  39. reelith-0.0.1/src/reelith/rl.py +186 -0
  40. reelith-0.0.1/src/reelith/server.py +504 -0
  41. reelith-0.0.1/src/reelith/state.py +343 -0
@@ -0,0 +1,190 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.5"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
16
+
17
+ [[package]]
18
+ name = "heck"
19
+ version = "0.5.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
22
+
23
+ [[package]]
24
+ name = "indoc"
25
+ version = "2.0.8"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
28
+ dependencies = [
29
+ "rustversion",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "libc"
34
+ version = "0.2.191"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
37
+
38
+ [[package]]
39
+ name = "memmap2"
40
+ version = "0.9.12"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "6b0ca1155a9ecc25aa12e8313a119f32edf0255fea2f44839c4ac0a12b2ac157"
43
+ dependencies = [
44
+ "libc",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "memoffset"
49
+ version = "0.9.1"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
52
+ dependencies = [
53
+ "autocfg",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "once_cell"
58
+ version = "1.21.4"
59
+ source = "registry+https://github.com/rust-lang/crates.io-index"
60
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
61
+
62
+ [[package]]
63
+ name = "portable-atomic"
64
+ version = "1.15.0"
65
+ source = "registry+https://github.com/rust-lang/crates.io-index"
66
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
67
+
68
+ [[package]]
69
+ name = "proc-macro2"
70
+ version = "1.0.107"
71
+ source = "registry+https://github.com/rust-lang/crates.io-index"
72
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
73
+ dependencies = [
74
+ "unicode-ident",
75
+ ]
76
+
77
+ [[package]]
78
+ name = "pyo3"
79
+ version = "0.22.6"
80
+ source = "registry+https://github.com/rust-lang/crates.io-index"
81
+ checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
82
+ dependencies = [
83
+ "cfg-if",
84
+ "indoc",
85
+ "libc",
86
+ "memoffset",
87
+ "once_cell",
88
+ "portable-atomic",
89
+ "pyo3-build-config",
90
+ "pyo3-ffi",
91
+ "pyo3-macros",
92
+ "unindent",
93
+ ]
94
+
95
+ [[package]]
96
+ name = "pyo3-build-config"
97
+ version = "0.22.6"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
100
+ dependencies = [
101
+ "once_cell",
102
+ "target-lexicon",
103
+ ]
104
+
105
+ [[package]]
106
+ name = "pyo3-ffi"
107
+ version = "0.22.6"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
110
+ dependencies = [
111
+ "libc",
112
+ "pyo3-build-config",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "pyo3-macros"
117
+ version = "0.22.6"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
120
+ dependencies = [
121
+ "proc-macro2",
122
+ "pyo3-macros-backend",
123
+ "quote",
124
+ "syn",
125
+ ]
126
+
127
+ [[package]]
128
+ name = "pyo3-macros-backend"
129
+ version = "0.22.6"
130
+ source = "registry+https://github.com/rust-lang/crates.io-index"
131
+ checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
132
+ dependencies = [
133
+ "heck",
134
+ "proc-macro2",
135
+ "pyo3-build-config",
136
+ "quote",
137
+ "syn",
138
+ ]
139
+
140
+ [[package]]
141
+ name = "quote"
142
+ version = "1.0.47"
143
+ source = "registry+https://github.com/rust-lang/crates.io-index"
144
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
145
+ dependencies = [
146
+ "proc-macro2",
147
+ ]
148
+
149
+ [[package]]
150
+ name = "reelith-engine"
151
+ version = "0.0.1"
152
+ dependencies = [
153
+ "memmap2",
154
+ "pyo3",
155
+ ]
156
+
157
+ [[package]]
158
+ name = "rustversion"
159
+ version = "1.0.23"
160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
161
+ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
162
+
163
+ [[package]]
164
+ name = "syn"
165
+ version = "2.0.119"
166
+ source = "registry+https://github.com/rust-lang/crates.io-index"
167
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
168
+ dependencies = [
169
+ "proc-macro2",
170
+ "quote",
171
+ "unicode-ident",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "target-lexicon"
176
+ version = "0.12.16"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
179
+
180
+ [[package]]
181
+ name = "unicode-ident"
182
+ version = "1.0.27"
183
+ source = "registry+https://github.com/rust-lang/crates.io-index"
184
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
185
+
186
+ [[package]]
187
+ name = "unindent"
188
+ version = "0.2.4"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
@@ -0,0 +1,13 @@
1
+ [workspace]
2
+ members = ["crates/reelith-engine"]
3
+ resolver = "2"
4
+
5
+ [workspace.package]
6
+ version = "0.0.1"
7
+ edition = "2021"
8
+ license = "MIT"
9
+
10
+ [workspace.dependencies]
11
+ # Pinned to the locally cached 0.22 line: this machine's cargo cannot reach
12
+ # crates.io (schannel TLS failure), so offline builds are the only option.
13
+ pyo3 = { version = "0.22", features = ["abi3-py311"] }
reelith-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mahdi Alikhah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
reelith-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,333 @@
1
+ Metadata-Version: 2.4
2
+ Name: reelith
3
+ Version: 0.0.1
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Topic :: Multimedia :: Video
7
+ Requires-Dist: mcp>=1.9
8
+ Requires-Dist: numpy>=1.26
9
+ Requires-Dist: pyarrow>=15
10
+ Requires-Dist: httpx>=0.27
11
+ Requires-Dist: beautifulsoup4>=4.12
12
+ Requires-Dist: lxml>=5
13
+ License-File: LICENSE
14
+ Summary: Local MCP film recommender for your Letterboxd history
15
+ Keywords: mcp,letterboxd,recommendations,model-context-protocol
16
+ Author: Mahdi Alikhah
17
+ License: MIT
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
20
+ Project-URL: Homepage, https://github.com/MahdiAlikhah/reelith
21
+ Project-URL: Issues, https://github.com/MahdiAlikhah/reelith/issues
22
+ Project-URL: Repository, https://github.com/MahdiAlikhah/reelith
23
+
24
+ # reelith
25
+
26
+ [![CI](https://github.com/MahdiAlikhah/reelith/actions/workflows/ci.yml/badge.svg)](https://github.com/MahdiAlikhah/reelith/actions/workflows/ci.yml)
27
+ [![PyPI](https://img.shields.io/pypi/v/reelith)](https://pypi.org/project/reelith/)
28
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
29
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](pyproject.toml)
30
+
31
+ A local, offline-capable film recommender for your Letterboxd history.
32
+
33
+ Your client LLM acts as a **semantic router**: it turns "something cynical and
34
+ slick" into anchor films like *Fight Club* and *Nightcrawler*, and a local vector
35
+ engine does the actual search. Nothing about your taste leaves your machine, and
36
+ the recommendations come from arithmetic over your own ratings rather than from a
37
+ model's memory.
38
+
39
+ ## How it works
40
+
41
+ ```
42
+ your mood
43
+ │
44
+ ▼
45
+ client LLM (BYO: Claude Desktop, ...) ← semantic router, no recommendations of its own
46
+ │ MCP over stdio, three tools
47
+ ▼
48
+ Python MCP server ──────────────┐
49
+ │ │
50
+ ▼ ▼
51
+ Rust/PyO3 vector engine SQLite local state
52
+ (cosine + Hilbert + Lehmer) (history, policy, cache)
53
+ ```
54
+
55
+ - **Anchors → vector.** Your positive anchors become a centroid; the policy blends
56
+ it with a learned vector `s_t` (state `S₀` is a flat, unweighted centroid of your
57
+ rated history — the MDP starting state).
58
+ - **Search.** Cosine scores over the whole catalog, then a top-*m* region ordered
59
+ by Hilbert rank and sampled by weighted Lehmer unranking. Sampling without
60
+ replacement, no duplicates, tunable temperature. As temperature approaches zero,
61
+ the output converges exactly to greedy.
62
+ - **Feedback.** `accept` / `reject_dislike` move `s_t`; `reject_seen_it` only masks.
63
+
64
+ ## Requirements
65
+
66
+ - Python 3.11+
67
+ - [uv](https://docs.astral.sh/uv/)
68
+
69
+ That is all a user needs. The Rust extension ships as a prebuilt `abi3` wheel
70
+ (one wheel covers every Python 3.11+), and the recommendation index builds
71
+ itself on first run, so there is no compiler and no setup step.
72
+
73
+ ## Install (users)
74
+
75
+ The server entry is always the same — `uvx reelith`, stdio transport. No compiler,
76
+ no config file, nothing to build.
77
+
78
+ ```bash
79
+ uvx reelith doctor # check this machine, then prints your client entry
80
+ ```
81
+
82
+ Then add it to any MCP client:
83
+
84
+ ```json
85
+ { "mcpServers": { "reelith": { "command": "uvx", "args": ["reelith"] } } }
86
+ ```
87
+
88
+ Claude Code:
89
+
90
+ ```bash
91
+ claude mcp add reelith -- uvx reelith
92
+ ```
93
+
94
+ `reelith doctor` is worth running first: the first recommendation downloads the
95
+ index, and in most MCP clients that progress goes to a stderr stream the host
96
+ never shows. Running it in a terminal once means the download happens where you
97
+ can see it.
98
+
99
+ ## The download (what it is and why)
100
+
101
+ reelith needs a **vector index** to rank films: one vector per film, learned from
102
+ 10.2 million Letterboxd ratings. That is the model. It is not a cache of the
103
+ site, and it is not your data — it is what makes recommendations arithmetic
104
+ instead of an LLM guessing.
105
+
106
+ It comes as three files totalling ~40 MB, fetched once into `~/.reelith/artifact/`:
107
+
108
+ | File | Size | What it is |
109
+ |---|---|---|
110
+ | `embeddings.bin` | 34 MB | 138,016 films × 64 floats. The actual vectors. |
111
+ | `films.sidecar.parquet` | 6.1 MB | Per-film metadata: slug, title, and `year` for the subset that has one. |
112
+ | `meta.json` | 300 B | Dimensions and build provenance, used for integrity checks. |
113
+
114
+ **Why not ship them inside the package?** A wheel is downloaded per virtualenv,
115
+ per platform. The index is fetched once per machine and shared by every client
116
+ that uses reelith.
117
+
118
+ **Why not fetch live from Letterboxd?** Rediscovering 138k films on every query
119
+ would be slow, rate-limited, and `robots.txt` forbids the browse pages. Live
120
+ Letterboxd is used only to bridge a film the index has never seen.
121
+
122
+ **After the first run there is no network requirement.** Queries are answered
123
+ from the mmap'd vectors on disk.
124
+
125
+ If the bundle is unreachable, reelith falls back to rebuilding from the public
126
+ [Letterboxd 10M ratings dataset](https://huggingface.co/datasets/titouann/letterboxd-10m-movies-ratings-2025):
127
+ `/prep/fetch-letterboxd` (~107 MB) then `letterboxd`, ~30 s of CPU. Same index,
128
+ more bytes. A self-hoster is never stuck.
129
+
130
+ Override the location with `REELITH_HOME`, point at a bundle or mirror with
131
+ `REELITH_BUNDLE_URL`, use a prebuilt index with `REELITH_ARTIFACT_DIR`, or set
132
+ `REELITH_NO_BOOTSTRAP=1` to get the old loud failure instead (useful in CI and
133
+ offline runs).
134
+
135
+ ## Install (per client)
136
+
137
+ The entry is identical everywhere — `uvx reelith`, stdio transport — because
138
+ `uvx` resolves the package without you choosing a Python or a venv. Copy the row
139
+ for your client.
140
+
141
+ **Claude Code**
142
+ ```bash
143
+ claude mcp add reelith -- uvx reelith
144
+ ```
145
+
146
+ **Claude Desktop** — `claude_desktop_config.json` (Windows:
147
+ `%APPDATA%\Claude\`, macOS: `~/Library/Application Support/Claude/`, Linux:
148
+ `~/.config/Claude/`):
149
+ ```json
150
+ { "mcpServers": { "reelith": { "command": "uvx", "args": ["reelith"] } } }
151
+ ```
152
+ Restart Claude Desktop afterwards.
153
+
154
+ **Cursor** — `~/.cursor/mcp.json`:
155
+ ```json
156
+ { "mcpServers": { "reelith": { "command": "uvx", "args": ["reelith"] } } }
157
+ ```
158
+
159
+ **VS Code** — `.vscode/mcp.json`:
160
+ ```json
161
+ { "servers": { "reelith": { "type": "stdio", "command": "uvx", "args": ["reelith"] } } }
162
+ ```
163
+
164
+ **Codex CLI**
165
+ ```bash
166
+ codex mcp add reelith -- uvx reelith
167
+ ```
168
+
169
+ **Gemini CLI** — `~/.gemini/settings.json`:
170
+ ```json
171
+ { "mcpServers": { "reelith": { "command": "uvx", "args": ["reelith"] } } }
172
+ ```
173
+
174
+ **DeepSeek Harness** — `~/.dsh/profiles/<profile>/cordis.patch.yml`:
175
+ ```yaml
176
+ - id: reelith
177
+ command: 'uvx'
178
+ args: ['reelith']
179
+ ```
180
+
181
+ **Anything else** that speaks MCP over stdio: the command is `uvx`, the args are
182
+ `["reelith"]`. That is the whole interface.
183
+
184
+ Do not have `uv`? Install it first:
185
+ `powershell -c "irm https://astral.sh/uv/install.ps1 | iex"` (Windows) or
186
+ `curl -LsSf https://astral.sh/uv/install.sh | sh` (macOS/Linux).
187
+
188
+ ### Without uvx
189
+
190
+ ```bash
191
+ pip install reelith # compiles Rust; needs a toolchain
192
+ reelith doctor
193
+ ```
194
+ Then use `"command": "reelith"` with no args. Prefer `uvx`: it needs no compiler
195
+ and no venv.
196
+
197
+ ## Develop
198
+
199
+ ```bash
200
+ uv sync # builds the Rust extension from source
201
+ uv run pytest # 238 tests, no network needed
202
+ ```
203
+
204
+ The `prep` dependency group (dataset build only) is not installed by default: it is
205
+ large and the server never imports it. Add it with `uv sync --group prep` when you
206
+ build an artifact.
207
+
208
+ Try it against the committed synthetic fixture before building a real artifact:
209
+
210
+ ```bash
211
+ uv run python examples/quickstart.py
212
+ ```
213
+
214
+ That drives all three tools over a real MCP client session — ingest a sample
215
+ export, query, record feedback — and prints what comes back. No client to
216
+ configure, no network, no API key. To use a real artifact instead:
217
+
218
+ ```bash
219
+ uv run python examples/quickstart.py --artifact data/artifacts/dev --state data/demo.db
220
+ ```
221
+
222
+ To run the actual server (what a client launches), use `uv run reelith` with the
223
+ environment variables from [docs/client-config.md](docs/client-config.md).
224
+
225
+ ## Build a real artifact
226
+
227
+ The committed fixture is 200 synthetic films — enough to exercise every code path,
228
+ not enough to recommend anything. For real use, build from a ratings dataset:
229
+
230
+ ```bash
231
+ uv run --group prep python -m reelith.prep build \
232
+ --dataset <huggingface-dataset> \
233
+ --outdir data/artifacts/dev
234
+ ```
235
+
236
+ This produces three files, which travel together:
237
+
238
+ | File | Contents |
239
+ |---|---|
240
+ | `embeddings.bin` | `LREC` magic, version, N, dim, then N×dim float32 unit vectors |
241
+ | `films.sidecar.parquet` | slug, title, year, runtime, director, genres, `hilbert_rank` (several are empty: see below) |
242
+ | `meta.json` | build parameters, dim, row count, checksums |
243
+
244
+ Expected scale: ~159k films × 64 dims ≈ 41 MB. See
245
+ [docs/FULL-BUILD.md](docs/FULL-BUILD.md) for the full-size build and
246
+ [docs/OFFLINE-BUILD.md](docs/OFFLINE-BUILD.md) for a no-network build.
247
+
248
+ ## Connect a client
249
+
250
+ See **[docs/client-config.md](docs/client-config.md)**. Short version: register
251
+ `reelith` as a stdio MCP server, point `REELITH_ARTIFACT_DIR` at your artifact, and
252
+ paste **[docs/SYSTEM-PROMPT.md](docs/SYSTEM-PROMPT.md)** into the client's custom
253
+ instructions.
254
+
255
+ ## The three tools
256
+
257
+ | Tool | Purpose |
258
+ |---|---|
259
+ | `ingest_letterboxd_data(username \| local_zip_path)` | Load history from a public profile or export zip. Exactly one argument. |
260
+ | `query_embedding_space(positive_anchor_movies, ...)` | Recommend films near the anchors. Supports `k`, negatives, director/year/runtime filters, `include_watched`. |
261
+ | `record_rl_feedback(movie_id, feedback_type)` | `accept` / `reject_dislike` / `reject_seen_it`. |
262
+
263
+ Anchors are film titles, not moods — the client LLM supplies the semantics. Titles
264
+ outside the local index come back in `missing_anchors` with a reason
265
+ (`no_api_key`, `no_tmdb_result`, `no_proxy`, `network`) so the client can say so
266
+ honestly instead of guessing.
267
+
268
+ ## Prompts and resources
269
+
270
+ Two more MCP surfaces, both read-only, for jobs that are not tool calls:
271
+
272
+ | Surface | Name | What it does |
273
+ |---|---|---|
274
+ | prompt | `recommend` | Takes a `mood`, expands it into the "find anchors, then query" instruction. |
275
+ | prompt | `onboard` | The setup flow: ask for a username or export zip, then ingest. |
276
+ | resource | `reelith://index` | Films, dimensions, ratings and history size — the index's provenance. |
277
+ | resource | `reelith://history` | Your films with the rating that counts, newest first. |
278
+ | resource | `reelith://films/{slug}` | One film record. |
279
+
280
+ Resources are what a person can *attach* to a conversation; tools are what the
281
+ model calls. Inspect engine state without burning a turn on a tool call.
282
+
283
+ Caveat on `reelith://films/{slug}`: the artifact carries `year` for only 22,289 of
284
+ 138,016 films, and no genres, director or runtime at all. Those fields are `null`,
285
+ not zero — the ratings dump does not include them.
286
+
287
+ ## Layout
288
+
289
+ ```
290
+ src/reelith/
291
+ server.py MCP server, three tools
292
+ context.py startup wiring: artifact, engine, state, policy, resolver
293
+ prompts.py the system prompt (canonical copy)
294
+ artifact.py artifact loading
295
+ state.py SQLite: history, policy, trajectories, TMDB cache
296
+ rl.py policy: S0, query blending, feedback updates, temperature
297
+ oov.py out-of-vocabulary resolution + TMDB proxy imputation
298
+ ingest/ zip parsing, scraping, pagination
299
+ prep/ artifact build: ALS, dimensionality reduction, Hilbert keys
300
+ crates/reelith-engine/ Rust: mmap vectors, Fenwick sampling, Hilbert ordering
301
+ spec/ per-module specs
302
+ tasks/ plan, task list, checkpoints
303
+ ```
304
+
305
+ ## Testing
306
+
307
+ ```bash
308
+ uv run pytest # everything
309
+ uv run pytest tests/server -q # MCP tools through a real client session
310
+ cargo test --offline # Rust: sampling, Fenwick, Hilbert
311
+ ```
312
+
313
+ The test suite needs no network. Scraper tests use synthetic HTML fixtures that
314
+ reproduce Letterboxd's documented markup conventions — they pin our parsers'
315
+ behavior, but they were not recorded from the live site, so a future DOM change
316
+ would not be caught by them. The parsers fail loudly rather than silently dropping
317
+ rows.
318
+
319
+ ## Known limits
320
+
321
+ - **Coverage is the artifact's vocabulary.** Films outside it are resolved through
322
+ TMDB proxies or reported missing; they are never invented.
323
+ - **Scraping is best-effort.** Letterboxd has no public API and may change its
324
+ markup. The zip export path is the stable fallback.
325
+ - **Embeddings are trained geometry, not semantics.** A random-projection fallback
326
+ replaces UMAP when `umap-learn` is unavailable; recommendations remain coherent
327
+ but less sharp.
328
+ - **Single user, single process.** stdio transport, one state database, no auth.
329
+
330
+ ## License
331
+
332
+ Not yet chosen.
333
+