sieve-memory 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 (56) hide show
  1. sieve_memory-0.1.0/LICENSE +21 -0
  2. sieve_memory-0.1.0/PKG-INFO +493 -0
  3. sieve_memory-0.1.0/README.md +450 -0
  4. sieve_memory-0.1.0/pyproject.toml +64 -0
  5. sieve_memory-0.1.0/setup.cfg +4 -0
  6. sieve_memory-0.1.0/sieve/__init__.py +43 -0
  7. sieve_memory-0.1.0/sieve/__main__.py +4 -0
  8. sieve_memory-0.1.0/sieve/adapters/__init__.py +4 -0
  9. sieve_memory-0.1.0/sieve/adapters/base.py +30 -0
  10. sieve_memory-0.1.0/sieve/adapters/json_file.py +37 -0
  11. sieve_memory-0.1.0/sieve/api.py +667 -0
  12. sieve_memory-0.1.0/sieve/assets/favicon.png +0 -0
  13. sieve_memory-0.1.0/sieve/assets/favicon.svg +15 -0
  14. sieve_memory-0.1.0/sieve/assets/icon.png +0 -0
  15. sieve_memory-0.1.0/sieve/assets/logo-black.svg +14 -0
  16. sieve_memory-0.1.0/sieve/assets/logo-white.png +0 -0
  17. sieve_memory-0.1.0/sieve/assets/logo-white.svg +14 -0
  18. sieve_memory-0.1.0/sieve/assets/logo.png +0 -0
  19. sieve_memory-0.1.0/sieve/assets/logo.svg +20 -0
  20. sieve_memory-0.1.0/sieve/cli.py +286 -0
  21. sieve_memory-0.1.0/sieve/integrations/__init__.py +8 -0
  22. sieve_memory-0.1.0/sieve/integrations/chroma.py +150 -0
  23. sieve_memory-0.1.0/sieve/integrations/langchain.py +150 -0
  24. sieve_memory-0.1.0/sieve/memory.py +165 -0
  25. sieve_memory-0.1.0/sieve/pipeline.py +80 -0
  26. sieve_memory-0.1.0/sieve/policy.py +85 -0
  27. sieve_memory-0.1.0/sieve/schemas.py +54 -0
  28. sieve_memory-0.1.0/sieve/scorer.py +205 -0
  29. sieve_memory-0.1.0/sieve/site/docs.html +2404 -0
  30. sieve_memory-0.1.0/sieve/site/favicon.ico +0 -0
  31. sieve_memory-0.1.0/sieve/site/favicon.png +0 -0
  32. sieve_memory-0.1.0/sieve/site/favicon.svg +15 -0
  33. sieve_memory-0.1.0/sieve/site/index.html +2451 -0
  34. sieve_memory-0.1.0/sieve/site/logo.png +0 -0
  35. sieve_memory-0.1.0/sieve/site/logo.svg +14 -0
  36. sieve_memory-0.1.0/sieve/site/vercel.json +30 -0
  37. sieve_memory-0.1.0/sieve/store.py +521 -0
  38. sieve_memory-0.1.0/sieve/sweep.py +136 -0
  39. sieve_memory-0.1.0/sieve/ui.py +699 -0
  40. sieve_memory-0.1.0/sieve/worker.py +103 -0
  41. sieve_memory-0.1.0/sieve_memory.egg-info/PKG-INFO +493 -0
  42. sieve_memory-0.1.0/sieve_memory.egg-info/SOURCES.txt +54 -0
  43. sieve_memory-0.1.0/sieve_memory.egg-info/dependency_links.txt +1 -0
  44. sieve_memory-0.1.0/sieve_memory.egg-info/entry_points.txt +2 -0
  45. sieve_memory-0.1.0/sieve_memory.egg-info/requires.txt +24 -0
  46. sieve_memory-0.1.0/sieve_memory.egg-info/top_level.txt +1 -0
  47. sieve_memory-0.1.0/tests/test_integrations.py +66 -0
  48. sieve_memory-0.1.0/tests/test_live_readiness_deep_dive.py +394 -0
  49. sieve_memory-0.1.0/tests/test_memory_api.py +93 -0
  50. sieve_memory-0.1.0/tests/test_policy_and_sweeps.py +72 -0
  51. sieve_memory-0.1.0/tests/test_production_fixes.py +434 -0
  52. sieve_memory-0.1.0/tests/test_production_readiness.py +221 -0
  53. sieve_memory-0.1.0/tests/test_real_laya_smoke.py +23 -0
  54. sieve_memory-0.1.0/tests/test_scorer.py +62 -0
  55. sieve_memory-0.1.0/tests/test_store.py +90 -0
  56. sieve_memory-0.1.0/tests/test_worker.py +34 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ashutosh Bansal
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,493 @@
1
+ Metadata-Version: 2.4
2
+ Name: sieve-memory
3
+ Version: 0.1.0
4
+ Summary: A fast, local, calibrated memory-curation layer for AI agents, built on Laya.
5
+ Author-email: Ashutosh Bansal <ashutoshbansalcs@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/ashutoshb206/sieve
8
+ Project-URL: Documentation, https://github.com/ashutoshb206/sieve#readme
9
+ Project-URL: Repository, https://github.com/ashutoshb206/sieve
10
+ Project-URL: Issues, https://github.com/ashutoshb206/sieve/issues
11
+ Keywords: memory,ai-agents,garbage-collection,llm,context-window,laya,langchain,vector-db
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: laya
24
+ Requires-Dist: laya; extra == "laya"
25
+ Provides-Extra: serve
26
+ Requires-Dist: fastapi; extra == "serve"
27
+ Requires-Dist: uvicorn; extra == "serve"
28
+ Provides-Extra: integrations
29
+ Requires-Dist: chromadb; extra == "integrations"
30
+ Requires-Dist: langchain-core; extra == "integrations"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest; extra == "dev"
33
+ Requires-Dist: httpx; extra == "dev"
34
+ Provides-Extra: all
35
+ Requires-Dist: laya; extra == "all"
36
+ Requires-Dist: fastapi; extra == "all"
37
+ Requires-Dist: uvicorn; extra == "all"
38
+ Requires-Dist: chromadb; extra == "all"
39
+ Requires-Dist: langchain-core; extra == "all"
40
+ Requires-Dist: pytest; extra == "all"
41
+ Requires-Dist: httpx; extra == "all"
42
+ Dynamic: license-file
43
+
44
+ <div align="center">
45
+
46
+ <picture>
47
+ <source media="(prefers-color-scheme: dark)" srcset="assets/logo-white.svg">
48
+ <source media="(prefers-color-scheme: light)" srcset="assets/logo-black.svg">
49
+ <img src="assets/logo-white.svg" alt="Sieve Sweep Logo" width="96" height="96" />
50
+ </picture>
51
+
52
+ # Sieve
53
+
54
+ ### Autonomous Memory Compaction & Self-Cleaning Store for AI Agents
55
+
56
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
57
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
58
+ [![CI](https://github.com/ashutoshb206/sieve/actions/workflows/ci.yml/badge.svg)](https://github.com/ashutoshb206/sieve/actions)
59
+ [![Tests](https://img.shields.io/badge/tests-50%20passed-brightgreen.svg)]()
60
+ [![Zero Dependencies Option](https://img.shields.io/badge/core%20deps-zero%20(pure%20python)-orange.svg)]()
61
+
62
+ **Sieve acts as an automated garbage collector and cache eviction daemon for AI agent memory.**
63
+ Instead of dumping endless logs into a vector store or burning money on an LLM call every turn to resolve contradictions, Sieve continuously scores, supersedes, and prunes memories in the background using non-autoregressive calibrated decisions (**~33ms, 100% local, $0 API cost**).
64
+
65
+ [Why Sieve?](#the-problem-sieve-solves) •
66
+ [Quickstart](#quickstart-5-minutes) •
67
+ [Interactive Web UI](#interactive-web-dashboard) •
68
+ [Integration Guide](#how-to-use-sieve-in-your-projects) •
69
+ [Benchmarks](#reproducible-benchmarks) •
70
+ [Architecture](#how-it-works) •
71
+ [REST API & CLI](#rest-api--cli)
72
+
73
+ </div>
74
+
75
+ ---
76
+
77
+ ## What Sieve Does (In 30 Seconds)
78
+
79
+ 1. **Ingest & Score (~0.2ms Mock / ~33ms Laya)**: Categorizes incoming conversation turns into `decision`, `reference`, `task`, or `smalltalk` and scores them on calibrated scales for `importance` (0.0 to 1.0) and `actionable` (0.0 to 1.0).
80
+ 2. **Background Pairwise Sweeps (FTS5 BM25)**: Evaluates whether a new fact contradicts or supersedes an older fact (e.g. *"We switched from PostgreSQL to MongoDB"* supersedes *"Our database is PostgreSQL"*). The outdated item is marked `status='archived'` with `superseded_by='<new_id>'`.
81
+ 3. **Pinned Memory Retention**: High-priority facts (or manual pins) remain immune to staleness pruning and stay active indefinitely.
82
+ 4. **Clean System Prompt Context**: `memory.get_context(namespace="user_1")` or `GET /context` yields clean, deduplicated, non-contradictory context ready for injection into your LLM prompt.
83
+
84
+ ---
85
+
86
+ ### Pattern 4: Standalone Microservice (FastAPI REST Server)
87
+
88
+ Run Sieve as an internal microservice for distributed agents across any tech stack (Python, TypeScript, Go, Rust):
89
+
90
+ ```bash
91
+ pip install "sieve-memory[serve]"
92
+ sieve serve --port 8000 --db sieve.db --api-key my_secret_key
93
+ ```
94
+
95
+ * `GET /context?namespace=default`: Formatted markdown bullet points ready for LLM prompt injection
96
+ * `POST /items`: Ingest single memory with immediate scoring
97
+ * `POST /items/batch`: Bulk ingest with per-item status tracking
98
+ * `GET /active?limit=50&offset=0`: Fetch active memory items (including pinned) ranked by importance
99
+ * `GET /inbox?threshold=0.6`: Fetch open action items ranked by actionability
100
+ * `POST /item/{id}/pin` & `/unpin`: Pin or unpin memories
101
+ * `POST /item/{id}/restore`: Reactivate an archived memory and clear supersession
102
+ * `GET /namespaces`: List all active namespaces
103
+ * `DELETE /namespace/{namespace}`: Permanently delete all memories in a namespace
104
+ * `GET /metrics`: System operational metrics (DB size, item counts, scorer backend, sweep durations)
105
+ * `POST /sweep/staleness`: Trigger background staleness sweep
106
+ * `POST /sweep/redundancy`: Trigger background redundancy detection
107
+ * `POST /sweep/retention`: Enforce retention bounds (`max_active_items` and `archive_ttl_seconds`)
108
+ * `GET /ui`: Interactive web dashboard (supports API key token prompt and toast notifications)
109
+
110
+ ### Production Deployment & Security
111
+
112
+ ```bash
113
+ # Production server with API key auth, custom checkpoint, and SQLite WAL storage
114
+ SIEVE_DB_PATH=/var/data/sieve.db \
115
+ SIEVE_API_KEY=your-secure-secret-token \
116
+ SIEVE_SCORER=laya \
117
+ SIEVE_LAYA_CHECKPOINT=convaiinnovations/laya \
118
+ SIEVE_LAYA_DEVICE=cuda \
119
+ uvicorn sieve.api:app --host 0.0.0.0 --port 8000
120
+ ```
121
+
122
+ | Setting | Default | Purpose |
123
+ | :--- | :--- | :--- |
124
+ | `SIEVE_DB_PATH` | `sieve.db` | Filepath to persistent SQLite database. Runs in WAL mode with auto-migrations. |
125
+ | `SIEVE_API_KEY` | *(None)* | Bearer token / `X-API-Key` auth. When set, all read/write endpoints require authentication. |
126
+ | `SIEVE_SCORER` | `mock` | Decision backend: `mock` (offline heuristic) or `laya` (calibrated neural model). |
127
+ | `SIEVE_LAYA_CHECKPOINT` | `convaiinnovations/laya` | Hugging Face model checkpoint for LayaScorer. Cached in memory. |
128
+ | `SIEVE_LAYA_DEVICE` | `None` *(auto)* | Target device for neural inference: `cuda`, `mps`, or `cpu`. |
129
+ | `SIEVE_CORS_ORIGINS` | *(None)* | Comma-separated list of allowed origins (or `*`) for external browser clients. |
130
+
131
+ > **Dashboard Authentication**: When `SIEVE_API_KEY` is configured on the server, the `/ui` dashboard provides an inline **🔑 API Key** manager modal, storing your token in this browser's `localStorage` and attaching it to all asynchronous requests.
132
+ > **Security Note**: Never expose Sieve directly to the public internet without `SIEVE_API_KEY` configured or without an authenticated reverse-proxy (Nginx/Caddy) providing TLS and access control.
133
+
134
+ ### Retention Policy & Operational Backups
135
+
136
+ Sieve supports automatic capacity bounds and live online backups:
137
+
138
+ ```bash
139
+ # Atomic online hot backup (WAL-safe without locking concurrent writes)
140
+ sieve backup /var/backups/sieve_$(date +%Y%m%d).db --db /var/data/sieve.db
141
+
142
+ # Enforce active context limits and TTL purging via CLI
143
+ sieve retention --namespace user_1 --max-active 20 --ttl 2592000
144
+ ```
145
+
146
+ In Python:
147
+ ```python
148
+ from sieve import SieveMemory, PolicyConfig
149
+
150
+ # Configure retention limits: max 20 active facts, purge archived facts older than 30 days
151
+ policy = PolicyConfig(
152
+ max_active_items=20,
153
+ archive_ttl_seconds=30 * 86400,
154
+ pinned_immune=True, # Pinned items are never auto-pruned
155
+ )
156
+ memory = SieveMemory(policy_config=policy)
157
+ ```
158
+ ---
159
+
160
+ ## The Problem Sieve Solves
161
+
162
+ Every modern AI agent stores conversational memory, but current approaches break at scale:
163
+
164
+ | Approach | Latency | Per-Turn Cost | Resolves Supersession & Staleness? |
165
+ | :--- | :--- | :--- | :--- |
166
+ | **Vector DBs (Chroma, Pinecone)** | ~15ms | $0 | ❌ **No.** Embeddings compute *topical similarity*, not *ground truth*. If an agent records *"User prefers PostgreSQL"* on Monday and *"Switched to MongoDB"* on Wednesday, vector search returns both with high cosine similarity. The LLM hallucinates outdated facts. |
167
+ | **Generative LLMs (Mem0, Letta)** | ~800–2500ms | $$$ | ✅ **Yes, but slow & expensive.** Asking GPT-4o on every single conversational turn to extract facts and check for contradictions adds 1–2 seconds of user latency and thousands of unnecessary tokens. |
168
+ | **Sieve (Built on Laya)** | **~33ms** | **$0** | **✅ Yes.** Calibrated non-autoregressive scoring runs locally. Background sweeps automatically supersede outdated facts and keep system prompts clean and up-to-date. |
169
+
170
+ > **Sieve is not a vector store, not a search index, and not a chat UI.**
171
+ > It is the lightweight metadata and curation layer that sits beside your agent storage and tells you what to **keep**, **pin**, or **retire**.
172
+
173
+ ---
174
+
175
+ ## Quickstart (5 Minutes)
176
+
177
+ ### 1. Installation
178
+
179
+ ```bash
180
+ # Zero-dependency core (runs anywhere, instant setup, built-in heuristic MockScorer)
181
+ pip install sieve-memory
182
+
183
+ # Optional extras for specific deployment targets:
184
+ pip install "sieve-memory[laya]" # Real neural decision model (ConvAI Laya checkpoint)
185
+ pip install "sieve-memory[serve]" # FastAPI REST microservice & visual UI dashboard
186
+ pip install "sieve-memory[integrations]" # LangChain & ChromaDB connectors
187
+ pip install "sieve-memory[all]" # Complete suite with all backends
188
+ ```
189
+
190
+ ### 2. Run the Interactive Demos
191
+
192
+ ```bash
193
+ # Agent workflow demo (remember -> update -> sweep -> context window)
194
+ python examples/agent_quickstart.py
195
+
196
+ # End-to-end batch curation demo
197
+ python examples/run_v0.py
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Interactive Web Dashboard
203
+
204
+ Sieve ships with a built-in dark mode dashboard for visualizing memory curation in real-time.
205
+
206
+ ```bash
207
+ # Start the visual dashboard (or pass --db path)
208
+ sieve ui --port 8000
209
+ ```
210
+ Open **`http://localhost:8000/ui`** in your browser:
211
+ * **Active Memories**: Real-time cards showing importance levels, categories, and pinning controls.
212
+ * **Superseded & Stale**: View facts pruned by background sweeps with pointers to the superseding item.
213
+ * **Action Items Inbox**: Real-time ranking of open tasks and pending follow-ups.
214
+ * **System Prompt Live Preview**: Inspect exactly what prompt context Sieve generates for your LLM.
215
+
216
+ ---
217
+
218
+ ## How to Use Sieve in Your Projects
219
+
220
+ ### Pattern 1: Drop-in Memory for Any AI Agent (OpenAI, Anthropic, LangChain)
221
+
222
+ Use `SieveMemory` directly inside your agent loop. It automatically partitions by namespace (`user_id` or `session_id`), supports continuous background workers, and prepares clean context strings for your system prompt:
223
+
224
+ ```python
225
+ from sieve import SieveMemory
226
+
227
+ # 1. Initialize memory store (persisted in SQLite + FTS5)
228
+ memory = SieveMemory(db_path="agent_memory.db")
229
+
230
+ # Optional: Start background curation daemon (runs sweeps every 60s)
231
+ memory.start_daemon(interval_seconds=60)
232
+
233
+ # 2. Record conversation facts as your agent talks to a user
234
+ session = "user_42"
235
+ memory.remember("User's primary database is PostgreSQL.", namespace=session)
236
+ memory.remember("TODO: Send invoice to Alice by Friday.", namespace=session)
237
+ memory.remember("Deployment target is AWS us-east-1.", namespace=session)
238
+
239
+ # 3. Later, the user changes a decision:
240
+ memory.remember("Update: We switched the database from PostgreSQL to MongoDB.", namespace=session)
241
+
242
+ # 4. Trigger a sweep manually (or let the background daemon handle it)
243
+ sweep_stats = memory.sweep(namespace=session)
244
+ print(f"Archived {sweep_stats['items_archived']} superseded items.")
245
+
246
+ # 5. Inject only active, non-superseded facts into your LLM system prompt
247
+ system_context = memory.get_context(namespace=session)
248
+ print(system_context)
249
+ ```
250
+
251
+ **What the LLM sees in its prompt:**
252
+ ```text
253
+ - [DECISION] Update: We switched the database from PostgreSQL to MongoDB.
254
+ - [TASK] TODO: Send invoice to Alice by Friday.
255
+ - [REFERENCE] Deployment target is AWS us-east-1.
256
+ ```
257
+ *(Notice: The old PostgreSQL fact was automatically identified as superseded, archived, and excluded from the active context window.)*
258
+
259
+ ---
260
+
261
+ ### Pattern 2: Modern LangChain Agent Integration (`LCEL`)
262
+
263
+ Use `SieveChatMessageHistory` as a drop-in replacement for standard message history in LangChain:
264
+
265
+ ```python
266
+ from sieve.integrations.langchain import SieveChatMessageHistory
267
+
268
+ # Automatically prunes superseded messages every 4 turns
269
+ history = SieveChatMessageHistory(session_id="user_alice", db_path="memory.db")
270
+
271
+ history.add_user_message("We chose PostgreSQL as our database.")
272
+ history.add_ai_message("Got it, PostgreSQL configured.")
273
+ history.add_user_message("Actually, we migrated to MongoDB instead.")
274
+
275
+ # In your LangChain agent prompt:
276
+ # Only active, non-superseded messages remain in history.messages!
277
+ print(history.messages)
278
+ ```
279
+
280
+ ---
281
+
282
+ ### Pattern 3: Sidecar alongside ChromaDB / Vector DBs
283
+
284
+ You don't need to replace your vector database. Sieve acts as an **active filter**:
285
+
286
+ ```python
287
+ import chromadb
288
+ from sieve.integrations.chroma import SieveChromaSync
289
+
290
+ client = chromadb.Client()
291
+ collection = client.create_collection("agent_docs")
292
+ sync = SieveChromaSync(collection, db_path="sieve.db")
293
+
294
+ # Add memories into both Sieve and Chroma
295
+ sync.add(
296
+ documents=["Primary DB is PostgreSQL.", "Actually, switched to MongoDB."],
297
+ ids=["doc_1", "doc_2"],
298
+ namespace="user_alice",
299
+ )
300
+
301
+ # Run sweep: marks doc_1 as archived in both Sieve and Chroma metadata
302
+ sync.sweep(namespace="user_alice")
303
+
304
+ # Query Chroma: automatically filters out stale/superseded records!
305
+ results = sync.query(
306
+ query_texts=["What database are we using?"],
307
+ namespace="user_alice",
308
+ only_active=True,
309
+ )
310
+ ```
311
+
312
+ ---
313
+
314
+ ### Pattern 4: Standalone Microservice (FastAPI REST Server)
315
+
316
+ Run Sieve as an internal microservice for distributed agents across any tech stack (Python, TypeScript, Go, Rust):
317
+
318
+ ```bash
319
+ pip install "sieve-memory[serve]"
320
+ sieve serve --port 8000 --db sieve.db --api-key my_secret_key
321
+ ```
322
+
323
+ * `GET /context?namespace=default`: Formatted markdown bullet points ready for LLM prompt injection
324
+ * `POST /items`: Ingest single memory with immediate scoring
325
+ * `POST /items/batch`: Bulk ingest with per-item status tracking
326
+ * `GET /active?limit=50&offset=0`: Fetch active memory items (including pinned) ranked by importance
327
+ * `GET /inbox?threshold=0.6`: Fetch open action items ranked by actionability
328
+ * `POST /item/{id}/pin` & `/unpin`: Pin or unpin memories
329
+ * `POST /item/{id}/restore`: Reactivate an archived memory and clear supersession
330
+ * `GET /namespaces`: List all active namespaces
331
+ * `GET /metrics`: System operational metrics (DB size, item counts, scorer backend)
332
+ * `POST /sweep/staleness`: Trigger background staleness sweep
333
+ * `POST /sweep/redundancy`: Trigger background redundancy detection
334
+ * `GET /ui`: Interactive web dashboard (supports API key token prompt)
335
+
336
+ ### Production Deployment & Security
337
+
338
+ ```bash
339
+ # Production server with API key auth, custom checkpoint, and SQLite WAL storage
340
+ SIEVE_DB_PATH=/var/data/sieve.db \
341
+ SIEVE_API_KEY=your-secure-secret-token \
342
+ SIEVE_SCORER=laya \
343
+ SIEVE_LAYA_CHECKPOINT=convaiinnovations/laya \
344
+ SIEVE_LAYA_DEVICE=cuda \
345
+ uvicorn sieve.api:app --host 0.0.0.0 --port 8000
346
+ ```
347
+
348
+ | Setting | Default | Purpose |
349
+ | :--- | :--- | :--- |
350
+ | `SIEVE_DB_PATH` | `sieve.db` | Filepath to persistent SQLite database. Runs in WAL mode with auto-migrations. |
351
+ | `SIEVE_API_KEY` | *(None)* | Bearer token / `X-API-Key` auth. When set, all read/write endpoints require authentication. |
352
+ | `SIEVE_SCORER` | `mock` | Decision backend: `mock` (offline heuristic) or `laya` (calibrated neural model). |
353
+ | `SIEVE_LAYA_CHECKPOINT` | `convaiinnovations/laya` | Hugging Face model checkpoint for LayaScorer. Cached in memory. |
354
+ | `SIEVE_LAYA_DEVICE` | `None` *(auto)* | Target device for neural inference: `cuda`, `mps`, or `cpu`. |
355
+
356
+ > **Dashboard Authentication**: When `SIEVE_API_KEY` is configured on the server, the `/ui` dashboard provides an inline **🔑 API Key** manager modal, storing your token in this browser's `localStorage` and attaching it to all asynchronous requests.
357
+ > **Security Note**: Never expose Sieve directly to the public internet without `SIEVE_API_KEY` configured or without an authenticated reverse-proxy (Nginx/Caddy) providing TLS and access control.
358
+
359
+ ---
360
+
361
+ ## Reproducible Benchmarks
362
+
363
+ Run the local pipeline benchmark on your machine:
364
+ ```bash
365
+ python benchmarks/benchmark.py --items 50
366
+ ```
367
+
368
+ > **Benchmark Transparency**: The performance numbers below evaluate the local pipeline infrastructure (SQLite FTS5 candidate pairing, scoring throughput, and token bloat reduction) using the zero-dependency `MockScorer`. Real-world neural inference via `LayaScorer` adds ~33ms per evaluated pair.
369
+
370
+ ### Typical Pipeline Baseline (Local M-Series / Linux):
371
+
372
+ ```text
373
+ ======================================================================
374
+ SUMMARY COMPARISON TABLE
375
+ ======================================================================
376
+ Metric | Sieve (Local) | LLM per Turn (4o-mini)
377
+ ------------------------------------------------------------------------
378
+ Latency per Item | 1.2 ms | ~850 ms
379
+ API Cost (10,000 items) | $0.00 | ~$1.35
380
+ Synthetic Benchmark Acc | ~100% (synthetic) | ~95%
381
+ Context Window Growth | Bounded (Pruned) | Bounded
382
+ Context Bloat Reduction | 33.5% saved | 30–35% saved
383
+ ======================================================================
384
+ ```
385
+
386
+ ---
387
+
388
+ ## Switching from Mock to Real Neural Inference (Laya)
389
+
390
+ By default, Sieve runs `MockScorer`—a zero-dependency heuristic engine designed for rapid development and CI tests.
391
+
392
+ To use the real **Laya** calibrated neural checkpoint:
393
+
394
+ ```bash
395
+ pip install laya
396
+ ```
397
+
398
+ ```python
399
+ from sieve import SieveMemory
400
+
401
+ # Loads the calibrated Laya checkpoint from Hugging Face (~33ms per inference)
402
+ memory = SieveMemory(use_real_laya=True)
403
+ ```
404
+
405
+ Every other layer of your stack (SQLite store, FTS5 sweeps, policy rules, REST API) remains completely unchanged.
406
+
407
+ ---
408
+
409
+ ## How It Works
410
+
411
+ ```
412
+ Raw Text Memory
413
+ │
414
+ ▼
415
+ 1. INGESTION ───► SQLite Store (Partitioned by Namespace)
416
+ │
417
+ ▼
418
+ 2. CALIBRATED ───► Evaluates:
419
+ SCORING • Importance: Will this matter beyond the moment? (0.0 - 1.0)
420
+ • Actionable: Is there an open task or follow-up? (P(true))
421
+ • Category: decision | reference | task | smalltalk
422
+ │
423
+ ▼
424
+ 3. POLICY ───► • Pin if importance >= 0.85 (immune to auto-archiving)
425
+ ENGINE • Route to Action Inbox if actionable >= 0.60
426
+ • Queue for batched review if confidence is low
427
+ │
428
+ ▼
429
+ 4. PAIRWISE ───► • Uses SQLite FTS5 BM25 to find topically related candidates
430
+ SWEEPS • Scores staleness: Does the newer item invalidate the older one?
431
+ • Archives outdated facts with pointer to `superseded_by`
432
+ ```
433
+
434
+ ### What Sieve Scores
435
+
436
+ | Metric | Type | Question Evaluated |
437
+ |---|---|---|
438
+ | **`importance`** | `score` | *Will this matter beyond the moment it was written?* |
439
+ | **`actionable`** | `noul` | *Is there an open task, pending decision, or required follow-up?* |
440
+ | **`category`** | `choice` | `decision` · `reference` · `task` · `smalltalk` |
441
+ | **`staleness`** | `noul` (pairwise) | *Does the newer item make the older item outdated or invalid?* |
442
+ | **`redundancy`** | `noul` (pairwise) | *Do two items convey substantially identical information?* |
443
+
444
+ ---
445
+
446
+ ## CLI Reference
447
+
448
+ ```bash
449
+ # Launch Sieve REST API server & web dashboard
450
+ sieve serve --port 8000 --db sieve.db --api-key my_secret
451
+
452
+ # Launch visual dashboard in browser
453
+ sieve ui --port 8000
454
+
455
+ # Remember a fact directly from terminal
456
+ sieve remember "Decided to adopt PostgreSQL" --namespace project_x
457
+
458
+ # Print active memory context formatted for direct LLM system prompt injection
459
+ sieve context --namespace project_x
460
+
461
+ # Pin critical items so they are permanently protected from pruning
462
+ sieve pin cli_179166_4ff0
463
+ sieve unpin cli_179166_4ff0
464
+
465
+ # Archive or delete memories
466
+ sieve archive cli_179166_4ff0
467
+ sieve delete cli_179166_4ff0
468
+
469
+ # Run curation sweeps (supersede outdated facts)
470
+ sieve sweep --namespace project_x
471
+
472
+ # Check open task inbox
473
+ sieve inbox --namespace project_x
474
+
475
+ # View store statistics
476
+ sieve stats --namespace project_x
477
+ ```
478
+
479
+ ---
480
+
481
+ ## Testing
482
+
483
+ Sieve has 100% passing tests covering CRUD, thread-safety, namespaces, FTS5 BM25 candidate ranking, policy staleness, LangChain & ChromaDB integrations, background daemons, and the REST API:
484
+
485
+ ```bash
486
+ python -m pytest tests/ -v
487
+ ```
488
+
489
+ ---
490
+
491
+ ## License
492
+
493
+ MIT © [Ashutosh Bansal](https://github.com/ashutoshb206)