oniondb 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.
- oniondb-0.1.0/LICENSE +21 -0
- oniondb-0.1.0/PKG-INFO +206 -0
- oniondb-0.1.0/README.md +176 -0
- oniondb-0.1.0/oniondb/__init__.py +9 -0
- oniondb-0.1.0/oniondb/onion_db.py +980 -0
- oniondb-0.1.0/oniondb/py.typed +1 -0
- oniondb-0.1.0/oniondb.egg-info/PKG-INFO +206 -0
- oniondb-0.1.0/oniondb.egg-info/SOURCES.txt +12 -0
- oniondb-0.1.0/oniondb.egg-info/dependency_links.txt +1 -0
- oniondb-0.1.0/oniondb.egg-info/requires.txt +4 -0
- oniondb-0.1.0/oniondb.egg-info/top_level.txt +1 -0
- oniondb-0.1.0/pyproject.toml +45 -0
- oniondb-0.1.0/setup.cfg +4 -0
- oniondb-0.1.0/tests/test_oniondb.py +389 -0
oniondb-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nick Sveler
|
|
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.
|
oniondb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oniondb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A geometric memory database with importance-stratified shells and zero dependencies.
|
|
5
|
+
Author: Nick Sveler
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Niksveler/oniondb
|
|
8
|
+
Project-URL: Documentation, https://github.com/Niksveler/oniondb#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/Niksveler/oniondb/issues
|
|
10
|
+
Keywords: database,geometric,memory,vector,embeddings,importance,hierarchical,sqlite,shell,retrieval
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Intended Audience :: Developers
|
|
22
|
+
Classifier: Development Status :: 3 - Alpha
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ๐ง
OnionDB
|
|
32
|
+
|
|
33
|
+
**A geometric memory database. Zero dependencies. Importance-stratified.**
|
|
34
|
+
|
|
35
|
+
Your data has a *location*, not just a vector.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
OnionDB organizes data in concentric shells โ like layers of an onion. Every record has a 4-part geometric address `(gap, ฮธ, ฯ, depth)` based on its importance and semantic content. This enables queries that flat vector databases can't do:
|
|
40
|
+
|
|
41
|
+
- **"Show me everything at importance level 3"** โ shell scan
|
|
42
|
+
- **"Drill through ALL importance levels at this semantic direction"** โ GRF (Geometric Ray Filter)
|
|
43
|
+
- **"Trace how this topic connects across depth levels"** โ reverse ray
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
โญโโโโโโโโโโโโโโโโโโโฎ
|
|
47
|
+
โฑ gap 4 (trivial) โฒ
|
|
48
|
+
โฑ โญโโโโโโโโโโโโโโโฎ โฒ
|
|
49
|
+
โฑ โฑ gap 3 (low) โฒ โฒ
|
|
50
|
+
โฑ โฑ โญโโโโโโโโโโโฎ โฒ โฒ
|
|
51
|
+
โฑ โฑ โฑ gap 2 (mid) โฒ โฒ โฒ
|
|
52
|
+
โฑ โฑ โฑ โญโโโโโโโโโฎ โฒ โฒ โฒ
|
|
53
|
+
โ โ โ โ gap 1 โ โ โ โ
|
|
54
|
+
โ โ โ โ โญโโโโโฎ โ โ โ โ
|
|
55
|
+
โ โ โ โ โ g0 โ โ โ โ โ โ GRF drills through ALL layers
|
|
56
|
+
โ โ โ โ โcoreโ โ โ โ โ at angle (ฮธ, ฯ)
|
|
57
|
+
โ โ โ โ โฐโโโโโฏ โ โ โ โ
|
|
58
|
+
โ โ โ โฐโโโโโโโโโโโฏ โ โ โ
|
|
59
|
+
โฒ โฒ โฒ________________โฑ โฑ โฑ
|
|
60
|
+
โฒ โฒ______________________โฑ โฑ
|
|
61
|
+
โฒ____________________________โฑ
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install oniondb
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from oniondb import OnionDB
|
|
74
|
+
|
|
75
|
+
# Create a database (SQLite file, zero config)
|
|
76
|
+
db = OnionDB("my_memories.db")
|
|
77
|
+
|
|
78
|
+
# Insert with importance (determines which shell)
|
|
79
|
+
db.insert("idea-1", "The Earth orbits the Sun", importance=0.9)
|
|
80
|
+
db.insert("idea-2", "I had coffee this morning", importance=0.3)
|
|
81
|
+
db.insert("idea-3", "E=mcยฒ defines mass-energy equivalence", importance=0.99)
|
|
82
|
+
|
|
83
|
+
# Shell scan โ everything at importance level 0 (core memories)
|
|
84
|
+
core = db.shell_scan(gap=0)
|
|
85
|
+
|
|
86
|
+
# GRF โ drill through ALL shells at a direction
|
|
87
|
+
# (requires embeddings for semantic direction)
|
|
88
|
+
profile = db.grf(theta=45.0, phi=10.0, query_embedding=my_embedding)
|
|
89
|
+
|
|
90
|
+
# Reverse ray โ follow semantic gravity inward
|
|
91
|
+
trace = db.reverse_ray(start_embedding=my_embedding)
|
|
92
|
+
print(f"Path curvature: {trace['curvature']}ยฐ") # 0=straight, high=fragmented
|
|
93
|
+
|
|
94
|
+
# Count, get, delete
|
|
95
|
+
print(db.count()) # 3
|
|
96
|
+
print(db.get("idea-1")) # full memory dict
|
|
97
|
+
db.delete("idea-2") # True
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Features
|
|
101
|
+
|
|
102
|
+
| Feature | Description |
|
|
103
|
+
|---------|------------|
|
|
104
|
+
| **Zero dependencies** | stdlib only โ `sqlite3`, `math`, `struct`, `json`, `os` |
|
|
105
|
+
| **Geometric addressing** | Every record has a location: `(gap, ฮธ, ฯ, depth)` |
|
|
106
|
+
| **Importance shells** | Data stratified by significance โ core vs trivial |
|
|
107
|
+
| **6 query operations** | horizontal, GRF, reverse_ray, temporal_grf, shell_scan, range_scan |
|
|
108
|
+
| **Embedding-agnostic** | Works with any embedding model (OpenAI, Ollama, sentence-transformers...) |
|
|
109
|
+
| **Single-file storage** | SQLite-backed, portable, copy-paste deployable |
|
|
110
|
+
| **Self-calibrating** | `fit_projection()` builds PCA from your data automatically |
|
|
111
|
+
| **Thread-safe** | WAL mode + `check_same_thread=False` |
|
|
112
|
+
|
|
113
|
+
## The Signature Query: GRF (Geometric Ray Filter)
|
|
114
|
+
|
|
115
|
+
The GRF is what makes OnionDB unique. It "drills a core sample" through every importance shell at a given semantic direction, returning a **depth profile** of how a topic exists at every level of significance.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# With embeddings: semantic direction from the embedding
|
|
119
|
+
profile = db.grf(theta=0, phi=0, query_embedding=embedding, k_per_gap=5)
|
|
120
|
+
# Returns: {0: [core memories], 1: [important], 2: [mid], 3: [low], 4: [trivial]}
|
|
121
|
+
|
|
122
|
+
# The reverse ray follows semantic gravity inward, bending as it goes
|
|
123
|
+
trace = db.reverse_ray(start_embedding=embedding)
|
|
124
|
+
# trace["curvature"] โ total angular deviation
|
|
125
|
+
# trace["straight"] โ True if topic is well-organized across all depths
|
|
126
|
+
# trace["path"] โ list of hops from outer to inner shells
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Using with Embeddings
|
|
130
|
+
|
|
131
|
+
OnionDB works with or without embeddings. Without them, queries use angular distance. With them, queries use cosine similarity for precise semantic ranking.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
# Any embedding model works โ just pass a list of floats
|
|
135
|
+
from sentence_transformers import SentenceTransformer
|
|
136
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
137
|
+
|
|
138
|
+
embedding = model.encode("quantum physics").tolist()
|
|
139
|
+
db.insert("q1", "Quantum entanglement is spooky", importance=0.8, embedding=embedding)
|
|
140
|
+
|
|
141
|
+
# After inserting enough data, calibrate the projection
|
|
142
|
+
stats = db.fit_projection()
|
|
143
|
+
print(f"Cell occupancy: {stats['occupancy_after']:.0%}") # target: >80%
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## API Reference
|
|
147
|
+
|
|
148
|
+
### Core Operations
|
|
149
|
+
|
|
150
|
+
| Method | Description |
|
|
151
|
+
|--------|-------------|
|
|
152
|
+
| `insert(id, content, importance, ...)` | Insert a record with auto-computed geometric address |
|
|
153
|
+
| `get(id)` | Retrieve a record by ID |
|
|
154
|
+
| `delete(id)` | Delete a record by ID |
|
|
155
|
+
| `count(gap=None)` | Count records (optionally per gap) |
|
|
156
|
+
| `batch_insert(items)` | Insert multiple records efficiently |
|
|
157
|
+
|
|
158
|
+
### Query Operations
|
|
159
|
+
|
|
160
|
+
| Method | Description |
|
|
161
|
+
|--------|-------------|
|
|
162
|
+
| `horizontal(gap, theta, phi, ...)` | Find nearby items within one shell |
|
|
163
|
+
| `grf(theta, phi, ...)` | **Geometric Ray Filter** โ drill through all shells |
|
|
164
|
+
| `reverse_ray(start_embedding, ...)` | Curved semantic trace from outer to inner |
|
|
165
|
+
| `temporal_grf(theta, phi, ...)` | Drill through time-based shells |
|
|
166
|
+
| `shell_scan(gap, limit)` | Return everything at one importance level |
|
|
167
|
+
| `range_scan(gap_start, gap_end, limit)` | Return everything between two levels |
|
|
168
|
+
|
|
169
|
+
### Configuration
|
|
170
|
+
|
|
171
|
+
| Method | Description |
|
|
172
|
+
|--------|-------------|
|
|
173
|
+
| `fit_projection(save=True)` | Self-calibrate PCA from stored embeddings |
|
|
174
|
+
| `stats()` | Database statistics (gaps, categories, grid) |
|
|
175
|
+
| `cell_density(gap)` | Cell occupancy map for a gap |
|
|
176
|
+
|
|
177
|
+
### Custom Boundaries
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# Default: 5 shells at [0.95, 0.85, 0.70, 0.50, 0.00]
|
|
181
|
+
db = OnionDB("custom.db", boundaries=[0.90, 0.70, 0.40, 0.00]) # 4 shells
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## How It Works
|
|
185
|
+
|
|
186
|
+
1. **Importance โ Gap**: Each record's importance score determines which shell (gap) it lives in. Gap 0 is the innermost core (most important).
|
|
187
|
+
|
|
188
|
+
2. **Embedding โ Angles**: If an embedding is provided, PCA projects it onto spherical coordinates (ฮธ, ฯ). This gives semantically similar items nearby angular positions.
|
|
189
|
+
|
|
190
|
+
3. **Address**: Every record gets a 4-part address: `(gap, ฮธ, ฯ, depth)` where depth is the position within the gap based on exact importance.
|
|
191
|
+
|
|
192
|
+
4. **Cells**: The sphere is divided into a 12ร6 grid. Queries search the target cell plus neighbors for efficiency.
|
|
193
|
+
|
|
194
|
+
## Comparison
|
|
195
|
+
|
|
196
|
+
| | OnionDB | FAISS | ChromaDB | Pinecone | pgvector |
|
|
197
|
+
|---|---------|-------|----------|----------|----------|
|
|
198
|
+
| Dependencies | **0** | numpy | many | cloud SDK | PostgreSQL |
|
|
199
|
+
| Importance hierarchy | **โ
native** | โ | โ | โ metadata | โ |
|
|
200
|
+
| Geometric queries | **โ
GRF, ray** | โ | โ | โ | โ |
|
|
201
|
+
| Storage | SQLite file | memory/file | SQLite | cloud | server |
|
|
202
|
+
| Setup | `pip install` | `pip install` | `pip install` | API key | DB server |
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT โ do whatever you want with it.
|
oniondb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# ๐ง
OnionDB
|
|
2
|
+
|
|
3
|
+
**A geometric memory database. Zero dependencies. Importance-stratified.**
|
|
4
|
+
|
|
5
|
+
Your data has a *location*, not just a vector.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
OnionDB organizes data in concentric shells โ like layers of an onion. Every record has a 4-part geometric address `(gap, ฮธ, ฯ, depth)` based on its importance and semantic content. This enables queries that flat vector databases can't do:
|
|
10
|
+
|
|
11
|
+
- **"Show me everything at importance level 3"** โ shell scan
|
|
12
|
+
- **"Drill through ALL importance levels at this semantic direction"** โ GRF (Geometric Ray Filter)
|
|
13
|
+
- **"Trace how this topic connects across depth levels"** โ reverse ray
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
โญโโโโโโโโโโโโโโโโโโโฎ
|
|
17
|
+
โฑ gap 4 (trivial) โฒ
|
|
18
|
+
โฑ โญโโโโโโโโโโโโโโโฎ โฒ
|
|
19
|
+
โฑ โฑ gap 3 (low) โฒ โฒ
|
|
20
|
+
โฑ โฑ โญโโโโโโโโโโโฎ โฒ โฒ
|
|
21
|
+
โฑ โฑ โฑ gap 2 (mid) โฒ โฒ โฒ
|
|
22
|
+
โฑ โฑ โฑ โญโโโโโโโโโฎ โฒ โฒ โฒ
|
|
23
|
+
โ โ โ โ gap 1 โ โ โ โ
|
|
24
|
+
โ โ โ โ โญโโโโโฎ โ โ โ โ
|
|
25
|
+
โ โ โ โ โ g0 โ โ โ โ โ โ GRF drills through ALL layers
|
|
26
|
+
โ โ โ โ โcoreโ โ โ โ โ at angle (ฮธ, ฯ)
|
|
27
|
+
โ โ โ โ โฐโโโโโฏ โ โ โ โ
|
|
28
|
+
โ โ โ โฐโโโโโโโโโโโฏ โ โ โ
|
|
29
|
+
โฒ โฒ โฒ________________โฑ โฑ โฑ
|
|
30
|
+
โฒ โฒ______________________โฑ โฑ
|
|
31
|
+
โฒ____________________________โฑ
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install oniondb
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from oniondb import OnionDB
|
|
44
|
+
|
|
45
|
+
# Create a database (SQLite file, zero config)
|
|
46
|
+
db = OnionDB("my_memories.db")
|
|
47
|
+
|
|
48
|
+
# Insert with importance (determines which shell)
|
|
49
|
+
db.insert("idea-1", "The Earth orbits the Sun", importance=0.9)
|
|
50
|
+
db.insert("idea-2", "I had coffee this morning", importance=0.3)
|
|
51
|
+
db.insert("idea-3", "E=mcยฒ defines mass-energy equivalence", importance=0.99)
|
|
52
|
+
|
|
53
|
+
# Shell scan โ everything at importance level 0 (core memories)
|
|
54
|
+
core = db.shell_scan(gap=0)
|
|
55
|
+
|
|
56
|
+
# GRF โ drill through ALL shells at a direction
|
|
57
|
+
# (requires embeddings for semantic direction)
|
|
58
|
+
profile = db.grf(theta=45.0, phi=10.0, query_embedding=my_embedding)
|
|
59
|
+
|
|
60
|
+
# Reverse ray โ follow semantic gravity inward
|
|
61
|
+
trace = db.reverse_ray(start_embedding=my_embedding)
|
|
62
|
+
print(f"Path curvature: {trace['curvature']}ยฐ") # 0=straight, high=fragmented
|
|
63
|
+
|
|
64
|
+
# Count, get, delete
|
|
65
|
+
print(db.count()) # 3
|
|
66
|
+
print(db.get("idea-1")) # full memory dict
|
|
67
|
+
db.delete("idea-2") # True
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Features
|
|
71
|
+
|
|
72
|
+
| Feature | Description |
|
|
73
|
+
|---------|------------|
|
|
74
|
+
| **Zero dependencies** | stdlib only โ `sqlite3`, `math`, `struct`, `json`, `os` |
|
|
75
|
+
| **Geometric addressing** | Every record has a location: `(gap, ฮธ, ฯ, depth)` |
|
|
76
|
+
| **Importance shells** | Data stratified by significance โ core vs trivial |
|
|
77
|
+
| **6 query operations** | horizontal, GRF, reverse_ray, temporal_grf, shell_scan, range_scan |
|
|
78
|
+
| **Embedding-agnostic** | Works with any embedding model (OpenAI, Ollama, sentence-transformers...) |
|
|
79
|
+
| **Single-file storage** | SQLite-backed, portable, copy-paste deployable |
|
|
80
|
+
| **Self-calibrating** | `fit_projection()` builds PCA from your data automatically |
|
|
81
|
+
| **Thread-safe** | WAL mode + `check_same_thread=False` |
|
|
82
|
+
|
|
83
|
+
## The Signature Query: GRF (Geometric Ray Filter)
|
|
84
|
+
|
|
85
|
+
The GRF is what makes OnionDB unique. It "drills a core sample" through every importance shell at a given semantic direction, returning a **depth profile** of how a topic exists at every level of significance.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# With embeddings: semantic direction from the embedding
|
|
89
|
+
profile = db.grf(theta=0, phi=0, query_embedding=embedding, k_per_gap=5)
|
|
90
|
+
# Returns: {0: [core memories], 1: [important], 2: [mid], 3: [low], 4: [trivial]}
|
|
91
|
+
|
|
92
|
+
# The reverse ray follows semantic gravity inward, bending as it goes
|
|
93
|
+
trace = db.reverse_ray(start_embedding=embedding)
|
|
94
|
+
# trace["curvature"] โ total angular deviation
|
|
95
|
+
# trace["straight"] โ True if topic is well-organized across all depths
|
|
96
|
+
# trace["path"] โ list of hops from outer to inner shells
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Using with Embeddings
|
|
100
|
+
|
|
101
|
+
OnionDB works with or without embeddings. Without them, queries use angular distance. With them, queries use cosine similarity for precise semantic ranking.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
# Any embedding model works โ just pass a list of floats
|
|
105
|
+
from sentence_transformers import SentenceTransformer
|
|
106
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
107
|
+
|
|
108
|
+
embedding = model.encode("quantum physics").tolist()
|
|
109
|
+
db.insert("q1", "Quantum entanglement is spooky", importance=0.8, embedding=embedding)
|
|
110
|
+
|
|
111
|
+
# After inserting enough data, calibrate the projection
|
|
112
|
+
stats = db.fit_projection()
|
|
113
|
+
print(f"Cell occupancy: {stats['occupancy_after']:.0%}") # target: >80%
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## API Reference
|
|
117
|
+
|
|
118
|
+
### Core Operations
|
|
119
|
+
|
|
120
|
+
| Method | Description |
|
|
121
|
+
|--------|-------------|
|
|
122
|
+
| `insert(id, content, importance, ...)` | Insert a record with auto-computed geometric address |
|
|
123
|
+
| `get(id)` | Retrieve a record by ID |
|
|
124
|
+
| `delete(id)` | Delete a record by ID |
|
|
125
|
+
| `count(gap=None)` | Count records (optionally per gap) |
|
|
126
|
+
| `batch_insert(items)` | Insert multiple records efficiently |
|
|
127
|
+
|
|
128
|
+
### Query Operations
|
|
129
|
+
|
|
130
|
+
| Method | Description |
|
|
131
|
+
|--------|-------------|
|
|
132
|
+
| `horizontal(gap, theta, phi, ...)` | Find nearby items within one shell |
|
|
133
|
+
| `grf(theta, phi, ...)` | **Geometric Ray Filter** โ drill through all shells |
|
|
134
|
+
| `reverse_ray(start_embedding, ...)` | Curved semantic trace from outer to inner |
|
|
135
|
+
| `temporal_grf(theta, phi, ...)` | Drill through time-based shells |
|
|
136
|
+
| `shell_scan(gap, limit)` | Return everything at one importance level |
|
|
137
|
+
| `range_scan(gap_start, gap_end, limit)` | Return everything between two levels |
|
|
138
|
+
|
|
139
|
+
### Configuration
|
|
140
|
+
|
|
141
|
+
| Method | Description |
|
|
142
|
+
|--------|-------------|
|
|
143
|
+
| `fit_projection(save=True)` | Self-calibrate PCA from stored embeddings |
|
|
144
|
+
| `stats()` | Database statistics (gaps, categories, grid) |
|
|
145
|
+
| `cell_density(gap)` | Cell occupancy map for a gap |
|
|
146
|
+
|
|
147
|
+
### Custom Boundaries
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Default: 5 shells at [0.95, 0.85, 0.70, 0.50, 0.00]
|
|
151
|
+
db = OnionDB("custom.db", boundaries=[0.90, 0.70, 0.40, 0.00]) # 4 shells
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## How It Works
|
|
155
|
+
|
|
156
|
+
1. **Importance โ Gap**: Each record's importance score determines which shell (gap) it lives in. Gap 0 is the innermost core (most important).
|
|
157
|
+
|
|
158
|
+
2. **Embedding โ Angles**: If an embedding is provided, PCA projects it onto spherical coordinates (ฮธ, ฯ). This gives semantically similar items nearby angular positions.
|
|
159
|
+
|
|
160
|
+
3. **Address**: Every record gets a 4-part address: `(gap, ฮธ, ฯ, depth)` where depth is the position within the gap based on exact importance.
|
|
161
|
+
|
|
162
|
+
4. **Cells**: The sphere is divided into a 12ร6 grid. Queries search the target cell plus neighbors for efficiency.
|
|
163
|
+
|
|
164
|
+
## Comparison
|
|
165
|
+
|
|
166
|
+
| | OnionDB | FAISS | ChromaDB | Pinecone | pgvector |
|
|
167
|
+
|---|---------|-------|----------|----------|----------|
|
|
168
|
+
| Dependencies | **0** | numpy | many | cloud SDK | PostgreSQL |
|
|
169
|
+
| Importance hierarchy | **โ
native** | โ | โ | โ metadata | โ |
|
|
170
|
+
| Geometric queries | **โ
GRF, ray** | โ | โ | โ | โ |
|
|
171
|
+
| Storage | SQLite file | memory/file | SQLite | cloud | server |
|
|
172
|
+
| Setup | `pip install` | `pip install` | `pip install` | API key | DB server |
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT โ do whatever you want with it.
|