Skip to main content

A high-performance, lightweight vector database

Project description

SurgeDB Bindings

UniFFI-based bindings for SurgeDB, enabling usage from Python, Swift, and Kotlin.

Architecture

Python / Swift / Kotlin
         │
         ▼
┌─────────────────────────┐
│   surgedb-bindings      │  ← Stable API (this crate)
│   (SurgeClient)         │
└───────────┬─────────────┘
            │
            ▼
┌─────────────────────────┐
│     surgedb-core        │  ← Can change freely (internal)
│   (internal engine)     │
└─────────────────────────┘

Stable API

The binding layer provides a stable API that won't change even when surgedb-core internals are optimized. This means:

  • Internal SIMD optimizations → No binding changes needed
  • HNSW algorithm improvements → No binding changes needed
  • New quantization methods → Add new enum variant (backward compatible)
  • Bug fixes → No binding changes needed

Building

# Build the Rust library
cargo build --release -p surgedb-bindings

Generating Python Bindings

cd crates/surgedb-bindings

# On macOS
make generate-python

# On Linux
make generate-python-linux

This will create Python bindings in the python/ directory.

Python Usage

from surgedb import SurgeClient, SurgeConfig, DistanceMetric, Quantization

# Simple in-memory database
db = SurgeClient.new_in_memory(dimensions=384)

# Insert vectors
db.insert("doc1", [0.1, 0.2, ...], '{"title": "Hello World"}')
db.insert("doc2", [0.3, 0.4, ...], '{"title": "Goodbye World"}')

# Search
results = db.search([0.1, 0.2, ...], k=5)
for r in results:
    print(f"{r.id}: {r.score}")

# With quantization and persistence
config = SurgeConfig(
    dimensions=768,
    distance_metric=DistanceMetric.COSINE,
    quantization=Quantization.SQ8,
    persistent=True,
    data_path="./my_db"
)
db = SurgeClient.open("./my_db", config)

API Reference

SurgeClient

Method Description
new_in_memory(dimensions) Create in-memory database
open(path, config) Open persistent database
insert(id, vector, metadata) Insert a vector
upsert(id, vector, metadata) Insert or update
upsert_batch(entries) Batch insert/update
delete(id) Delete by ID
get(id) Get vector by ID
search(query, k) Find k nearest neighbors
search_with_filter(query, k, filter) Filtered search
list(offset, limit) List vector IDs
len() Get vector count
is_empty() Check if empty
stats() Get database statistics
checkpoint() Create snapshot
sync() Force sync to disk

Enums

# Distance metrics
DistanceMetric.COSINE      # Cosine similarity (default)
DistanceMetric.EUCLIDEAN   # Euclidean distance
DistanceMetric.DOT_PRODUCT # Dot product

# Quantization types
Quantization.NONE    # No quantization (full precision)
Quantization.SQ8     # 4x compression
Quantization.BINARY  # 32x compression

Filters

from surgedb import SearchFilter

# Exact match
f = SearchFilter.Exact(field="category", value_json='"tech"')

# One of many values
f = SearchFilter.OneOf(field="tag", values_json=['"ai"', '"ml"'])

# Logical AND
f = SearchFilter.And(filters=[filter1, filter2])

# Logical OR
f = SearchFilter.Or(filters=[filter1, filter2])

Swift / Kotlin

Swift and Kotlin bindings can be generated similarly:

# Generate Swift bindings
cargo run --release -p surgedb-bindings --bin uniffi-bindgen -- \
    generate \
    --library ../target/release/libsurgedb_bindings.dylib \
    --language swift \
    --out-dir swift/

# Generate Kotlin bindings
cargo run --release -p surgedb-bindings --bin uniffi-bindgen -- \
    generate \
    --library ../target/release/libsurgedb_bindings.so \
    --language kotlin \
    --out-dir kotlin/

Development

Adding New Methods

  1. Add method to src/surgedb.udl
  2. Implement in src/lib.rs
  3. Regenerate bindings
  4. Update language-specific tests

Testing

# Rust tests
cargo test -p surgedb-bindings

# Python tests (after generating bindings)
make test-python

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

surgedb-1.0.0a1.tar.gz (82.7 kB view details)

Uploaded Source

Built Distributions

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

surgedb-1.0.0a1-py3-none-win_amd64.whl (296.2 kB view details)

Uploaded Python 3Windows x86-64

surgedb-1.0.0a1-py3-none-manylinux_2_34_x86_64.whl (430.1 kB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

surgedb-1.0.0a1-py3-none-manylinux_2_34_aarch64.whl (420.9 kB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

surgedb-1.0.0a1-py3-none-macosx_11_0_arm64.whl (384.2 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

surgedb-1.0.0a1-py3-none-macosx_10_12_x86_64.whl (397.7 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file surgedb-1.0.0a1.tar.gz.

File metadata

  • Download URL: surgedb-1.0.0a1.tar.gz
  • Upload date:
  • Size: 82.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for surgedb-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 1ed843d6bcf861f1f679f5a0e8da4937b658665551a955762d98f38258c81c54
MD5 5eff70799f54f1c1219d4b6e5c28b430
BLAKE2b-256 79ac095425eb88f431115801e4a4f8d03353e85d3dabb4dfa26aaddb299ab6e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1.tar.gz:

Publisher: release-pypi.yml on meet447/SurgeDB

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

File details

Details for the file surgedb-1.0.0a1-py3-none-win_amd64.whl.

File metadata

  • Download URL: surgedb-1.0.0a1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 296.2 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for surgedb-1.0.0a1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8224d24ffb953bfe3cf48fd11f005ab12d33b16509157b804c3da1265423a6a7
MD5 5ea99f3104f04dd875bf88a1d2de16aa
BLAKE2b-256 ae63a48efc5c17544de85fcae8f92816b919252a996491b4ee9f56be5366c659

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1-py3-none-win_amd64.whl:

Publisher: release-pypi.yml on meet447/SurgeDB

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

File details

Details for the file surgedb-1.0.0a1-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for surgedb-1.0.0a1-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 844f1ae8cac527b362ba74d2527961bae40dd2b195a77fbbdba9c04f3d212996
MD5 4b3f9da8820c1385dbb8163cf74ce4c4
BLAKE2b-256 9936763cc0d93fcbf2c4471946db1725a7455ebe9d974d40f90001e6880a74f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1-py3-none-manylinux_2_34_x86_64.whl:

Publisher: release-pypi.yml on meet447/SurgeDB

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

File details

Details for the file surgedb-1.0.0a1-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for surgedb-1.0.0a1-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 fc304e7bdc1755058c94fbf662ac0d769f4f392d71335f29dbbfff2ddbde840a
MD5 8600caabaa3ecbfdf96a2c15a65faccf
BLAKE2b-256 de09457eeacd607bd582abaee625768d3226c15e8e1226b93fbcf7cc49cb9385

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1-py3-none-manylinux_2_34_aarch64.whl:

Publisher: release-pypi.yml on meet447/SurgeDB

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

File details

Details for the file surgedb-1.0.0a1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for surgedb-1.0.0a1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb85500e16427b6a0731c367bb1235f4c83797d515fd676f99ff3a950ace3219
MD5 03a230ea82cf761f6f4986f94f9cbfef
BLAKE2b-256 1dcccc2a443d5d98b2e5a87626946ae7b33bae36c97e6b8c248ef200d6794d62

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1-py3-none-macosx_11_0_arm64.whl:

Publisher: release-pypi.yml on meet447/SurgeDB

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

File details

Details for the file surgedb-1.0.0a1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for surgedb-1.0.0a1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b082cfe4db95e6aeb281f895756e16e9be21f54b862347e2a86f715bfff5c408
MD5 96784188133e6977fc79e13e207c9064
BLAKE2b-256 7090b4845f66cf06e1e9c38bce90679236c91de402df673a19c613e0e02bf13f

See more details on using hashes here.

Provenance

The following attestation bundles were made for surgedb-1.0.0a1-py3-none-macosx_10_12_x86_64.whl:

Publisher: release-pypi.yml on meet447/SurgeDB

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