streamembed 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamembed-0.1.0/.gitignore +8 -0
- streamembed-0.1.0/.hgignore +17 -0
- streamembed-0.1.0/LICENSE +201 -0
- streamembed-0.1.0/NOTICE +11 -0
- streamembed-0.1.0/PKG-INFO +122 -0
- streamembed-0.1.0/README.md +95 -0
- streamembed-0.1.0/examples/main.py +21 -0
- streamembed-0.1.0/pyproject.toml +45 -0
- streamembed-0.1.0/src/streamembed/__init__.py +7 -0
- streamembed-0.1.0/src/streamembed/api.py +205 -0
- streamembed-0.1.0/src/streamembed/capture.py +88 -0
- streamembed-0.1.0/src/streamembed/encoder.py +108 -0
- streamembed-0.1.0/src/streamembed/engine/__init__.py +1 -0
- streamembed-0.1.0/src/streamembed/engine/config.py +82 -0
- streamembed-0.1.0/src/streamembed/engine/engine.py +90 -0
- streamembed-0.1.0/src/streamembed/engine/llm.py +170 -0
- streamembed-0.1.0/src/streamembed/engine/macs.py +46 -0
- streamembed-0.1.0/src/streamembed/engine/model.py +254 -0
- streamembed-0.1.0/src/streamembed/engine/qwen_embedder.py +106 -0
- streamembed-0.1.0/src/streamembed/engine/spatial.py +126 -0
- streamembed-0.1.0/src/streamembed/engine/temporal.py +108 -0
- streamembed-0.1.0/src/streamembed/engine/vit.py +86 -0
- streamembed-0.1.0/src/streamembed/gate.py +102 -0
- streamembed-0.1.0/src/streamembed/index.py +138 -0
- streamembed-0.1.0/src/streamembed/models.py +90 -0
- streamembed-0.1.0/src/streamembed/static/results.html +148 -0
- streamembed-0.1.0/src/streamembed/visualize.py +39 -0
- streamembed-0.1.0/tests/test_api.py +145 -0
- streamembed-0.1.0/tests/test_models.py +53 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Use shell-style glob syntax
|
|
2
|
+
syntax: glob
|
|
3
|
+
|
|
4
|
+
# Compiled Python files
|
|
5
|
+
*.pyc
|
|
6
|
+
|
|
7
|
+
# Folder view configuration files
|
|
8
|
+
.DS_Store
|
|
9
|
+
Desktop.ini
|
|
10
|
+
|
|
11
|
+
# Thumbnail cache files
|
|
12
|
+
._*
|
|
13
|
+
Thumbs.db
|
|
14
|
+
|
|
15
|
+
# Files that might appear on external disks
|
|
16
|
+
.Spotlight-V100
|
|
17
|
+
.Trashes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
streamembed-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
StreamEmbed
|
|
2
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
3
|
+
|
|
4
|
+
This product includes software derived from the following projects, also licensed under the Apache License, Version 2.0:
|
|
5
|
+
|
|
6
|
+
- Qwen3-VL-Embedding reference implementation (qwen3_vl_embedding.py), Qwen Team, Alibaba Cloud.
|
|
7
|
+
src/streamembed/engine/qwen_embedder.py is a trimmed copy.
|
|
8
|
+
- Hugging Face Transformers, Qwen3-VL model code, The Hugging Face team and the Qwen Team.
|
|
9
|
+
src/streamembed/engine/ (vit.py, llm.py, model.py) re-implements parts of the Qwen3-VL forward pass against it.
|
|
10
|
+
|
|
11
|
+
The model weights (Qwen/Qwen3-VL-Embedding-2B) are not included; they are downloaded from Hugging Face on first use under their own license.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: streamembed
|
|
3
|
+
Version: 0.1.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 :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: huggingface-hub>=0.30
|
|
15
|
+
Requires-Dist: mss>=9
|
|
16
|
+
Requires-Dist: numpy>=2.2
|
|
17
|
+
Requires-Dist: pillow>=11
|
|
18
|
+
Requires-Dist: pyobjc-framework-quartz>=10; sys_platform == 'darwin'
|
|
19
|
+
Requires-Dist: qwen-vl-utils==0.0.14
|
|
20
|
+
Requires-Dist: safetensors>=0.4
|
|
21
|
+
Requires-Dist: torch==2.8.0
|
|
22
|
+
Requires-Dist: torchvision==0.23.0
|
|
23
|
+
Requires-Dist: transformers==5.17.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# StreamEmbed
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
It embeds the pixels with Qwen3-VL-Embedding-2B, and encodes screenshots as a stream so that this keeps up on a laptop: blocks that repeat a neighbor are skipped, and the keys and values of blocks that did not change are reused from the previous frame.
|
|
33
|
+
|
|
34
|
+
## Use
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import streamembed as se
|
|
38
|
+
|
|
39
|
+
se.configure(index_type="flat") # optional; see below
|
|
40
|
+
se.build_index_from_directory("screenshots") # a folder of .png / .jpg / .webp, searched recursively
|
|
41
|
+
capture = se.build_index_from_now(interval=10) # capture the screen every 10 s, in the background
|
|
42
|
+
|
|
43
|
+
results = se.query_index("the flight search page with fares to Denver", top_k=10)
|
|
44
|
+
se.visualize_results(results) # writes an HTML page and opens it
|
|
45
|
+
|
|
46
|
+
capture.stop()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`examples/main.py` is a complete script.
|
|
50
|
+
|
|
51
|
+
| Function | What it does |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `available_index_types()` | `["flat", "binary"]` |
|
|
54
|
+
| `available_models()` | Model names: those in the model repo, then the built-in base models |
|
|
55
|
+
| `configure(index_dir, index_type, model, models_repo, device, width)` | Where the index lives (default `./streamembed_index`), the index type and the model. Optional |
|
|
56
|
+
| `build_index_from_directory(directory, order="mtime")` | Index a folder as one stream. `order="mtime"` uses each file's time as its capture time; `order="name"` sorts by path |
|
|
57
|
+
| `build_index_from_now(interval, duration=None, block=False)` | Capture the primary display every `interval` seconds, in the background. Returns a `Capture` with `stop()`, `pause()`, `resume()`, `wait()`, `stats` |
|
|
58
|
+
| `query_index(query, top_k)` | `Result`s with score, time, app, window title and the stored image path. A match within 30 s of a better one is dropped |
|
|
59
|
+
| `visualize_results(results)` | A self-contained HTML page. Each result opens full size with the frames before and after it; arrow keys step through time |
|
|
60
|
+
|
|
61
|
+
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 30 s later if anything changed (the paper's change gate).
|
|
62
|
+
|
|
63
|
+
### The index folder
|
|
64
|
+
|
|
65
|
+
| File | Content |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `frames.jsonl` | One line per stored screen: time, image path, app, window title |
|
|
68
|
+
| `vectors.f16` | One 2048-d fp16 vector per line of `frames.jsonl` |
|
|
69
|
+
| `images/` | The stored screenshots, 1280 px wide |
|
|
70
|
+
| `seen.jsonl` | When an unchanged screen was still on screen |
|
|
71
|
+
| `codes.bin`, `mu.npy` | `binary` only |
|
|
72
|
+
| `thumbs/`, `results.html` | Made by `visualize_results` |
|
|
73
|
+
|
|
74
|
+
### Index types
|
|
75
|
+
|
|
76
|
+
| Type | Search |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `flat` | Exact inner product over every stored vector (fp16, 4 KB per frame) |
|
|
79
|
+
| `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 |
|
|
80
|
+
|
|
81
|
+
An index folder can be reopened with the other type. It also records the encoder, and refuses vectors from a different one.
|
|
82
|
+
|
|
83
|
+
### Models
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
| Model | What it is |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `qwen3-vl-2b` (default) | Qwen3-VL-Embedding-2B with the StreamEmbed LoRAs |
|
|
90
|
+
| `qwen3-vl-8b` | Qwen3-VL-Embedding-8B with the StreamEmbed LoRAs; needs a GPU with about 20 GB |
|
|
91
|
+
| `qwen3-vl-2b-base` | Qwen3-VL-Embedding-2B without LoRAs; built in, needs no model repo |
|
|
92
|
+
|
|
93
|
+
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, so selecting one raises `NotImplementedError` when StreamEmbed first encodes.
|
|
94
|
+
|
|
95
|
+
`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.
|
|
96
|
+
|
|
97
|
+
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 frame on an M2 Pro GPU; the change gate skips screens that did not change.
|
|
98
|
+
|
|
99
|
+
## Requirements
|
|
100
|
+
|
|
101
|
+
Python 3.12 or later on macOS (Apple silicon, tested) or Linux under X11 (capture not yet tested). 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.
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
## Privacy
|
|
106
|
+
|
|
107
|
+
- Screenshots, vectors and metadata stay in the index folder (owner-only). Screenshots are stored unencrypted.
|
|
108
|
+
- 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.
|
|
109
|
+
- Nothing is sent over the network after the model download.
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
uv venv && uv pip install -e ".[dev]"
|
|
115
|
+
.venv/bin/python -m pytest # API tests with a stand-in encoder; no model needed
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`src/streamembed/engine/` is the stream encoder from the paper's code and keeps its names: Token Pruning is spatial pruning, KV Reuse is temporal reuse.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
Apache-2.0. See `LICENSE` and `NOTICE`; the model weights are downloaded under their own license.
|
|
@@ -0,0 +1,95 @@
|
|
|
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 this keeps up on a laptop: blocks that repeat a neighbor are skipped, and the keys and values of blocks that did not change are reused from the previous frame.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import streamembed as se
|
|
11
|
+
|
|
12
|
+
se.configure(index_type="flat") # optional; see below
|
|
13
|
+
se.build_index_from_directory("screenshots") # a folder of .png / .jpg / .webp, searched recursively
|
|
14
|
+
capture = se.build_index_from_now(interval=10) # capture the screen every 10 s, in the background
|
|
15
|
+
|
|
16
|
+
results = se.query_index("the flight search page with fares to Denver", top_k=10)
|
|
17
|
+
se.visualize_results(results) # writes an HTML page and opens it
|
|
18
|
+
|
|
19
|
+
capture.stop()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`examples/main.py` is a complete script.
|
|
23
|
+
|
|
24
|
+
| Function | What it does |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `available_index_types()` | `["flat", "binary"]` |
|
|
27
|
+
| `available_models()` | Model names: those in the model repo, then the built-in base models |
|
|
28
|
+
| `configure(index_dir, index_type, model, models_repo, device, width)` | Where the index lives (default `./streamembed_index`), the index type and the model. Optional |
|
|
29
|
+
| `build_index_from_directory(directory, order="mtime")` | Index a folder as one stream. `order="mtime"` uses each file's time as its capture time; `order="name"` sorts by path |
|
|
30
|
+
| `build_index_from_now(interval, duration=None, block=False)` | Capture the primary display every `interval` seconds, in the background. Returns a `Capture` with `stop()`, `pause()`, `resume()`, `wait()`, `stats` |
|
|
31
|
+
| `query_index(query, top_k)` | `Result`s with score, time, app, window title and the stored image path. A match within 30 s of a better one is dropped |
|
|
32
|
+
| `visualize_results(results)` | A self-contained HTML page. Each result opens full size with the frames before and after it; arrow keys step through time |
|
|
33
|
+
|
|
34
|
+
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 30 s later if anything changed (the paper's change gate).
|
|
35
|
+
|
|
36
|
+
### The index folder
|
|
37
|
+
|
|
38
|
+
| File | Content |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `frames.jsonl` | One line per stored screen: time, image path, app, window title |
|
|
41
|
+
| `vectors.f16` | One 2048-d fp16 vector per line of `frames.jsonl` |
|
|
42
|
+
| `images/` | The stored screenshots, 1280 px wide |
|
|
43
|
+
| `seen.jsonl` | When an unchanged screen was still on screen |
|
|
44
|
+
| `codes.bin`, `mu.npy` | `binary` only |
|
|
45
|
+
| `thumbs/`, `results.html` | Made by `visualize_results` |
|
|
46
|
+
|
|
47
|
+
### Index types
|
|
48
|
+
|
|
49
|
+
| Type | Search |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `flat` | Exact inner product over every stored vector (fp16, 4 KB per frame) |
|
|
52
|
+
| `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 |
|
|
53
|
+
|
|
54
|
+
An index folder can be reopened with the other type. It also records the encoder, and refuses vectors from a different one.
|
|
55
|
+
|
|
56
|
+
### Models
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
| Model | What it is |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `qwen3-vl-2b` (default) | Qwen3-VL-Embedding-2B with the StreamEmbed LoRAs |
|
|
63
|
+
| `qwen3-vl-8b` | Qwen3-VL-Embedding-8B with the StreamEmbed LoRAs; needs a GPU with about 20 GB |
|
|
64
|
+
| `qwen3-vl-2b-base` | Qwen3-VL-Embedding-2B without LoRAs; built in, needs no model repo |
|
|
65
|
+
|
|
66
|
+
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, so selecting one raises `NotImplementedError` when StreamEmbed first encodes.
|
|
67
|
+
|
|
68
|
+
`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.
|
|
69
|
+
|
|
70
|
+
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 frame on an M2 Pro GPU; the change gate skips screens that did not change.
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
Python 3.12 or later on macOS (Apple silicon, tested) or Linux under X11 (capture not yet tested). 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.
|
|
75
|
+
|
|
76
|
+
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.
|
|
77
|
+
|
|
78
|
+
## Privacy
|
|
79
|
+
|
|
80
|
+
- Screenshots, vectors and metadata stay in the index folder (owner-only). Screenshots are stored unencrypted.
|
|
81
|
+
- 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.
|
|
82
|
+
- Nothing is sent over the network after the model download.
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
uv venv && uv pip install -e ".[dev]"
|
|
88
|
+
.venv/bin/python -m pytest # API tests with a stand-in encoder; no model needed
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`src/streamembed/engine/` is the stream encoder from the paper's code and keeps its names: Token Pruning is spatial pruning, KV Reuse is temporal reuse.
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
Apache-2.0. See `LICENSE` and `NOTICE`; the model weights are downloaded under their own license.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import streamembed as se
|
|
2
|
+
|
|
3
|
+
# Global variables
|
|
4
|
+
SCREENSHOT_FOLDER = "screenshots"
|
|
5
|
+
SCREENSHOT_INTERVAL = 10 # seconds
|
|
6
|
+
INDEX_TYPE = "flat"
|
|
7
|
+
|
|
8
|
+
# Check index type
|
|
9
|
+
if INDEX_TYPE not in se.available_index_types():
|
|
10
|
+
raise ValueError(f"Invalid index type: {INDEX_TYPE} not in {se.available_index_types()}")
|
|
11
|
+
se.configure(index_type=INDEX_TYPE)
|
|
12
|
+
|
|
13
|
+
# Build index from an existing screenshot folder and take screenshots every 10 seconds
|
|
14
|
+
se.build_index_from_directory(directory=SCREENSHOT_FOLDER)
|
|
15
|
+
capture = se.build_index_from_now(interval=SCREENSHOT_INTERVAL) # keeps capturing in the background
|
|
16
|
+
|
|
17
|
+
# Query the index
|
|
18
|
+
results = se.query_index(query="the flight search page with fares to Denver", top_k=10)
|
|
19
|
+
se.visualize_results(results)
|
|
20
|
+
|
|
21
|
+
capture.wait() # keep capturing until Ctrl-C
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "streamembed"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Search your own screen history by describing what you saw, from screenshots, on your machine"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
keywords = ["screen-history", "screenshots", "embeddings", "retrieval", "on-device"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Operating System :: MacOS",
|
|
13
|
+
"Operating System :: POSIX :: Linux",
|
|
14
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
15
|
+
]
|
|
16
|
+
# 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
|
+
dependencies = [
|
|
19
|
+
"torch==2.8.0",
|
|
20
|
+
"torchvision==0.23.0",
|
|
21
|
+
"transformers==5.17.0",
|
|
22
|
+
"qwen-vl-utils==0.0.14",
|
|
23
|
+
"huggingface-hub>=0.30",
|
|
24
|
+
"safetensors>=0.4",
|
|
25
|
+
"numpy>=2.2",
|
|
26
|
+
"pillow>=11",
|
|
27
|
+
"mss>=9",
|
|
28
|
+
"pyobjc-framework-Quartz>=10; sys_platform == 'darwin'",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = ["pytest>=8"]
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling>=1.27"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["src/streamembed"]
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.sdist]
|
|
42
|
+
include = ["src/streamembed", "tests", "examples", "README.md", "pyproject.toml", "LICENSE", "NOTICE"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,7 @@
|
|
|
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, query_index,
|
|
3
|
+
visualize_results)
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
__all__ = ["Capture", "Result", "available_index_types", "available_models", "build_index_from_directory", "build_index_from_now", "configure", "query_index",
|
|
7
|
+
"visualize_results"]
|