Skip to main content

Predictive queries (RelQL) over your own data: GraphQL-style user-defined retrievers, no bundled database connectors.

Project description

relativedb logo

RelativeDB / RelQL

RelativeDB is an optimized implementation of Relational Transformers, exposed through RelQL, a query language for predicting what happens next:

PREDICT NOT EXISTS(orders.*)
FROM customers

"For every customer, what is the probability they don't place an order."

RelativeDB works best with many tables (10–100) and needs no feature engineering. Subgraphs are discovered automatically, though you can ablate them to find what features really matter. Because it uses a pretrained model, it works in environments with very little data.

# Auto-label a GitHub issue: predict its label from title, body, and history.
PREDICT issues.label
WHERE issues.label IS NULL

# Would customer 42 churn if we moved them to the premium plan?
PREDICT NOT EXISTS(orders.*)
FROM customers c
WHERE c.customer_id = 42
ASSUMING c.plan = 'premium'

# Expected spend per customer over the next quarter.
PREDICT SUM(transactions.price) OVER (90 DAYS FOLLOWING)
FROM customers

# The 12 articles each customer is most likely to buy next.
PREDICT ARRAY_AGG(transactions.article_id) OVER (30 DAYS FOLLOWING RANK TOP 12)
FROM customers

Install

pip install relativedb

Python 3.10 or newer. Wheels bundle the native inference engine for macOS (universal2, 13.0+; Accelerate and Metal) and manylinux x86_64 / aarch64. Windows is not supported. On any other platform pip falls back to the source distribution, which contains no engine: build it from the repository (cpp/ with CMake) and point RELATIVEDB_RT_LIB at the built librt_c.

Quickstart: 90-day churn from your own DataFrames

A sketch — customer_dao, order_dao and t0 stand in for your storage and your anchor time. A copy-paste runnable version with an in-memory database is in the repository README.

from relativedb import (Schema, TableDef, LinkDef, ValueType,
                        RetrieverWiring, Engine, ExecutionInput, RtNativeBackend)

schema = (Schema.new_schema()
    .table(TableDef.new_table("customers")
        .column("age", ValueType.NUMBER)
        .column("signup_date", ValueType.DATETIME)
        .primary_key("customer_id").build())
    .table(TableDef.new_table("orders")
        .column("qty", ValueType.NUMBER)
        .column("order_date", ValueType.DATETIME)
        .primary_key("order_id").time_column("order_date").build())
    .link(LinkDef("orders", "customer_id", "customers"))
    .build())

wiring = (RetrieverWiring.new_wiring()
    .entities("customers", lambda table, ids, bound: customer_dao.by_ids(ids))
    .entities("orders",    lambda table, ids, bound: order_dao.by_ids(ids, bound))
    .default_links(lambda link, parent_id, bound, limit:
                   order_dao.recent_by_customer(parent_id, bound.as_of, limit))
    .build())

engine = Engine(schema, wiring, model_backend=RtNativeBackend(schema=schema))
result = engine.execute(ExecutionInput(
    query="PREDICT NOT EXISTS(orders.*) OVER (90 DAYS FOLLOWING) FROM customers "
          "WHERE customers.customer_id IN :ids",
    params={"ids": ["C7"]},   # the cohort; drop the WHERE to score every customer
    anchor_time=t0))

Checkpoints

Model checkpoints resolve through the Hugging Face cache on first use. Set RELATIVEDB_RT_QUANTIZED to f16, q8, or q4 to trade footprint for precision:

Checkpoint On-disk Accuracy Download
fp32 342 MB reference
fp16 172 MB identical rt-j-fp16
int8 88 MB ±0.01 rt-j-int8
int4 64 MB ±0.15 rt-j-int4

The model

RelativeDB is based on:

Development

pip install -e ".[dev]"

pytest -m "not integration"   # unit tier: no checkpoint, no network (<1s)
pytest -m integration         # native kernels + the real rt-j checkpoint
pytest                        # everything

Both tiers run from this directory or from the repository root. The unit tier still needs librt_c — the RelQL grammar lives once in C++ and is shared by the Python, Java, and Rust bindings — but it never downloads a checkpoint or opens a socket. The integration tier resolves hf://stanford-star/rt-j/… through the Hugging Face cache (~326 MB fp32, plus ~128 MB for the pinned MiniLM text encoder).

Set RELATIVEDB_REQUIRE_NATIVE=1 to make a missing library or an unresolvable checkpoint a hard failure instead of a skip. CI sets it on the integration job, so a cold or broken model cache turns the build red rather than reporting "0 tests ran, all green".

Coverage:

pytest --cov=relativedb --cov-report=xml:coverage-python.xml --cov-report=term

Docs

Read the RelQL book.

License

Apache-2.0.

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

relativedb-0.1.3.tar.gz (183.4 kB view details)

Uploaded Source

Built Distributions

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

relativedb-0.1.3-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded Python 3manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

relativedb-0.1.3-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (964.8 kB view details)

Uploaded Python 3manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

relativedb-0.1.3-py3-none-macosx_13_0_universal2.whl (705.2 kB view details)

Uploaded Python 3macOS 13.0+ universal2 (ARM64, x86-64)

File details

Details for the file relativedb-0.1.3.tar.gz.

File metadata

  • Download URL: relativedb-0.1.3.tar.gz
  • Upload date:
  • Size: 183.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for relativedb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 968da4b245504d4a25939e8072f3e65db5094f9de9fcaecc18303c7eaa025af3
MD5 7b46780a9ea99f727dc4095a858f75d9
BLAKE2b-256 4a8eb9ac2c2d7779d59ee015127e88a7dec193b41e991ff98281eb67bad8e4f2

See more details on using hashes here.

File details

Details for the file relativedb-0.1.3-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for relativedb-0.1.3-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 72bc278f5987216bf3b2304f5b5b73d7685819872a8081f682434b3a7a844bb2
MD5 2a035c5cd344103ba557512e298cd8aa
BLAKE2b-256 56f79cb07473109a7923ca1ae25c8891cef56bf3eb7906e985afa0a5b9e6d7a9

See more details on using hashes here.

File details

Details for the file relativedb-0.1.3-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for relativedb-0.1.3-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7679c17077b4cb36a6946fc2aace2d67ac6618ee12fee60f8317b8933d85f896
MD5 82e94f6b0779355c1d4d669100e6cd5f
BLAKE2b-256 dc48f24a912027fa5cf430f74bcc6d85e043a6845fc574c8f7440940c5803929

See more details on using hashes here.

File details

Details for the file relativedb-0.1.3-py3-none-macosx_13_0_universal2.whl.

File metadata

File hashes

Hashes for relativedb-0.1.3-py3-none-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 3255737c4d245f6e6106172403ce3e294b8749596d5353ce21f739ddd0cf2d7b
MD5 c5e659b46dbf34aab32d90d7cff6f562
BLAKE2b-256 8812cde0c68aa5a7093b42249fd7030a5aaac4b801bd576cc040dfdb3723a07a

See more details on using hashes here.

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