tinysuite-context 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.
Files changed (46) hide show
  1. tinysuite_context-0.1.0/LICENSE +21 -0
  2. tinysuite_context-0.1.0/MANIFEST.in +1 -0
  3. tinysuite_context-0.1.0/NOTICE +19 -0
  4. tinysuite_context-0.1.0/PKG-INFO +356 -0
  5. tinysuite_context-0.1.0/README.md +326 -0
  6. tinysuite_context-0.1.0/pyproject.toml +47 -0
  7. tinysuite_context-0.1.0/setup.cfg +4 -0
  8. tinysuite_context-0.1.0/src/tinycontext/__init__.py +10 -0
  9. tinysuite_context-0.1.0/src/tinycontext/__main__.py +5 -0
  10. tinysuite_context-0.1.0/src/tinycontext/cli.py +69 -0
  11. tinysuite_context-0.1.0/src/tinycontext/config.py +197 -0
  12. tinysuite_context-0.1.0/src/tinycontext/core.py +124 -0
  13. tinysuite_context-0.1.0/src/tinycontext/doctor.py +89 -0
  14. tinysuite_context-0.1.0/src/tinycontext/errors.py +24 -0
  15. tinysuite_context-0.1.0/src/tinycontext/models.py +24 -0
  16. tinysuite_context-0.1.0/src/tinycontext/paths.py +29 -0
  17. tinysuite_context-0.1.0/src/tinycontext/pipelines/__init__.py +1 -0
  18. tinysuite_context-0.1.0/src/tinycontext/pipelines/memory_recall.py +178 -0
  19. tinysuite_context-0.1.0/src/tinycontext/servers/__init__.py +1 -0
  20. tinysuite_context-0.1.0/src/tinycontext/servers/fastapi_server.py +142 -0
  21. tinysuite_context-0.1.0/src/tinycontext/servers/mcp_server.py +293 -0
  22. tinysuite_context-0.1.0/src/tinycontext/services/__init__.py +1 -0
  23. tinysuite_context-0.1.0/src/tinycontext/services/context_config_service.py +92 -0
  24. tinysuite_context-0.1.0/src/tinycontext/services/embedding_service.py +347 -0
  25. tinysuite_context-0.1.0/src/tinycontext/services/memory_store_service.py +377 -0
  26. tinysuite_context-0.1.0/src/tinycontext/services/onnx_bundle_service.py +107 -0
  27. tinysuite_context-0.1.0/src/tinycontext/services/token_counter_service.py +53 -0
  28. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/PKG-INFO +356 -0
  29. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/SOURCES.txt +44 -0
  30. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/dependency_links.txt +1 -0
  31. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/entry_points.txt +2 -0
  32. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/requires.txt +13 -0
  33. tinysuite_context-0.1.0/src/tinysuite_context.egg-info/top_level.txt +1 -0
  34. tinysuite_context-0.1.0/tests/__init__.py +1 -0
  35. tinysuite_context-0.1.0/tests/embedding_fakes.py +44 -0
  36. tinysuite_context-0.1.0/tests/test_cli.py +59 -0
  37. tinysuite_context-0.1.0/tests/test_doctor.py +39 -0
  38. tinysuite_context-0.1.0/tests/test_embedding_service.py +55 -0
  39. tinysuite_context-0.1.0/tests/test_fastapi_memory_endpoints.py +78 -0
  40. tinysuite_context-0.1.0/tests/test_mcp_memory_tools.py +77 -0
  41. tinysuite_context-0.1.0/tests/test_memory_fastapi_mcp_parity.py +91 -0
  42. tinysuite_context-0.1.0/tests/test_memory_recall_pipeline.py +89 -0
  43. tinysuite_context-0.1.0/tests/test_memory_service.py +83 -0
  44. tinysuite_context-0.1.0/tests/test_memory_store_service.py +191 -0
  45. tinysuite_context-0.1.0/tests/test_public_config_and_paths.py +141 -0
  46. tinysuite_context-0.1.0/tests/test_source_wrappers.py +20 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MarcellM01
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.
@@ -0,0 +1 @@
1
+ recursive-include tests *.py
@@ -0,0 +1,19 @@
1
+ TinyContext
2
+ Copyright (c) 2026 MarcellM01
3
+
4
+ TinyContext source code is licensed under the MIT License. See LICENSE.
5
+
6
+ The Docker image installs third-party Python packages from requirements.txt and
7
+ their transitive dependencies. Those packages remain under their respective
8
+ upstream licenses.
9
+
10
+ TinyContext does not commit or bake ONNX embedding model files into this
11
+ repository or Docker image. When the ONNX backend is enabled, the running
12
+ application may download the selected model bundle from Hugging Face into the
13
+ configured models directory. Those model files are separate distributions under
14
+ their upstream model-card licenses.
15
+
16
+ The default fast embedding bundle is derived from all-MiniLM-L6-v2 and is
17
+ Apache-2.0. The balanced and quality presets use BAAI bge model bundles; check
18
+ their Hugging Face model cards before redistributing images, volumes, or
19
+ archives that include downloaded weights.
@@ -0,0 +1,356 @@
1
+ Metadata-Version: 2.4
2
+ Name: tinysuite-context
3
+ Version: 0.1.0
4
+ Summary: Token-light local memory with SQLite hybrid retrieval for AI agents.
5
+ Author: MarcellM01
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/TinySuiteHQ/TinyContext
8
+ Project-URL: Repository, https://github.com/TinySuiteHQ/TinyContext
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Requires-Dist: tiktoken==0.12.0
18
+ Requires-Dist: rank-bm25==0.2.2
19
+ Requires-Dist: platformdirs<5,>=4
20
+ Requires-Dist: huggingface_hub==0.36.0
21
+ Requires-Dist: onnxruntime<2,>=1.17.0
22
+ Requires-Dist: tokenizers<1,>=0.15.0
23
+ Requires-Dist: numpy<3,>=1.26
24
+ Requires-Dist: sqlite-vec==0.1.9
25
+ Provides-Extra: server
26
+ Requires-Dist: fastapi==0.136.1; extra == "server"
27
+ Requires-Dist: uvicorn==0.46.0; extra == "server"
28
+ Requires-Dist: mcp==1.28.1; extra == "server"
29
+ Dynamic: license-file
30
+
31
+ # TinyContext
32
+
33
+ <!-- mcp-name: io.github.TinySuiteHQ/tinycontext -->
34
+
35
+ **Context that fits your local LLMs.**
36
+
37
+ [![PyPI version](https://img.shields.io/pypi/v/tinysuite-context?label=pypi)](https://pypi.org/project/tinysuite-context/)
38
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
39
+ [![Release](https://img.shields.io/github/v/release/TinySuiteHQ/TinyContext?label=release)](https://github.com/TinySuiteHQ/TinyContext/releases)
40
+ [![Docker Pulls](https://img.shields.io/docker/pulls/marcellm01/tinycontext?label=docker%20pulls)](https://hub.docker.com/r/marcellm01/tinycontext)
41
+ ![MCP Server](https://img.shields.io/badge/MCP-server-blue)
42
+ ![FastAPI](https://img.shields.io/badge/FastAPI-supported-009688)
43
+
44
+ TinyContext is a token-light local memory layer for AI agents. It stores concise
45
+ memories and their embeddings in SQLite, ranks them with hybrid BM25 and dense
46
+ retrieval, and returns only the context that fits the requested token budget.
47
+
48
+ No hosted account. No giant context dumps. No required vector database.
49
+
50
+ ## Choose a tier
51
+
52
+ | Tier | Use it when | Entry point |
53
+ | --- | --- | --- |
54
+ | Python library | You are building an agent or Python application | `pip install tinysuite-context` |
55
+ | One-command MCP | An MCP client should launch TinyContext for you | `uvx --python 3.12 --from "tinysuite-context[server]" tinycontext` |
56
+ | Docker | You want persistent self-hosted storage and HTTP MCP | `docker compose ... up -d` |
57
+
58
+ The Python library contains the memory engine. MCP, FastAPI, and Docker are
59
+ adapters around the same `save_memories` and `recall_memories` operations.
60
+
61
+ ## One-command MCP
62
+
63
+ Add TinyContext to any stdio MCP client:
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "tinycontext": {
69
+ "command": "uvx",
70
+ "args": [
71
+ "--python",
72
+ "3.12",
73
+ "--from",
74
+ "tinysuite-context[server]",
75
+ "tinycontext"
76
+ ]
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ The no-argument `tinycontext` command runs stdio MCP. On its first launch,
83
+ TinyContext downloads the selected ONNX embedding bundle into its per-user data
84
+ directory. The database is created lazily on the first save or recall. Later
85
+ launches reuse both local assets.
86
+
87
+ Check the resolved configuration and storage readiness with:
88
+
89
+ ```bash
90
+ uvx --python 3.12 --from "tinysuite-context[server]" tinycontext doctor
91
+ ```
92
+
93
+ TinyContext exposes two tools:
94
+
95
+ ```text
96
+ save_memories(memories)
97
+ recall_memories(query)
98
+ ```
99
+
100
+ - Use `save_memories` for durable facts, preferences, decisions, and research notes.
101
+ - Use `recall_memories` before answering when previous context may help.
102
+
103
+ ## Python library
104
+
105
+ Install only the transport-independent core:
106
+
107
+ ```bash
108
+ pip install tinysuite-context
109
+ ```
110
+
111
+ ```python
112
+ from pathlib import Path
113
+
114
+ from tinycontext import (
115
+ MemoryInput,
116
+ TinyContextConfig,
117
+ recall_memories,
118
+ save_memories,
119
+ )
120
+
121
+ config = TinyContextConfig(
122
+ memory_db_path=str(Path("agent-memory.db").resolve()),
123
+ recall_max_tokens=800,
124
+ )
125
+
126
+ save_memories(
127
+ [
128
+ MemoryInput(
129
+ content="The project uses SQLite for local state.",
130
+ tags=["architecture"],
131
+ metadata={"source": "design-session"},
132
+ )
133
+ ],
134
+ session_id="project-a",
135
+ config=config,
136
+ )
137
+
138
+ result = recall_memories(
139
+ "How does the project store state?",
140
+ session_id="project-a",
141
+ config=config,
142
+ )
143
+
144
+ for memory in result["memories"]:
145
+ print(memory["content"])
146
+ ```
147
+
148
+ Programmatic configuration does not read environment variables or depend on the
149
+ checkout. Passing no config uses the per-user data directory returned by
150
+ `platformdirs`.
151
+
152
+ ## Docker
153
+
154
+ Run the published image as an MCP server over Streamable HTTP:
155
+
156
+ ```bash
157
+ docker compose -f "https://github.com/TinySuiteHQ/TinyContext.git#main:compose.quickstart.yaml" up -d
158
+ ```
159
+
160
+ Connect an MCP client to:
161
+
162
+ ```json
163
+ {
164
+ "mcpServers": {
165
+ "tinycontext": {
166
+ "url": "http://localhost:8000/mcp"
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ The `data` volume persists `/data/memories.db` and `/data/models`.
173
+
174
+ Stop the service with:
175
+
176
+ ```bash
177
+ docker compose -f "https://github.com/TinySuiteHQ/TinyContext.git#main:compose.quickstart.yaml" down
178
+ ```
179
+
180
+ For a local image build:
181
+
182
+ ```bash
183
+ docker compose up -d --build
184
+ ```
185
+
186
+ The optional FastAPI profile uses the same image:
187
+
188
+ ```bash
189
+ docker compose --profile fastapi up -d --build
190
+ ```
191
+
192
+ - MCP Streamable HTTP: `http://localhost:8000/mcp`
193
+ - FastAPI: `http://localhost:8001`
194
+
195
+ ## How recall works
196
+
197
+ ```mermaid
198
+ flowchart LR
199
+ A[Agent] --> B[save_memories]
200
+ A --> C[recall_memories]
201
+ B --> D[(SQLite)]
202
+ C --> D
203
+ C --> E[BM25 rank]
204
+ C --> G[sqlite-vec cosine rank]
205
+ E --> H[Weighted RRF]
206
+ G --> H
207
+ H --> F[Token budget trim]
208
+ F --> A
209
+ ```
210
+
211
+ 1. Generate embeddings locally with the selected ONNX model.
212
+ 2. Save text, metadata, and float32 embedding BLOBs in the same SQLite row.
213
+ 3. Filter by `session_id`, rank lexical matches with BM25, and calculate cosine
214
+ similarity in SQLite through `sqlite-vec`.
215
+ 4. Fuse both rankings with weighted reciprocal rank fusion (RRF).
216
+ 5. Return the highest-ranked memories within the token budget.
217
+
218
+ Existing TinyContext databases are upgraded in place with nullable embedding
219
+ columns. The first recall backfills embeddings for legacy rows; no database
220
+ migration command or separate vector service is required.
221
+
222
+ ## FastAPI
223
+
224
+ The optional HTTP API mirrors the two MCP tools.
225
+
226
+ | Method | Path | Purpose |
227
+ | --- | --- | --- |
228
+ | GET | `/health` | Liveness |
229
+ | POST/GET | `/save_memories` | Persist one or more memories |
230
+ | POST/GET | `/recall_memories` | Recall ranked memories within a token budget |
231
+
232
+ Install and run it directly:
233
+
234
+ ```bash
235
+ pip install "tinysuite-context[server]"
236
+ uvicorn tinycontext.servers.fastapi_server:app --host 0.0.0.0 --port 8000
237
+ ```
238
+
239
+ ### Save request
240
+
241
+ ```json
242
+ {
243
+ "session_id": "optional-session",
244
+ "memories": [
245
+ {
246
+ "content": "User prefers concise answers",
247
+ "tags": ["preference"],
248
+ "metadata": {"source": "chat"}
249
+ }
250
+ ]
251
+ }
252
+ ```
253
+
254
+ ### Recall request
255
+
256
+ ```json
257
+ {
258
+ "query": "user preferences",
259
+ "session_id": "optional-session",
260
+ "max_tokens": 2000,
261
+ "top_k": 10
262
+ }
263
+ ```
264
+
265
+ ### Error codes
266
+
267
+ | Code | HTTP | Meaning |
268
+ | --- | --- | --- |
269
+ | `empty_memory` | 400 | Missing or blank memory content/query |
270
+ | `session_not_found` | 404 | No memories exist for the requested session |
271
+ | `recall_budget` | 400 | Invalid recall budget parameters |
272
+ | `internal_error` | 500 | Unexpected server error |
273
+
274
+ ## Configuration
275
+
276
+ The core defaults are:
277
+
278
+ | Key | Default | Description |
279
+ | --- | --- | --- |
280
+ | `memory_db_path` | Per-user TinyContext data directory | SQLite database |
281
+ | `recall_top_k` | `10` | Maximum memories considered |
282
+ | `recall_max_tokens` | `2000` | Default recall token budget |
283
+ | `encoding_name` | `o200k_base` | Tokenizer used for budgeting |
284
+ | `models_dir` | Per-user TinyContext data directory | Downloaded ONNX bundles |
285
+ | `embedding_model` | `fast` | `fast`, `balanced`, `quality`, or a Hugging Face repository |
286
+ | `embedding_batch_size` | `32` | Local ONNX inference batch size |
287
+ | `recall_dense_weight` | `0.5` | Dense contribution to weighted RRF |
288
+ | `recall_rrf_k` | `60` | RRF rank constant |
289
+ | `dense_query_prefix` | empty | Optional text prepended before embedding queries |
290
+ | `dense_document_prefix` | empty | Optional text prepended before embedding memories |
291
+
292
+ Server processes look for `context_config.json` in the per-user TinyContext
293
+ configuration directory. A relative `memory_db_path` inside a JSON config is
294
+ resolved relative to that file.
295
+
296
+ Environment overrides:
297
+
298
+ | Variable | Purpose |
299
+ | --- | --- |
300
+ | `TINYCONTEXT_CONFIG_PATH` | Use an explicit JSON configuration file |
301
+ | `TINYCONTEXT_MEMORY_DB_PATH` | Override the SQLite database path |
302
+ | `TINYCONTEXT_RECALL_TOP_K` | Override the default candidate count |
303
+ | `TINYCONTEXT_RECALL_MAX_TOKENS` | Override the default token budget |
304
+ | `TINYCONTEXT_ENCODING_NAME` | Override the tokenizer |
305
+ | `TINYCONTEXT_MODELS_DIR` | Override the ONNX bundle directory |
306
+ | `TINYCONTEXT_EMBEDDING_MODEL` | Override the embedding model |
307
+ | `TINYCONTEXT_EMBEDDING_BATCH_SIZE` | Override inference batch size |
308
+ | `TINYCONTEXT_RECALL_DENSE_WEIGHT` | Override the dense RRF weight |
309
+ | `TINYCONTEXT_RECALL_RRF_K` | Override the RRF rank constant |
310
+ | `TINYCONTEXT_DENSE_QUERY_PREFIX` | Override the dense query prefix |
311
+ | `TINYCONTEXT_DENSE_DOCUMENT_PREFIX` | Override the dense document prefix |
312
+ | `TINYCONTEXT_VERSION` | Set the FastAPI/container version |
313
+ | `MCP_TRANSPORT` | `stdio`, `sse`, or `streamable-http` |
314
+ | `MCP_HOST` | MCP HTTP bind host |
315
+ | `MCP_PORT` | MCP HTTP bind port |
316
+ | `MCP_CORS_ORIGINS` | Comma-separated CORS origins |
317
+
318
+ An existing checkout-local database remains usable:
319
+
320
+ ```bash
321
+ TINYCONTEXT_MEMORY_DB_PATH=/absolute/path/to/TinyContext/data/memories.db tinycontext
322
+ ```
323
+
324
+ ## Development
325
+
326
+ ```bash
327
+ git clone https://github.com/TinySuiteHQ/TinyContext
328
+ cd TinyContext
329
+ python -m venv .venv
330
+ source .venv/bin/activate
331
+ pip install -e ".[server]"
332
+ python -m unittest discover tests
333
+ python scripts/smoke_mcp_stdio.py
334
+ ```
335
+
336
+ TinyContext supports Python 3.12 and newer. CI tests Python 3.12, 3.13, and
337
+ 3.14 across Linux, macOS, and Windows.
338
+
339
+ Source-checkout compatibility shims remain available:
340
+
341
+ ```bash
342
+ python servers/mcp_server.py
343
+ uvicorn servers.fastapi_server:app --host 0.0.0.0 --port 8000
344
+ ```
345
+
346
+ ## Entrypoints
347
+
348
+ - `tinycontext.save_memories` and `tinycontext.recall_memories`: Python API
349
+ - `tinycontext` / `tinycontext mcp`: stdio MCP
350
+ - `tinycontext serve`: Streamable HTTP MCP
351
+ - `tinycontext doctor`: configuration and storage readiness
352
+ - `tinycontext.servers.fastapi_server:app`: optional FastAPI application
353
+
354
+ ## License
355
+
356
+ MIT. See [LICENSE](LICENSE) and [NOTICE](NOTICE).