streamembed 0.2.0__tar.gz → 0.3.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 (58) hide show
  1. streamembed-0.3.0/PKG-INFO +86 -0
  2. streamembed-0.3.0/PYPI.md +56 -0
  3. streamembed-0.3.0/README.md +273 -0
  4. streamembed-0.3.0/examples/main.py +31 -0
  5. {streamembed-0.2.0 → streamembed-0.3.0}/pyproject.toml +4 -3
  6. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/__init__.py +3 -3
  7. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/ann.py +1 -1
  8. streamembed-0.3.0/src/streamembed/api.py +726 -0
  9. streamembed-0.3.0/src/streamembed/capture.py +386 -0
  10. streamembed-0.3.0/src/streamembed/cli.py +325 -0
  11. streamembed-0.3.0/src/streamembed/config.py +247 -0
  12. streamembed-0.3.0/src/streamembed/defaults.toml +49 -0
  13. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/encoder.py +22 -8
  14. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/qwen_embedder.py +4 -3
  15. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/gate.py +10 -10
  16. streamembed-0.3.0/src/streamembed/index.py +556 -0
  17. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/models.py +49 -3
  18. streamembed-0.3.0/src/streamembed/queryserver.py +112 -0
  19. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/service.py +116 -21
  20. streamembed-0.3.0/src/streamembed/static/results.html +380 -0
  21. streamembed-0.3.0/src/streamembed/visualize.py +87 -0
  22. streamembed-0.3.0/src/streamembed/webui.py +160 -0
  23. {streamembed-0.2.0 → streamembed-0.3.0}/tests/conftest.py +11 -0
  24. streamembed-0.3.0/tests/test_api.py +1552 -0
  25. streamembed-0.3.0/tests/test_config.py +170 -0
  26. streamembed-0.3.0/tests/test_encoder_order.py +68 -0
  27. streamembed-0.3.0/tests/test_front.py +150 -0
  28. {streamembed-0.2.0 → streamembed-0.3.0}/tests/test_models.py +12 -0
  29. streamembed-0.3.0/tests/test_prune.py +85 -0
  30. streamembed-0.2.0/PKG-INFO +0 -77
  31. streamembed-0.2.0/PYPI.md +0 -48
  32. streamembed-0.2.0/README.md +0 -180
  33. streamembed-0.2.0/examples/main.py +0 -21
  34. streamembed-0.2.0/src/streamembed/api.py +0 -333
  35. streamembed-0.2.0/src/streamembed/capture.py +0 -183
  36. streamembed-0.2.0/src/streamembed/cli.py +0 -154
  37. streamembed-0.2.0/src/streamembed/config.py +0 -135
  38. streamembed-0.2.0/src/streamembed/defaults.toml +0 -32
  39. streamembed-0.2.0/src/streamembed/index.py +0 -232
  40. streamembed-0.2.0/src/streamembed/static/results.html +0 -195
  41. streamembed-0.2.0/src/streamembed/timeparse.py +0 -164
  42. streamembed-0.2.0/src/streamembed/visualize.py +0 -42
  43. streamembed-0.2.0/tests/test_api.py +0 -609
  44. streamembed-0.2.0/tests/test_config.py +0 -66
  45. {streamembed-0.2.0 → streamembed-0.3.0}/.gitignore +0 -0
  46. {streamembed-0.2.0 → streamembed-0.3.0}/.hgignore +0 -0
  47. {streamembed-0.2.0 → streamembed-0.3.0}/LICENSE +0 -0
  48. {streamembed-0.2.0 → streamembed-0.3.0}/NOTICE +0 -0
  49. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/__main__.py +0 -0
  50. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/__init__.py +0 -0
  51. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/config.py +0 -0
  52. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/engine.py +0 -0
  53. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/llm.py +0 -0
  54. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/macs.py +0 -0
  55. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/model.py +0 -0
  56. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/spatial.py +0 -0
  57. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/temporal.py +0 -0
  58. {streamembed-0.2.0 → streamembed-0.3.0}/src/streamembed/engine/vit.py +0 -0
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.5
2
+ Name: streamembed
3
+ Version: 0.3.0
4
+ Summary: Search your own screen history by describing what you saw, from screenshots, on your machine
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: embeddings,on-device,retrieval,screen-history,screenshots
9
+ Classifier: Operating System :: MacOS
10
+ Classifier: Operating System :: Microsoft :: Windows
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: huggingface-hub>=0.30
16
+ Requires-Dist: mss<11,>=9
17
+ Requires-Dist: numpy>=2.2
18
+ Requires-Dist: pillow>=11
19
+ Requires-Dist: pyobjc-framework-quartz>=10; sys_platform == 'darwin'
20
+ Requires-Dist: qwen-vl-utils==0.0.14
21
+ Requires-Dist: safetensors>=0.4
22
+ Requires-Dist: torch==2.8.0
23
+ Requires-Dist: torchvision==0.23.0
24
+ Requires-Dist: transformers==5.17.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8; extra == 'dev'
27
+ Provides-Extra: hnsw
28
+ Requires-Dist: chroma-hnswlib==0.7.6; extra == 'hnsw'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # StreamEmbed
32
+
33
+ Search your own screen history by describing what you saw. StreamEmbed indexes the screenshots you already have and keeps capturing your screen as you work, then finds a past screen from a sentence such as "the flight search page to Denver". Everything runs on your machine.
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ uv venv && source .venv/bin/activate
39
+ uv pip install streamembed
40
+
41
+ # or only the `streamembed` command, in an environment of its own
42
+ uv tool install streamembed
43
+
44
+ # with the "hnsw" index type (Python 3.12)
45
+ uv pip install "streamembed[hnsw]"
46
+ ```
47
+
48
+ Python 3.12 or later. Tested on macOS (Apple silicon), Ubuntu 24.04 (X11; Wayland is not supported) and Windows Server 2025 (x86-64, CPU). The first run downloads the model (about 4 GB). On macOS, allow Screen Recording for your terminal or Python when asked, then run `streamembed start` again. On Windows, the `hnsw` extra needs the Microsoft C++ Build Tools: it has no prebuilt wheel there.
49
+
50
+ ## Quick Start
51
+
52
+ From a terminal:
53
+
54
+ ```bash
55
+ streamembed start --folder ~/Desktop # index the screenshots there, then capture every 5 s, now and after every login
56
+ streamembed search "the flight search page to Denver" # prints the matches and opens a results page
57
+ streamembed status # also: pause, resume, stop
58
+ streamembed config set interval 10 # change a default
59
+ ```
60
+
61
+ `--folder` is the folder your screenshots are saved in: `~/Desktop` on macOS (unless you changed it in the Screenshot app), `~/Pictures/Screenshots` on Windows and Ubuntu. Every image in it and in its subfolders is indexed. macOS protects `~/Desktop`: if the terminal (or, for `start`, the service's Python) has no access to it, indexing stops with a permission error; allow it in System Settings > Privacy & Security > Files and Folders.
62
+
63
+ Or, instead of `streamembed start`, from Python. It cannot write to an index that `streamembed start` is capturing into (stop that first, or use another `index_dir`); `query_index` and `visualize_results` work alongside it.
64
+
65
+ ```python
66
+ import streamembed as se
67
+
68
+ se.build_index_from_directory("~/Desktop") # screenshots you already have
69
+ capture = se.build_index_from_now() # capture the screen every 5 s, in the background
70
+
71
+ results = se.query_index("the flight search page to Denver")
72
+ se.visualize_results(results) # an HTML page with each match and the screens before and after it
73
+ capture.stop()
74
+ ```
75
+
76
+ `streamembed config` lists every setting, its value and where the value comes from. `streamembed COMMAND --help` lists every option of a command.
77
+
78
+ The index type (`flat`, `binary`, `hnsw`, `ivf` or `pq`) is a setting, not an install choice: `streamembed config set index_type pq` switches an existing index without indexing again. Only `hnsw` needs the extra above.
79
+
80
+ Vectors and metadata stay in the index folder (owner-only, unencrypted). Live captures are written to `capture_dir`, by default `captures/` in the index folder; screenshots indexed from a folder are not copied. On macOS, nothing is captured while the screen is locked or a password manager or private browsing window is in front; on Linux and Windows these checks are not implemented, and everything on screen is captured.
81
+
82
+ The full reference (every command and function, the settings, the index folder, the index types and the privacy notes) is `README.md` in the source distribution: under Download files on this page (https://pypi.org/project/streamembed/#files), download `streamembed-VERSION.tar.gz`; after `tar xzf streamembed-VERSION.tar.gz` it is `streamembed-VERSION/README.md`.
83
+
84
+ ## License
85
+
86
+ Apache-2.0. The model weights are downloaded from Hugging Face under their own licenses.
@@ -0,0 +1,56 @@
1
+ # StreamEmbed
2
+
3
+ Search your own screen history by describing what you saw. StreamEmbed indexes the screenshots you already have and keeps capturing your screen as you work, then finds a past screen from a sentence such as "the flight search page to Denver". Everything runs on your machine.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ uv venv && source .venv/bin/activate
9
+ uv pip install streamembed
10
+
11
+ # or only the `streamembed` command, in an environment of its own
12
+ uv tool install streamembed
13
+
14
+ # with the "hnsw" index type (Python 3.12)
15
+ uv pip install "streamembed[hnsw]"
16
+ ```
17
+
18
+ Python 3.12 or later. Tested on macOS (Apple silicon), Ubuntu 24.04 (X11; Wayland is not supported) and Windows Server 2025 (x86-64, CPU). The first run downloads the model (about 4 GB). On macOS, allow Screen Recording for your terminal or Python when asked, then run `streamembed start` again. On Windows, the `hnsw` extra needs the Microsoft C++ Build Tools: it has no prebuilt wheel there.
19
+
20
+ ## Quick Start
21
+
22
+ From a terminal:
23
+
24
+ ```bash
25
+ streamembed start --folder ~/Desktop # index the screenshots there, then capture every 5 s, now and after every login
26
+ streamembed search "the flight search page to Denver" # prints the matches and opens a results page
27
+ streamembed status # also: pause, resume, stop
28
+ streamembed config set interval 10 # change a default
29
+ ```
30
+
31
+ `--folder` is the folder your screenshots are saved in: `~/Desktop` on macOS (unless you changed it in the Screenshot app), `~/Pictures/Screenshots` on Windows and Ubuntu. Every image in it and in its subfolders is indexed. macOS protects `~/Desktop`: if the terminal (or, for `start`, the service's Python) has no access to it, indexing stops with a permission error; allow it in System Settings > Privacy & Security > Files and Folders.
32
+
33
+ Or, instead of `streamembed start`, from Python. It cannot write to an index that `streamembed start` is capturing into (stop that first, or use another `index_dir`); `query_index` and `visualize_results` work alongside it.
34
+
35
+ ```python
36
+ import streamembed as se
37
+
38
+ se.build_index_from_directory("~/Desktop") # screenshots you already have
39
+ capture = se.build_index_from_now() # capture the screen every 5 s, in the background
40
+
41
+ results = se.query_index("the flight search page to Denver")
42
+ se.visualize_results(results) # an HTML page with each match and the screens before and after it
43
+ capture.stop()
44
+ ```
45
+
46
+ `streamembed config` lists every setting, its value and where the value comes from. `streamembed COMMAND --help` lists every option of a command.
47
+
48
+ The index type (`flat`, `binary`, `hnsw`, `ivf` or `pq`) is a setting, not an install choice: `streamembed config set index_type pq` switches an existing index without indexing again. Only `hnsw` needs the extra above.
49
+
50
+ Vectors and metadata stay in the index folder (owner-only, unencrypted). Live captures are written to `capture_dir`, by default `captures/` in the index folder; screenshots indexed from a folder are not copied. On macOS, nothing is captured while the screen is locked or a password manager or private browsing window is in front; on Linux and Windows these checks are not implemented, and everything on screen is captured.
51
+
52
+ The full reference (every command and function, the settings, the index folder, the index types and the privacy notes) is `README.md` in the source distribution: under Download files on this page (https://pypi.org/project/streamembed/#files), download `streamembed-VERSION.tar.gz`; after `tar xzf streamembed-VERSION.tar.gz` it is `streamembed-VERSION/README.md`.
53
+
54
+ ## License
55
+
56
+ Apache-2.0. The model weights are downloaded from Hugging Face under their own licenses.
@@ -0,0 +1,273 @@
1
+ # StreamEmbed
2
+
3
+ Search your own screen history by describing what you saw. StreamEmbed indexes screenshots, from a folder or from your screen as you work, and finds a past screen from a sentence. Everything runs on your machine.
4
+
5
+ It embeds the pixels with Qwen3-VL-Embedding-2B and encodes screenshots as a stream, so that it keeps up on a laptop: blocks that repeat a neighbor are skipped (spatial pruning), and the keys and values of blocks that did not change are reused from the previous frame (temporal reuse).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ uv venv && source .venv/bin/activate
11
+ uv pip install streamembed
12
+
13
+ # or only the `streamembed` command, in an environment of its own
14
+ uv tool install streamembed
15
+
16
+ # with the "hnsw" index type (Python 3.12)
17
+ uv pip install "streamembed[hnsw]"
18
+ ```
19
+
20
+ The first run downloads the model (about 4 GB). On macOS, allow Screen Recording for your terminal or Python when asked, then run `streamembed start` again. On Windows, the `hnsw` extra needs the Microsoft C++ Build Tools: it has no prebuilt wheel there. See Requirements for the tested systems.
21
+
22
+ ## Quick Start
23
+
24
+ From a terminal:
25
+
26
+ ```bash
27
+ streamembed start --folder ~/Desktop # index the screenshots there, then capture every 5 s, now and after every login
28
+ streamembed search "the flight search page to Denver" # prints the matches and opens a results page
29
+ streamembed status # also: pause, resume, stop
30
+ streamembed config set interval 10 # change a default
31
+ ```
32
+
33
+ `--folder` is the folder your screenshots are saved in: `~/Desktop` on macOS (unless you changed it in the Screenshot app), `~/Pictures/Screenshots` on Windows and Ubuntu. Every image in it and in its subfolders is indexed. macOS protects `~/Desktop`: if the terminal (or, for `start`, the service's Python) has no access to it, indexing stops with a permission error; allow it in System Settings > Privacy & Security > Files and Folders.
34
+
35
+ Or, instead of `streamembed start`, from Python. It cannot write to an index that `streamembed start` is capturing into (stop that first, or use another `index_dir`); `query_index` and `visualize_results` work alongside it.
36
+
37
+ ```python
38
+ import streamembed as se
39
+
40
+ se.build_index_from_directory("~/Desktop") # screenshots you already have
41
+ capture = se.build_index_from_now() # capture the screen every 5 s, in the background
42
+
43
+ results = se.query_index("the flight search page to Denver")
44
+ se.visualize_results(results) # an HTML page with each match and the screens before and after it
45
+ capture.stop()
46
+ ```
47
+
48
+ `streamembed config` lists every setting, its value and where the value comes from.
49
+
50
+ The index type (`flat`, `binary`, `hnsw`, `ivf` or `pq`) is a setting, not an install choice: `streamembed config set index_type pq` switches an existing index without indexing again. Only `hnsw` needs the extra above.
51
+
52
+ ## Requirements
53
+
54
+ Python 3.12 or later. Tested on macOS 15 (Apple silicon, GPU), Ubuntu 24.04 under X11 (Xvfb; CPU) and Windows Server 2025 (CPU): installing, indexing a folder, searching, capturing, and the background service (start, pause, resume, stop, restart after a reboot). Not tested: Wayland (not supported), Windows with several monitors, CUDA GPUs. On macOS, capturing the screen needs Screen Recording permission for the app that runs Python; `build_index_from_now` raises `PermissionError` until it is granted. On Windows, capture needs a logged-in desktop session: while the screen is locked, captures fail and are retried.
55
+
56
+ Dependencies are pinned to torch 2.8.0 and transformers 5.17.0: the stream encoder re-implements parts of the Qwen3-VL forward pass against transformers internals, and its outputs were checked for equality with these versions. Install StreamEmbed in its own environment (for example `uv tool`, `pipx`, or a venv) if your project needs other versions.
57
+
58
+ The `hnsw` index type needs the `hnsw` extra (`pip install "streamembed[hnsw]"`), which installs chroma-hnswlib 0.7.6: hnswlib with prebuilt wheels (the `hnswlib` package itself is a source package that needs a C++ compiler). Its wheels cover Python 3.12; on later Python versions it is built from source. It does not use OpenMP and runs in one process with torch (checked on macOS with torch 2.8.0 on MPS). The other types need only numpy.
59
+
60
+ ## Privacy
61
+
62
+ - Vectors and metadata stay in the index folder (owner-only). Live captures are written to `capture_dir` (by default `captures/` in the index folder, also owner-only) as plain image files (WebP by default). If you set `capture_dir` to a folder that a cloud service syncs (iCloud Desktop & Documents, Dropbox, OneDrive), your screen history is uploaded with it.
63
+ - On macOS, capture is skipped when the screen is locked, when the frontmost app is a password manager, and when the frontmost window is a private browsing window. Other windows on screen are not checked; use `capture.pause()` for sensitive work. On Linux and Windows these checks are not implemented yet: everything on screen is captured.
64
+ - While the search page is shown, its browser window is painted gray in the captures, so a search does not find the results of earlier ones. Everything else is captured as usual, including a window over part of the page (macOS). A display with nothing on it but the page is not stored. On Windows and Linux, the window is painted only while the page has focus.
65
+ - Nothing is sent over the network after the model download.
66
+
67
+ ## Reference
68
+
69
+ ### Commands
70
+
71
+ | Command | What it does |
72
+ |---|---|
73
+ | `streamembed start [--folder DIR] [--interval S] [--monitors all\|primary\|1,2] [--keep-unchanged] [--model M] [--index-type T]` | Capture in the background from now and after every login (see below); with `--folder`, index those screenshots first |
74
+ | `streamembed status`, `pause`, `resume`, `stop` | The background capture: its state and number of screens; pause and resume (in every process, in the service's index folder); stop and remove |
75
+ | `streamembed index DIR [--interval S] [--keep-unchanged]` | Index a folder now and print the progress. Ctrl-C stops it; running it again reads only screenshots not read before (also ones added since). The index folder is left out of the scan |
76
+ | `streamembed capture [--interval S] [--monitors ...] [--keep-unchanged] [--model M] [--index-type T]` | Capture in this terminal until Ctrl-C |
77
+ | `streamembed search ["QUESTION"] [--top-k N] [--since DATE] [--until DATE] [--no-open]` | Print the best matches and open the results page. While the background capture runs, the page is served by it (a search box, answers in under a second, no second model); `streamembed search` alone opens that page empty. Otherwise the model loads here (20-60 s) and the page is written to `results.html` |
78
+ | `streamembed config [show \| set KEY VALUE ... \| reset [KEY ...] \| path]` | Show (the default), change or reset the settings, or print where the settings files are. After `set` or `reset`, a line says when `$STREAMEMBED_INDEX` or `$STREAMEMBED_MODELS` overrides the value |
79
+
80
+ Options go after the command: `streamembed search --index-dir DIR "QUESTION"`. Every command except `config` takes `--index-dir`. `streamembed COMMAND --help` lists all the options of a command, and `streamembed --version` prints the version. A mistake in a setting, a path or a date prints one line that starts with `streamembed: error:`; a mistake in an option prints the command's usage and an error naming the option. Both exit with status 2. `python -m streamembed` is the same command.
81
+
82
+ ### Python
83
+
84
+ `examples/main.py` is a complete script.
85
+
86
+ | Function | What it does |
87
+ |---|---|
88
+ | `available_index_types()` | `["flat", "binary", "hnsw", "ivf", "pq"]` |
89
+ | `available_models()` | Model names: those in the model repo, then the built-in base models |
90
+ | `configure(index_dir=None, index_type=None, model=None, models_repo=None, device=None, width=None, capture_dir=None, capture_format=None, capture_width=None)` | Settings for this process only (see Settings), such as `configure(capture_width=0)` to save live captures at the screen's own size |
91
+ | `build_index_from_directory(directory, interval=None, skip_unchanged=None, progress=None) -> dict` | Index screenshots you already have |
92
+ | `build_index_from_now(interval=None, duration=None, block=False, monitors=None, skip_unchanged=None) -> Capture` | Capture the screen in the background |
93
+ | `query_index(query, top_k=None, since=None, until=None) -> Results` | The screens that best match a description; an empty question raises `ValueError` |
94
+ | `visualize_results(results, path=None, open_browser=True, context=None, query=None) -> Path` | Write the results page and open it in the browser; returns the page's path |
95
+ | `get_config()`, `set_config(**values)`, `reset_config(*names)` | The settings (below) |
96
+ | `pause()`, `resume()`, `is_paused()` | Pause capturing into the index, in every process (the background service too) |
97
+
98
+ Arguments left as None come from the settings. Screens that did not change are not stored again: a capture is encoded when more than 10 % of its kept blocks changed since the last stored one, or, when it changed less than that, once `heartbeat` seconds (300 by default) have passed since then.
99
+
100
+ #### Indexing a folder
101
+
102
+ - Every `.jpg`, `.jpeg`, `.png` and `.webp` file in the folder and its subfolders is read.
103
+ - A screenshot's time comes from its file name (macOS screenshot names, Unix times, dates), else its EXIF data, else the file time.
104
+ - Each subfolder, each display number after the time in the name (`_1`, ` (2)`) and each image size is a screen of its own. A screen is its own stream with its own change gate, and screens are indexed one after another, each in time order.
105
+ - Per screen, at most one screenshot every `interval` seconds is used (0: all). Screenshots dated only by their file time are all used, since that time may be the time they were copied.
106
+ - Ctrl-C stops it. Running it again reads only the screenshots not read before, stored or not (`handled.jsonl` records those that were not), and also ones added since, whatever their time. When there is nothing new it returns before the model loads. The folder is recorded by its full path, so `shots` and `/Users/me/shots` are the same folder.
107
+ - The index folder is left out of the scan. Giving the index folder itself, or a folder inside it, raises `ValueError`.
108
+ - The index's write lock is taken while it indexes and released when it returns, so a Python session left open does not keep `streamembed start` from writing.
109
+ - A folder with no screenshots returns zero counts. A missing folder raises `FileNotFoundError`, a file `NotADirectoryError`, and a folder that cannot be read `PermissionError` (on macOS, see Files and Folders in Quick Start). A subfolder that cannot be read is named on stderr and left out.
110
+ - It returns the counts: `found` (files), `skipped` (left out by `interval`), `done` (read in earlier runs), `todo` (read in this run), `captured`, `encoded` (stored), `idle` (unchanged, not stored), `minor` (changed too little to store), `errors` (not readable as images, or not stored) and `stopped`. When it ends, `found` is the sum of `skipped`, `done`, `encoded`, `idle`, `minor` and `errors`. `progress`, if given, is called with these counts after each screenshot.
111
+
112
+ #### Capturing the screen
113
+
114
+ - `monitors`: `"all"` (a display connected meanwhile is captured from then on), `"primary"` or display numbers (1 = primary). Each display is its own stream.
115
+ - At least 0.5 s passes between captures, also with `interval=0`. `duration` stops the capture after that many seconds. The index's write lock is held until the capture ends.
116
+ - A frame that cannot be stored (a full disk, for example) is counted in `stats["errors"]` and printed to stderr, which is `service.log` for the background service.
117
+ - It returns a `Capture`: `stop()`, `pause()`, `resume()`, `wait()` (until it stops, or Ctrl-C), `running`, `stalled`, and `stats` (`captured`, `encoded`, `idle`, `minor`, `skipped`, `errors`).
118
+ - A screen grab that has not returned for 60 s (seen on macOS, outside StreamEmbed) sets `stalled` and is printed to stderr. `wait()` then returns. `stop()` finishes a screenshot being encoded, gives up on a grab that has not returned after 30 s and returns `False`; nothing more is stored from that capture, and `build_index_from_now()` can start a new one. The background service exits in this case, and the service manager starts it again.
119
+ - While the index is paused (`streamembed pause`), capturing and folder indexing wait and say so once on stderr.
120
+
121
+ #### Searching
122
+
123
+ `query_index` returns `Results`, a list of `Result`, best first. It also carries the question (`query`; `text` is the same) and the time window from `since`/`until` (`window`), and a slice of it keeps them:
124
+
125
+ | Field | Type | Content |
126
+ |---|---|---|
127
+ | `id` | int | Row in the index |
128
+ | `score` | float | Cosine similarity |
129
+ | `time` | str | Capture time, local, `YYYY-MM-DD HH:MM:SS` |
130
+ | `ts` | float | The same, in Unix seconds |
131
+ | `path` | str | The image file: the original screenshot for a folder screenshot, the file in `capture_dir` for a live capture |
132
+ | `source` | str or None | The original file of a folder screenshot (the same as `path`); `None` for a live capture |
133
+
134
+ `to_dict()` gives the fields as a dict.
135
+
136
+ - A match within 30 s of a better one from the same screen (the same subfolder and display) is dropped: a screen stays up for a while. Folder screenshots with no time in their file name are never dropped this way.
137
+ - `since` and `until` (Unix seconds, `"YYYY-MM-DD"` or `"YYYY-MM-DD HH:MM"`) limit the search to that time; the question is searched as written. A date alone as `until` includes that day. `since` at or after `until` raises `ValueError`.
138
+ - An empty index, or a time window with no screens in it, returns `[]` without loading the model.
139
+
140
+ #### The results page
141
+
142
+ `visualize_results` writes an HTML page, `results.html` in the index folder unless `path` is given.
143
+
144
+ The background capture also serves this page with a search box, at `http://127.0.0.1:<port>/` with a token that `streamembed search` puts in the link (the port and token are in `web.json` in the index folder, owner-only). It answers only on this machine, only with the token, and serves images by index row, never by path. The page's language (English, 한국어, 中文) is chosen at the top right, or with `?lang=ko` in the link, and kept in the browser; dates and times follow it.
145
+
146
+ - It shows each screenshot from where it is: a folder screenshot from its original file, a live capture from `capture_dir`. Match thumbnails are made in `thumbs/` in the index folder. The page needs no server and works on this machine while those files are there; a moved or deleted original shows its path instead of an image.
147
+ - Its heading is `query` if given, else the question and the time window the results came with. A list you built yourself has no heading unless you give `query`.
148
+ - It shows the best 10, with Show more for the next 10. A card gives the day and time of its screen (the match score shows on hover). A match within 5 minutes of a better one from the same screen is left out: only the best of them is shown.
149
+ - A date chip (the 7 most recent days with results; the others behind a toggle) keeps the results from that day; `--since`/`--until` search a range. Pass more results (`query_index(..., top_k=100)`, as `streamembed search` does) to have more to pick from.
150
+ - A card opens full size, with up to `context` frames of the same screen before and after it in time order. The match is marked with a dot and its score; a gap in the strip marks a pause, a new day, or frames left out. Arrow keys, or a swipe on a phone, step through the frames. Full size opens the image file.
151
+ - Cards open from the keyboard (Tab, then Enter).
152
+
153
+ ### Settings
154
+
155
+ Every setting has a default in `defaults.toml` in the package.
156
+
157
+ - `streamembed config set KEY VALUE` (or `se.set_config(KEY=VALUE)`) changes a setting for good. It is kept in your own file (`streamembed config path` shows where), and a value that does not fit the setting is refused.
158
+ - `streamembed config reset KEY` goes back to the default; `streamembed config reset` resets every setting.
159
+ - `streamembed config` lists every setting and where its value comes from.
160
+ - The background capture reads the settings when it starts: run `streamembed start` again to apply a change. When `$STREAMEMBED_CONFIG` names your file, `streamembed start` passes that path on to the service.
161
+
162
+ A value given to a function or a command takes precedence for that call. Then come `configure()` (for its process), `$STREAMEMBED_INDEX` / `$STREAMEMBED_MODELS`, your file, and the defaults, in that order.
163
+
164
+ | Setting | Default | What it does |
165
+ |---|---|---|
166
+ | `index_dir` | `~/screenshot_index` | The index folder |
167
+ | `capture_dir` | `""` | Where live captures are written, as a full path (`~` is allowed); empty: `captures/` in the index folder. It can be your screenshots folder: indexing it later leaves the captures out. Screenshots indexed from a folder are never copied; the index keeps only vectors and each image's time and path |
168
+ | `capture_format` | `webp` | `webp` or `jpeg`. WebP is about half the size at the same quality (a 1280-wide screenshot: about 80 KB, JPEG 150-200 KB) |
169
+ | `capture_width` | 1280 | Width of a saved capture in pixels; 0 keeps the screen's own size (sharper when zoomed in, about 3.5 times larger). The model always sees the capture fitted to `width` |
170
+ | `capture_max_gb` | 20 | Live captures are kept under this many GB (images; 0: no limit). Past it, the oldest are removed with their screens in the index until they take 90 % of it; the capture checks when it starts and every hour. Screenshots indexed from a folder are never removed |
171
+ | `capture_keep_days` | 0 | Live captures older than this many days are removed with their screens in the index (0: kept however old). Checked with `capture_max_gb` |
172
+ | `index_type` | `flat` | `flat`, `binary`, `hnsw`, `ivf` or `pq` (see Index types) |
173
+ | `model`, `models_repo`, `device` | `qwen3-vl-2b`, `dayoon/streamembed`, `auto` | The model, where its LoRAs come from, and the device (`auto`, `mps`, `cuda`, `cuda:N`, `cpu`) |
174
+ | `width` | 1280 | Wider screenshots are shrunk to it; narrower ones are left as they are |
175
+ | `interval` | 5 | Seconds between captures, 0 to 86,400; live capture uses at least 0.5. For a folder, at most one screenshot per screen this often (0: all) |
176
+ | `monitors` | `all` | `all`, `primary`, or display numbers such as `[1, 2]` |
177
+ | `skip_unchanged` | true | Skip screens that did not change |
178
+ | `heartbeat` | 300 | A screen that changed a little (under 10 % of its blocks, such as a few typed characters) is stored at most once per this many seconds; one that changed more is stored at once |
179
+ | `exclude_apps`, `exclude_titles` | password managers; private browsing windows | Nothing is captured while the frontmost app or window title contains one of these (macOS). A value replaces the whole list, and `set` names the defaults it drops. To add an app and keep the defaults, list them all: `streamembed config set exclude_apps "1password,bitwarden,dashlane,lastpass,keychain access,keepass,signal"` |
180
+ | `top_k` | 10 | Results per question |
181
+ | `page_results`, `context` | 100, 15 | Results put on the results page (to pick dates among); frames shown before and after each |
182
+
183
+ ### Capturing in the background
184
+
185
+ `build_index_from_now` captures while its Python process runs: `examples/main.py` keeps capturing until Ctrl-C or until the terminal closes. To keep capturing with no terminal open and after every login, install it as a service. It uses the system's own service manager:
186
+
187
+ ```python
188
+ se.install_service(interval=5, monitors="all") # starts now and at every login; restarted if it stops with an error
189
+ se.service_status() # {"installed": True, "running": True, "pid": ..., "log": ".../service.log", ...}
190
+ se.uninstall_service() # stops it and removes it; the index stays
191
+ ```
192
+
193
+ | System | Service | Notes |
194
+ |---|---|---|
195
+ | macOS | launchd user agent `org.streamembed.capture` (`~/Library/LaunchAgents/`) | The first start asks for Screen Recording permission for this Python (System Settings > Privacy & Security > Screen Recording); allow it, then run `streamembed start` (or `install_service()`) again. With `--folder ~/Desktop`, this Python also needs access to the Desktop folder (Files and Folders); without it, `service.log` says so and the service captures without the folder |
196
+ | Linux | systemd user service `streamembed-capture.service` (`~/.config/systemd/user/`) | X11 only. Install from a terminal in your desktop session: the service keeps that session's `DISPLAY` |
197
+ | Windows | Task Scheduler task `StreamEmbedCapture`, at logon, run with `pythonw` (no console window) | Stopping it ends the process at once; the index drops a half-written row when it is next opened |
198
+
199
+ | Function | What it does |
200
+ |---|---|
201
+ | `install_service(interval=None, monitors=None, skip_unchanged=None, index_dir=None, index_type=None, model=None, models_repo=None, device=None, width=None, directory=None)` | Run `build_index_from_now` as a service (`streamembed start` does this); with `directory` (it must exist), index those screenshots first. Settings left out are read from the settings when the service starts. Installing again replaces it |
202
+ | `service_status()` | Whether it is installed, running and paused, its pid, its index folder, its log file (`service.log` in the index folder) and its command line |
203
+ | `uninstall_service()` | Stop it and remove it |
204
+
205
+ One process writes an index at a time. While the service runs, other processes open its index read-only: `query_index` and `visualize_results` work and see newly captured screens, and `build_index_*` on that folder raises until the service is stopped. The other way round, while a Python session is indexing or capturing into the folder, the service writes a line saying so to `service.log`, and the service manager starts it again a minute later. A `directory` that is the index folder or inside it is refused before the service is installed.
206
+
207
+ ### The index folder
208
+
209
+ | File | Content |
210
+ |---|---|
211
+ | `index.json` | The encoder name and the vector size; the index refuses vectors from another encoder |
212
+ | `frames.jsonl` | One line per stored screen: its time (`ts`) and the path of its image, as `source` for a folder screenshot and as `path` for a live capture in `capture_dir` (relative when it is inside the index folder) |
213
+ | `vectors.f16` | One fp16 vector (2048-d for 2B, 4096-d for 8B) per line of `frames.jsonl` |
214
+ | `captures/YYYY-MM-DD/` | Live captures (unless `capture_dir` puts them elsewhere), in `capture_format` at `capture_width`, named `<ms>.webp` (primary display) and `<ms>_1.webp`, `<ms>_2.webp` (other displays: display 2, as in `--monitors 1,2`, is stored as `_1`, display 3 as `_2`), with `-<n>` added when the name is taken. Screenshots indexed from a folder are not copied here; the results page shows the originals, so moving or deleting one leaves its result without an image |
215
+ | `paused` | Present while capture is paused |
216
+ | `seen.jsonl` | When an unchanged screen was still on screen |
217
+ | `handled.jsonl` | Folder screenshots that were read but not stored (unchanged, changed too little, or not readable), so that indexing the folder again leaves them out |
218
+ | `writer.lock` | Held by the process that writes; others read |
219
+ | `query.sock` (`query.port` on Windows) | While the background capture runs: where searches from other processes send their question (owner-only; a token on Windows) |
220
+ | `web.json` | While the background capture runs: the address and token of its search page |
221
+ | `service.log` | The background service's log |
222
+ | `codes.bin`, `mu.npy` | `binary` only |
223
+ | `hnsw.bin`, `hnsw.json` | `hnsw` only: the graph with its 512-d float32 vectors, and its parameters |
224
+ | `ivf.json`, `ivf_centroids.npy`, `ivf_codes.bin` | `ivf` only: training size, list centroids, the list of each frame (4 B) |
225
+ | `pq.json`, `pq_centroids.npy`, `pq_codebooks.npy`, `pq_codes.bin` | `pq` only: training size, list centroids, PQ codebooks, the list and the 64 PQ codes of each frame (68 B) |
226
+ | `thumbs/`, `results.html` | Made by `visualize_results` |
227
+
228
+ A process takes `writer.lock` when it first writes (indexing or capturing), not when it only searches, and releases it when the indexing or the capture ends. A line cut short by a crash is left out when the folder is next opened, and a vector written just before a crash without its line is dropped. If `vectors.f16` holds more than one vector beyond the lines of `frames.jsonl` (an older `frames.jsonl` restored, for example), the extra vectors are moved to `vectors.f16.orphan-<time>` instead, and stderr says so.
229
+
230
+ ### Index types
231
+
232
+ | Type | Search |
233
+ |---|---|
234
+ | `flat` | Exact inner product over every stored vector (fp16, 4 KB per frame) |
235
+ | `binary` | Exact up to 1,000 frames. Beyond that, Hamming top 1,000 over 1-bit codes of the first 512 dimensions (64 B per frame, kept in memory), then exact re-rank. About 0.13 GB of memory per year of 5-s captures |
236
+ | `hnsw` | Exact up to 10,000 frames. Beyond that, an HNSW graph (hnswlib, M = 32, efConstruction = 500) over the first 512 dimensions; a query takes the graph's top 800 (efSearch) and re-ranks them exactly. About 2.3 KB per frame in memory and on disk. Needs `pip install "streamembed[hnsw]"` |
237
+ | `ivf` | Exact up to 10,000 frames. Beyond that, the frames are split into round(sqrt(n)) lists by spherical k-means (10 iterations, fixed seed, on up to 50,000 evenly spaced frames); a query scores every frame of its 32 nearest lists exactly. 4 B per frame plus the centroids |
238
+ | `pq` | IVF-PQ. Exact up to 10,000 frames. Beyond that, the same kind of lists, plus a product-quantized code of the first 512 dimensions per frame (64 sub-quantizers x 8 bits, trained on up to 20,000 frames); a query ranks the frames of its 64 nearest lists by their codes and re-ranks the top 2,000 exactly. 68 B per frame plus the centroids and codebooks |
239
+
240
+ Every type returns exact cosines: candidates are re-scored over `vectors.f16`. New frames are searchable as soon as they are added: `hnsw` inserts them into the graph, `ivf` and `pq` put them in their nearest list. `ivf` and `pq` train when the index passes 10,000 frames and train again from scratch (new lists and codebooks, every frame re-encoded, a few seconds) each time the index has grown 4x since the last training. The `hnsw` graph is never rebuilt; it is saved every 1,000 new frames and when the index is closed. If a structure lags the vectors (a crash, or frames added while the folder was open with another type), the missing frames are added when the index is opened. A process that opens the folder read-only uses these files but never writes them; if they are missing or behind, it builds or catches up in memory. Defaults are constants in `src/streamembed/ann.py`.
241
+
242
+ Measured on an M2 Pro (16 GB) with 200,000 2048-d frames (132,221 stored Qwen3-VL-Embedding-2B frame vectors plus noisy copies of them) and 200 stored text-query vectors, top 10 with the 30-s dedupe: the share of `flat`'s top 10 that each type also returns is 0.93 for `binary`, 0.95 for `hnsw`, 0.97 for `ivf` and 0.96 for `pq`; median query time is 295 ms for `flat`, 8 ms for `binary`, 13 ms for `hnsw`, 53 ms for `ivf` and 22 ms for `pq`. Building from `vectors.f16` takes 1 s (`binary`), 61 s (`hnsw`), 5 s (`ivf`) and 19 s (`pq`). At 50,000 frames recall is 0.91, 0.99, 0.95 and 0.97.
243
+
244
+ An index folder can be reopened with any other type. It also records the encoder, and refuses vectors from a different one.
245
+
246
+ ### Models
247
+
248
+ A model is a base model from its own Hugging Face repository, pinned to a commit, plus two LoRAs from the StreamEmbed model repository: one for screenshots (a consistency adapter that keeps pruned, streamed frames close to full frames) and one for questions. Only the LoRAs live in the StreamEmbed repository; its `models.json` names each model's base repository, commit and files.
249
+
250
+ | Model | What it is |
251
+ |---|---|
252
+ | `qwen3-vl-2b` (default) | Qwen3-VL-Embedding-2B with the StreamEmbed LoRAs |
253
+ | `qwen3-vl-8b` | Qwen3-VL-Embedding-8B with the StreamEmbed LoRAs; needs a GPU with about 20 GB |
254
+ | `qwen3-vl-2b-base` | Qwen3-VL-Embedding-2B without LoRAs; built in, needs no model repo |
255
+
256
+ The model repository also holds LoRAs for SigLIP2 So400m, SigLIP2 Base and VultronRetrieverFlash 0.8B. `available_models()` lists them, but the stream encoder supports Qwen3-VL models only: `set_config` and `streamembed config set` refuse them, and `configure(model=...)` with one raises `NotImplementedError` when StreamEmbed first encodes.
257
+
258
+ `configure(models_repo=...)` or `$STREAMEMBED_MODELS` points to another Hugging Face repository or a local folder with the same layout. An index records its model and refuses vectors from another one.
259
+
260
+ The first run of `qwen3-vl-2b` downloads the base model (about 4 GB) and the LoRAs (70 MB each); after that nothing is downloaded. Encoding needs about 8 GB of memory and takes 0.7 to 1.3 s per 1280-px frame on an M2 Pro GPU that nothing else uses; while another process (the background capture, for example) encodes on the same GPU, expect about twice that. Loading the model takes about 20 to 60 s (stderr says when it loads, and says it downloads only when the model is not cached yet), so `build_index_from_now()`, `streamembed index` and the first search in a process wait that long before they start. The change gate skips screens that did not change.
261
+
262
+ ## Development
263
+
264
+ ```bash
265
+ uv venv && uv pip install -e ".[dev,hnsw]"
266
+ .venv/bin/python -m pytest # API tests with a stand-in encoder; no model needed (hnsw tests are skipped without the extra)
267
+ ```
268
+
269
+ `src/streamembed/engine/` is the stream encoder. It keeps older names in places: Token Pruning is spatial pruning, KV Reuse is temporal reuse.
270
+
271
+ ## License
272
+
273
+ Apache-2.0. See `LICENSE` and `NOTICE`; the model weights are downloaded under their own license.
@@ -0,0 +1,31 @@
1
+ """Index the screenshots you already have, keep capturing the screen, and search. Ctrl-C stops capturing.
2
+
3
+ Settings left out here come from `streamembed config` (defaults: every 5 s, every display, changed screens only).
4
+ To keep capturing with no terminal open, use `streamembed start` instead. This script is an alternative to it: while
5
+ `streamembed start` captures into the same index, it cannot write there (stop that first, or use another index_dir).
6
+ """
7
+ import streamembed as se
8
+
9
+ SCREENSHOT_FOLDER = "~/Desktop" # where your screenshots are saved: ~/Desktop on macOS, ~/Pictures/Screenshots on Windows and Ubuntu
10
+ INDEX_TYPE = "flat" # one of se.available_index_types(); can be changed later without indexing again
11
+ QUESTION = "the flight search page with fares to Denver"
12
+
13
+ se.configure(index_type=INDEX_TYPE)
14
+
15
+ # Screenshots you already have. Ctrl-C stops the script here; run it again and it continues where it stopped. A folder with no
16
+ # screenshots gives zero counts; on macOS, the terminal needs access to ~/Desktop (System Settings > Privacy & Security > Files and
17
+ # Folders).
18
+ stats = se.build_index_from_directory(SCREENSHOT_FOLDER)
19
+ print(stats)
20
+ if stats["stopped"]:
21
+ raise SystemExit("Stopped; run it again to continue.")
22
+
23
+ # From now on, in the background
24
+ capture = se.build_index_from_now()
25
+
26
+ # Search: print the best matches, and open a page with the best 100 to browse by date
27
+ for r in se.query_index(QUESTION, top_k=5):
28
+ print(f"{r.score:.3f} {r.time} {r.path}")
29
+ se.visualize_results(se.query_index(QUESTION, top_k=100))
30
+
31
+ capture.wait() # keep capturing until Ctrl-C
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "streamembed"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Search your own screen history by describing what you saw, from screenshots, on your machine"
5
5
  readme = "PYPI.md"
6
6
  license = "Apache-2.0"
@@ -11,10 +11,11 @@ classifiers = [
11
11
  "Programming Language :: Python :: 3",
12
12
  "Operating System :: MacOS",
13
13
  "Operating System :: POSIX :: Linux",
14
+ "Operating System :: Microsoft :: Windows",
14
15
  "Topic :: Scientific/Engineering :: Information Analysis",
15
16
  ]
16
17
  # The engine re-implements parts of the Qwen3-VL forward against transformers internals, so torch and transformers stay pinned
17
- # to the versions the paper's timing and equivalence runs used.
18
+ # to the versions its outputs were checked for equality with.
18
19
  dependencies = [
19
20
  "torch==2.8.0",
20
21
  "torchvision==0.23.0",
@@ -24,7 +25,7 @@ dependencies = [
24
25
  "safetensors>=0.4",
25
26
  "numpy>=2.2",
26
27
  "pillow>=11",
27
- "mss>=9",
28
+ "mss>=9,<11", # mss.MSS from 10.2, mss.mss before (capture._grabber)
28
29
  "pyobjc-framework-Quartz>=10; sys_platform == 'darwin'",
29
30
  ]
30
31
 
@@ -1,10 +1,10 @@
1
1
  """StreamEmbed: search your own screen history by describing what you saw. Everything runs on your machine."""
2
- from .api import (Capture, Result, available_index_types, available_models, build_index_from_directory, build_index_from_now, configure, is_paused,
2
+ from .api import (Capture, Result, Results, available_index_types, available_models, build_index_from_directory, build_index_from_now, configure, is_paused,
3
3
  pause, query_index, resume, visualize_results)
4
4
  from .config import get_config, reset_config, set_config
5
5
  from .service import install_service, service_status, uninstall_service
6
6
 
7
- __version__ = "0.2.0"
8
- __all__ = ["Capture", "Result", "available_index_types", "available_models", "build_index_from_directory", "build_index_from_now", "configure", "query_index",
7
+ __version__ = "0.3.0"
8
+ __all__ = ["Capture", "Result", "Results", "available_index_types", "available_models", "build_index_from_directory", "build_index_from_now", "configure", "query_index",
9
9
  "visualize_results", "install_service", "service_status", "uninstall_service", "pause", "resume", "is_paused",
10
10
  "get_config", "set_config", "reset_config"]
@@ -72,7 +72,7 @@ def _replace(path: Path, write) -> None:
72
72
 
73
73
  def _read_json(path: Path):
74
74
  try:
75
- return json.loads(path.read_text())
75
+ return json.loads(path.read_text(encoding="utf-8"))
76
76
  except (OSError, ValueError):
77
77
  return None
78
78