spectraltm-db 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 (44) hide show
  1. spectraltm_db-0.1.0/LICENSE +201 -0
  2. spectraltm_db-0.1.0/PKG-INFO +294 -0
  3. spectraltm_db-0.1.0/README.md +254 -0
  4. spectraltm_db-0.1.0/pyproject.toml +67 -0
  5. spectraltm_db-0.1.0/setup.cfg +4 -0
  6. spectraltm_db-0.1.0/spectraltm_db/__init__.py +46 -0
  7. spectraltm_db-0.1.0/spectraltm_db/__main__.py +248 -0
  8. spectraltm_db-0.1.0/spectraltm_db/config.py +129 -0
  9. spectraltm_db-0.1.0/spectraltm_db/errors.py +34 -0
  10. spectraltm_db-0.1.0/spectraltm_db/index.py +771 -0
  11. spectraltm_db-0.1.0/spectraltm_db/integrations/__init__.py +25 -0
  12. spectraltm_db-0.1.0/spectraltm_db/integrations/langchain.py +324 -0
  13. spectraltm_db-0.1.0/spectraltm_db/integrations/llamaindex.py +233 -0
  14. spectraltm_db-0.1.0/spectraltm_db/retrieval/__init__.py +6 -0
  15. spectraltm_db-0.1.0/spectraltm_db/retrieval/filter_compiler.py +176 -0
  16. spectraltm_db-0.1.0/spectraltm_db/retrieval/filter_executor.py +34 -0
  17. spectraltm_db-0.1.0/spectraltm_db/server.py +468 -0
  18. spectraltm_db-0.1.0/spectraltm_db/sparse.py +88 -0
  19. spectraltm_db-0.1.0/spectraltm_db/storage/__init__.py +40 -0
  20. spectraltm_db-0.1.0/spectraltm_db/storage/id_map.py +204 -0
  21. spectraltm_db-0.1.0/spectraltm_db/storage/metadata_store.py +246 -0
  22. spectraltm_db-0.1.0/spectraltm_db/storage/namespaces.py +71 -0
  23. spectraltm_db-0.1.0/spectraltm_db/storage/vector_store.py +585 -0
  24. spectraltm_db-0.1.0/spectraltm_db/wal.py +80 -0
  25. spectraltm_db-0.1.0/spectraltm_db.egg-info/PKG-INFO +294 -0
  26. spectraltm_db-0.1.0/spectraltm_db.egg-info/SOURCES.txt +42 -0
  27. spectraltm_db-0.1.0/spectraltm_db.egg-info/dependency_links.txt +1 -0
  28. spectraltm_db-0.1.0/spectraltm_db.egg-info/requires.txt +23 -0
  29. spectraltm_db-0.1.0/spectraltm_db.egg-info/top_level.txt +1 -0
  30. spectraltm_db-0.1.0/tests/test_cli.py +113 -0
  31. spectraltm_db-0.1.0/tests/test_compact.py +118 -0
  32. spectraltm_db-0.1.0/tests/test_config.py +71 -0
  33. spectraltm_db-0.1.0/tests/test_filter_compiler.py +139 -0
  34. spectraltm_db-0.1.0/tests/test_id_map.py +86 -0
  35. spectraltm_db-0.1.0/tests/test_index.py +269 -0
  36. spectraltm_db-0.1.0/tests/test_metadata_store.py +98 -0
  37. spectraltm_db-0.1.0/tests/test_pinecone_compat.py +48 -0
  38. spectraltm_db-0.1.0/tests/test_score_one_binding.py +68 -0
  39. spectraltm_db-0.1.0/tests/test_server.py +207 -0
  40. spectraltm_db-0.1.0/tests/test_sparse.py +86 -0
  41. spectraltm_db-0.1.0/tests/test_upsert_batch.py +138 -0
  42. spectraltm_db-0.1.0/tests/test_vector_store.py +157 -0
  43. spectraltm_db-0.1.0/tests/test_wal.py +36 -0
  44. spectraltm_db-0.1.0/tests/test_wal_replay.py +91 -0
@@ -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 tracking, enhancing, or otherwise modifying
59
+ the Work, but excludes communication that is conspicuously marked or
60
+ otherwise 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 signed
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 describing the origin of the Work and
141
+ 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 Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
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 2026 Gerald Enrique Nelson Mc Kenzie
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.
@@ -0,0 +1,294 @@
1
+ Metadata-Version: 2.4
2
+ Name: spectraltm-db
3
+ Version: 0.1.0
4
+ Summary: Pinecone-shaped local vector database on top of the SpectralTM Rust crate (Sparse Spectral Encoding cold-tier compression).
5
+ Author-email: Gerald Enrique Nelson Mc Kenzie <lordxmen2k@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/lordxmen2k/sparse-spectral-encoding
8
+ Keywords: vector-database,semantic-search,rag,pinecone,spectral-encoding,cold-tier,memory
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Database
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: spectraltm>=0.1.1
22
+ Requires-Dist: numpy>=1.24
23
+ Requires-Dist: msgpack>=1.0.7
24
+ Provides-Extra: encoder
25
+ Requires-Dist: sentence-transformers>=2.2; extra == "encoder"
26
+ Provides-Extra: langchain
27
+ Requires-Dist: langchain-core>=0.1; extra == "langchain"
28
+ Provides-Extra: llamaindex
29
+ Requires-Dist: llama-index-core>=0.10; extra == "llamaindex"
30
+ Provides-Extra: server
31
+ Requires-Dist: fastapi>=0.110; extra == "server"
32
+ Requires-Dist: uvicorn>=0.27; extra == "server"
33
+ Provides-Extra: all
34
+ Requires-Dist: sentence-transformers>=2.2; extra == "all"
35
+ Requires-Dist: langchain-core>=0.1; extra == "all"
36
+ Requires-Dist: llama-index-core>=0.10; extra == "all"
37
+ Requires-Dist: fastapi>=0.110; extra == "all"
38
+ Requires-Dist: uvicorn>=0.27; extra == "all"
39
+ Dynamic: license-file
40
+
41
+ # spectraltm-db
42
+
43
+ [![PyPI version](https://img.shields.io/badge/pypi-v0.1.0.dev0-blue)](https://pypi.org/project/spectraltm-db/)
44
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
45
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
46
+
47
+ > **Pinecone-shape local vector database built on the Spectral encoding Rust engine.**
48
+
49
+ `spectraltm-db` wraps the AVX2-accelerated [`spectraltm`](https://pypi.org/project/spectraltm/) crate with a Pinecone-compatible Python API: same `Index.create`, `Index.upsert`, `Index.query`, metadata filters, namespaces, REST server — running entirely on disk, single-process, no cloud dependency.
50
+
51
+ ## Features
52
+
53
+ - **Pinecone-shape surface**: `Index.create`, `open`, `upsert`, `query`, `fetch`, `delete`, `update`, `describe_index_stats`, `compact` — wire-compatible with the `pinecone` Python SDK.
54
+ - **Spectral encoding compression**: 192 B/chunk at K=64, d=384 (vs ~1.5 KB for float32 embeddings); four named levels: `spectral_k64 / k128 / k256 / float32`.
55
+ - **11 metadata filter operators**: `$eq $ne $gt $gte $lt $lte $in $nin $exists $and $or` — compiled to `json_extract(...)` SQL via a tiny in-process SQLite store.
56
+ - **Multi-namespace** by directory partitioning; per-namespace WAL, calibration buffer, `raw.npy` source-of-truth.
57
+ - **Soft delete + real `compact()`**: re-encodes from `raw.npy` minus tombstones, recovers on-disk space — not just a flag-flip.
58
+ - **LangChain + LlamaIndex adapters** (`pip install spectraltm-db[langchain]` / `[llamaindex]`).
59
+ - **Pinecone-identical REST server** (`pip install spectraltm-db[server]`): 11 endpoints, `Api-Key` auth, multi-index registry.
60
+ - **CLI** (`python -m spectraltm_db {create,stats,upsert,query,delete,update,compact,serve,list}`).
61
+ - **AVX2 SIMD scoring** via the Rust crate; falls back to scalar on other platforms.
62
+ - **Optional `SpectralIndex.score_one` PyO3 binding** for safe single-chunk scoring at n=1 (where `select_nth_unstable_by` would panic).
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ pip install spectraltm-db
68
+ ```
69
+
70
+ Requires Python 3.10+. Pulls in `spectraltm>=0.1.1` (Rust SSE engine) and a pure-Python stack: `numpy`, `msgpack`, stdlib `sqlite3`.
71
+
72
+ Optional extras:
73
+
74
+ ```bash
75
+ pip install "spectraltm-db[encoder]" # sentence-transformers auto-embedding
76
+ pip install "spectraltm-db[langchain]" # langchain_core VectorStore adapter
77
+ pip install "spectraltm-db[llamaindex]" # llama-index VectorStore adapter
78
+ pip install "spectraltm-db[server]" # FastAPI REST server (11 endpoints)
79
+ pip install "spectraltm-db[all]" # everything
80
+ ```
81
+
82
+ ## Quick start
83
+
84
+ ```python
85
+ import spectraltm_db as stm
86
+
87
+ # Calibration sample: 1,000-10,000 random vectors of dim `dimension`.
88
+ # Calibrates the SSE encoder's magnitude/phase quantization grids.
89
+ calibration = [random.gauss(0, 1) for _ in range(2000 * 384)]
90
+
91
+ idx = stm.Index.create(
92
+ name="conversations",
93
+ path="~/.spectraltm/conversations",
94
+ dimension=384,
95
+ compression="spectral_k64", # or spectral_k128 / spectral_k256 / float32
96
+ calibration_sample=calibration,
97
+ )
98
+
99
+ # Upsert some vectors (Pinecone-style dicts)
100
+ idx.upsert(vectors=[
101
+ {"id": "turn_001",
102
+ "values": [...], # length-384 list of floats
103
+ "metadata": {"session_id": "abc", "role": "user"}},
104
+ {"id": "turn_002",
105
+ "values": [...],
106
+ "metadata": {"session_id": "abc", "role": "assistant"}},
107
+ ])
108
+
109
+ # Pinecone-shape query
110
+ results = idx.query(
111
+ vector=[...], # length-384 list
112
+ top_k=10,
113
+ filter={"session_id": {"$eq": "abc"}}, # metadata filter
114
+ )
115
+ for m in results["matches"]:
116
+ print(m["id"], m["score"], m["metadata"])
117
+
118
+ # Reopen after process restart
119
+ idx.flush()
120
+ idx2 = stm.Index.open("~/.spectraltm/conversations")
121
+ ```
122
+
123
+ See `examples/rag_demo.py` for a runnable end-to-end example.
124
+
125
+ ## Benchmarks — measured at v0.1.0.dev0 (median, top_k=10, dim=384)
126
+
127
+ Run via `python -m spectraltm_db.examples.benchmark`. Ingest uses the bulk
128
+ `add_batch` Rust path; query latency is single-threaded.
129
+
130
+ | N | K | dim | bytes/chunk | total MB | ms/query (median) | ms/query (p95) | ms/query (p99) | ingest (s) |
131
+ |----------|----|-----|-------------|----------|-------------------|----------------|----------------|------------|
132
+ | 10 000 | 64 | 384 | 192 | 1.83 | **7.29 ms** | 9.24 ms | 14.31 ms | ~10 s |
133
+ | 100 000 | 64 | 384 | 192 | 18.3 | **86.43 ms** | 93.88 ms | 95.50 ms | ~451 s |
134
+
135
+ Honest framing:
136
+
137
+ - **Search latency scales linearly with N at AVX2 throughput** (~12× slower
138
+ for 10× more data). The n=1 corner case is handled by Rust `score_one`
139
+ or NumPy fallback when the binding isn't present.
140
+ - **Ingest is dominated by per-vector rFFT encoding.** Each new vector
141
+ pays an O(F log F) encoding pass; the bulk `add_batch` path amortizes
142
+ Python→Rust overhead at 1.4 ms/vector but cannot skip the encoding.
143
+ The fully-vectorized "load_codes" path (accepting pre-quantized codes)
144
+ is on the v0.2 roadmap and is what unlocks billion-vector scale.
145
+ - **`spectraltm-db` is a lossy compressed index, not a brute-force
146
+ cosine replacement.** See `spectraltm`'s BEIR numbers (K=8 loses ~65%
147
+ nDCG, K=64 ~12%) for the quality curve. Your choice of K is a
148
+ storage-budget / quality-bar tradeoff.
149
+
150
+ ## When to use spectraltm-db
151
+
152
+ Use it when:
153
+
154
+ - You want a **Pinecone-shaped API** without a managed service: RAG,
155
+ conversation memory, semantic search — anything you'd point at a
156
+ Pinecone index and don't want cloud cost or egress.
157
+ - Your corpus fits on a single machine and on the order of N ≤ 1M
158
+ vectors (above which encoding dominates ingest).
159
+ - You value **single-tenant, on-disk persistence**: no cluster, no
160
+ replicas, just a folder on disk that you can `cp`, `rsync`, or
161
+ back up however you like.
162
+
163
+ Don't use it when:
164
+
165
+ - You need real Pinecone parity in **multi-region / serverless
166
+ autoscaling / RBAC / backups** — that's v0.2+.
167
+ - You need **sparse-dense hybrid ranking** with actual BM25/Reciprocal
168
+ Rank Fusion — wire surface only in v0.1, scoring lands in v0.2.
169
+ - You need **billion-vector scale** — the AVX2 inner loop scales
170
+ linearly with N; ingest cost dominates above ~1M without a pre-coded
171
+ bulk-load path.
172
+ - You need **multi-process writers** — single-process at a time;
173
+ multi-reader via SQLite WAL is fine; threaded HTTP works in-process.
174
+
175
+ ## Project layout
176
+
177
+ ```
178
+ spectraltm_db/
179
+ ├── spectraltm_db/
180
+ │ ├── __init__.py # Index / IndexConfig / errors
181
+ │ ├── __main__.py # CLI entry point
182
+ │ ├── config.py # IndexConfig + CompressionSpec + MetricSpec
183
+ │ ├── errors.py # exception hierarchy
184
+ │ ├── index.py # Index — Pinecone-shape public API
185
+ │ ├── wal.py # minimal JSONL write-ahead log
186
+ │ ├── sparse.py # Sparse-dense wire surface (v0.2 stub)
187
+ │ ├── server.py # FastAPI REST server (optional)
188
+ │ ├── .github/workflows/test.yml # CI
189
+ │ ├── storage/
190
+ │ │ ├── vector_store.py # wraps spectraltm.SpectralIndex
191
+ │ │ ├── id_map.py # str-id ↔ chunk_id bijection
192
+ │ │ ├── metadata_store.py # SQLite metadata + dynamic indexes
193
+ │ │ └── namespaces.py # directory partitioning
194
+ │ ├── retrieval/
195
+ │ │ ├── filter_compiler.py # dict → SQL
196
+ │ │ └── filter_executor.py # SQL → chunk_id set
197
+ │ ├── integrations/
198
+ │ │ ├── langchain.py # VectorStore adapter
199
+ │ │ └── llamaindex.py # VectorStore adapter
200
+ │ └── examples/
201
+ │ ├── smoke_test.py
202
+ │ ├── rag_demo.py
203
+ │ └── benchmark.py
204
+ ├── tests/ # 107 tests (3 conditional skips for optional Rust binding)
205
+ ├── pyproject.toml # pure-python; depends on spectraltm from PyPI
206
+ ├── README.md
207
+ ├── CHANGELOG.md
208
+ ├── PUBLISH.md # how to publish to PyPI
209
+ └── LICENSE # Apache-2.0
210
+ ```
211
+
212
+ ## How It Works
213
+
214
+ ```
215
+ embeddings ─┐
216
+ ├─► [encoder.calibrate] ─► quantizer grids (mags, phases, norms)
217
+
218
+ ├─► [encoder.encode] ─► SpectralCodes (idx, mag_q, phase_q, norm_q)
219
+
220
+ └─► [vector_store.add_batch] ─► Rust add_embeddings ─► dense (N,F) mags + phases
221
+
222
+ queries ──┬─► [filter_compiler] ─► SQL chunk_id whitelist (when filter present)
223
+
224
+ ├─► [encoder.encode] ─► query SpectralCodes
225
+
226
+ └─► [SpectralIndex.search] ─► AVX2 SIMD inner loop ─► top-K cosine scores
227
+
228
+ └─► [metadata_store.hydrate] ─► Pinecone-shaped response
229
+ ```
230
+
231
+ The hot path is the Rust `SpectralIndex.search` (AVX2 SIMD on x86_64,
232
+ scalar fallback elsewhere). Filter pre-narrowing happens in SQLite
233
+ before we hand the candidate set to SSE; this matches the Pinecone
234
+ data plane, where `filter` runs before scoring. n=1 uses an optional
235
+ Rust `score_one` binding to bypass `select_nth_unstable_by` (which would
236
+ panic for `top_k >= n`).
237
+
238
+ ## Development
239
+
240
+ ```bash
241
+ # Editable install (Pure-Python) — pulls spectraltm from PyPI:
242
+ pip install -e ".[all]"
243
+
244
+ # Run the test suite:
245
+ pytest tests/ -v
246
+
247
+ # Reinstall the built wheel:
248
+ pip install --force-reinstall --no-deps dist/spectraltm_db-*-py3-none-any.whl
249
+
250
+ # Smoke CLI:
251
+ python -m spectraltm_db --help
252
+ ```
253
+
254
+ For the optional `score_one` Rust binding path, you need a local build
255
+ of `spectraltm>=0.1.3` (workspace has the Rust patch; release to
256
+ PyPI is on the v0.2 roadmap). Until then, `VectorStore.search` falls
257
+ back to a NumPy dot product for the n=1 corner.
258
+
259
+ See [`PUBLISH.md`](PUBLISH.md) for the PyPI release flow.
260
+
261
+ ## Citation
262
+
263
+ ```
264
+ @misc{mckenzie2026spectraldb,
265
+ title={spectraltm-db — Pinecone-shape local vector database on Spectral encoding},
266
+ author={Mc Kenzie, Gerald Enrique Nelson},
267
+ year={2026},
268
+ month={6},
269
+ day={29},
270
+ howpublished={Companion to spectraltm (Sparse Spectral Encoding)},
271
+ license={Apache-2.0},
272
+ note={Uses spectraltm https://pypi.org/project/spectraltm/ as the underlying engine.}
273
+ }
274
+ ```
275
+
276
+ **Metadata**
277
+
278
+ - **Author:** Gerald Enrique Nelson Mc Kenzie
279
+ - **Date:** 2026-06-29
280
+ - **Repository:** [github.com/lordxmen2k/sparse-spectral-encoding](https://github.com/lordxmen2k/sparse-spectral-encoding)
281
+ - **Engine:** [spectraltm](https://pypi.org/project/spectraltm/) on PyPI
282
+ - **License:** Apache License 2.0
283
+ - **Contact:** lordxmen2k@gmail.com
284
+
285
+ ## License
286
+
287
+ Apache-2.0 — see [LICENSE](LICENSE).
288
+
289
+ ---
290
+
291
+ Built as a Pinecone-shape wrapper around the [`spectraltm`](https://pypi.org/project/spectraltm/)
292
+ crate. The two projects share zero source code per the explicit
293
+ separation rule; the only cross-project coupling is the `spectraltm`
294
+ PyPI dependency.