Skip to main content

A geometric memory database with importance-stratified shells and zero dependencies.

Project description

๐Ÿง… OnionDB

A geometric memory database. Zero dependencies. Importance-stratified.

Your data has a location, not just a vector.


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:

  • "Show me everything at importance level 3" โ†’ shell scan
  • "Drill through ALL importance levels at this semantic direction" โ†’ GRF (Geometric Ray Filter)
  • "Trace how this topic connects across depth levels" โ†’ reverse ray
         โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
        โ•ฑ   gap 4 (trivial)  โ•ฒ
       โ•ฑ  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ•ฒ
      โ•ฑ  โ•ฑ  gap 3 (low)   โ•ฒ    โ•ฒ
     โ•ฑ  โ•ฑ  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ•ฒ    โ•ฒ
    โ•ฑ  โ•ฑ  โ•ฑ  gap 2 (mid) โ•ฒ    โ•ฒ    โ•ฒ
   โ•ฑ  โ•ฑ  โ•ฑ  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ•ฒ    โ•ฒ    โ•ฒ
  โ”‚  โ”‚  โ”‚  โ”‚ gap 1    โ”‚    โ”‚    โ”‚    โ”‚
  โ”‚  โ”‚  โ”‚  โ”‚ โ•ญโ”€โ”€โ”€โ”€โ•ฎ   โ”‚    โ”‚    โ”‚    โ”‚
  โ”‚  โ”‚  โ”‚  โ”‚ โ”‚ g0 โ”‚   โ”‚    โ”‚    โ”‚    โ”‚   โ† GRF drills through ALL layers
  โ”‚  โ”‚  โ”‚  โ”‚ โ”‚coreโ”‚   โ”‚    โ”‚    โ”‚    โ”‚     at angle (ฮธ, ฯ†)
  โ”‚  โ”‚  โ”‚  โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ•ฏ   โ”‚    โ”‚    โ”‚    โ”‚
  โ”‚  โ”‚  โ”‚  โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ    โ”‚    โ”‚    โ”‚
   โ•ฒ  โ•ฒ  โ•ฒ________________โ•ฑ    โ•ฑ    โ•ฑ
    โ•ฒ  โ•ฒ______________________โ•ฑ    โ•ฑ
     โ•ฒ____________________________โ•ฑ

Install

pip install oniondb

Quick Start

from oniondb import OnionDB

# Create a database (SQLite file, zero config)
db = OnionDB("my_memories.db")

# Insert with importance (determines which shell)
db.insert("idea-1", "The Earth orbits the Sun", importance=0.9)
db.insert("idea-2", "I had coffee this morning", importance=0.3)
db.insert("idea-3", "E=mcยฒ defines mass-energy equivalence", importance=0.99)

# Shell scan โ€” everything at importance level 0 (core memories)
core = db.shell_scan(gap=0)

# GRF โ€” drill through ALL shells at a direction
# (requires embeddings for semantic direction)
profile = db.grf(theta=45.0, phi=10.0, query_embedding=my_embedding)

# Reverse ray โ€” follow semantic gravity inward
trace = db.reverse_ray(start_embedding=my_embedding)
print(f"Path curvature: {trace['curvature']}ยฐ")  # 0=straight, high=fragmented

# Count, get, delete
print(db.count())        # 3
print(db.get("idea-1"))  # full memory dict
db.delete("idea-2")      # True

Features

Feature Description
Zero dependencies stdlib only โ€” sqlite3, math, struct, json, os
Geometric addressing Every record has a location: (gap, ฮธ, ฯ†, depth)
Importance shells Data stratified by significance โ€” core vs trivial
6 query operations horizontal, GRF, reverse_ray, temporal_grf, shell_scan, range_scan
Embedding-agnostic Works with any embedding model (OpenAI, Ollama, sentence-transformers...)
Single-file storage SQLite-backed, portable, copy-paste deployable
Self-calibrating fit_projection() builds PCA from your data automatically
Thread-safe WAL mode + check_same_thread=False

The Signature Query: GRF (Geometric Ray Filter)

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.

# With embeddings: semantic direction from the embedding
profile = db.grf(theta=0, phi=0, query_embedding=embedding, k_per_gap=5)
# Returns: {0: [core memories], 1: [important], 2: [mid], 3: [low], 4: [trivial]}

# The reverse ray follows semantic gravity inward, bending as it goes
trace = db.reverse_ray(start_embedding=embedding)
# trace["curvature"] โ€” total angular deviation
# trace["straight"]  โ€” True if topic is well-organized across all depths
# trace["path"]      โ€” list of hops from outer to inner shells

Using with Embeddings

OnionDB works with or without embeddings. Without them, queries use angular distance. With them, queries use cosine similarity for precise semantic ranking.

# Any embedding model works โ€” just pass a list of floats
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")

embedding = model.encode("quantum physics").tolist()
db.insert("q1", "Quantum entanglement is spooky", importance=0.8, embedding=embedding)

# After inserting enough data, calibrate the projection
stats = db.fit_projection()
print(f"Cell occupancy: {stats['occupancy_after']:.0%}")  # target: >80%

API Reference

Core Operations

Method Description
insert(id, content, importance, ...) Insert a record with auto-computed geometric address
get(id) Retrieve a record by ID
delete(id) Delete a record by ID
count(gap=None) Count records (optionally per gap)
batch_insert(items) Insert multiple records efficiently

Query Operations

Method Description
horizontal(gap, theta, phi, ...) Find nearby items within one shell
grf(theta, phi, ...) Geometric Ray Filter โ€” drill through all shells
reverse_ray(start_embedding, ...) Curved semantic trace from outer to inner
temporal_grf(theta, phi, ...) Drill through time-based shells
shell_scan(gap, limit) Return everything at one importance level
range_scan(gap_start, gap_end, limit) Return everything between two levels

Configuration

Method Description
fit_projection(save=True) Self-calibrate PCA from stored embeddings
stats() Database statistics (gaps, categories, grid)
cell_density(gap) Cell occupancy map for a gap

Custom Boundaries

# Default: 5 shells at [0.95, 0.85, 0.70, 0.50, 0.00]
db = OnionDB("custom.db", boundaries=[0.90, 0.70, 0.40, 0.00])  # 4 shells

How It Works

  1. Importance โ†’ Gap: Each record's importance score determines which shell (gap) it lives in. Gap 0 is the innermost core (most important).

  2. Embedding โ†’ Angles: If an embedding is provided, PCA projects it onto spherical coordinates (ฮธ, ฯ†). This gives semantically similar items nearby angular positions.

  3. Address: Every record gets a 4-part address: (gap, ฮธ, ฯ†, depth) where depth is the position within the gap based on exact importance.

  4. Cells: The sphere is divided into a 12ร—6 grid. Queries search the target cell plus neighbors for efficiency.

Comparison

OnionDB FAISS ChromaDB Pinecone pgvector
Dependencies 0 numpy many cloud SDK PostgreSQL
Importance hierarchy โœ… native โŒ โŒ โŒ metadata โŒ
Geometric queries โœ… GRF, ray โŒ โŒ โŒ โŒ
Storage SQLite file memory/file SQLite cloud server
Setup pip install pip install pip install API key DB server

License

MIT โ€” do whatever you want with it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oniondb-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oniondb-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file oniondb-0.1.0.tar.gz.

File metadata

  • Download URL: oniondb-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oniondb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ccc2ac34cf27ce9ca46e027120390d381f849d101424fe8d9ef4c45d1cb5d120
MD5 240a0c098b4b41a0f6128fb231f5a935
BLAKE2b-256 cafc6b3fedb0130da1655d5f6e3933cac42287c99c933091cf31081c671ec7b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for oniondb-0.1.0.tar.gz:

Publisher: publish.yml on Niksveler/oniondb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oniondb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oniondb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oniondb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f611d9cd34b38f23a646249014145c0ca55890ac878f05af2aceb8c7456ad400
MD5 e1723f3e480c7d1097e974e9828ba742
BLAKE2b-256 246b84d891eb42986fa4260126e4c1f817891a8c5dd37a33c9c4d40fa092114d

See more details on using hashes here.

Provenance

The following attestation bundles were made for oniondb-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Niksveler/oniondb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page