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.2.tar.gz (158.1 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.2-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.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (949.8 kB view details)

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

relativedb-0.1.2-py3-none-macosx_13_0_universal2.whl (692.4 kB view details)

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

File details

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

File metadata

  • Download URL: relativedb-0.1.2.tar.gz
  • Upload date:
  • Size: 158.1 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.2.tar.gz
Algorithm Hash digest
SHA256 c04b863067c63c113252f4b4b950888847bc4c181a5c03fdf1d5b33cbb4995ba
MD5 07a2a303ac0fe82526bbb960323312a7
BLAKE2b-256 3e430d5ae228aa689c6520a61f9241b3f62009364bc1a0404b624ad3ca86ec52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for relativedb-0.1.2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0352959dd83d43d31cb4932283ddde807b87cc520d8a6ba732a01ffb8a2c6f34
MD5 65ed1f37b9e525e6105d36cab2735065
BLAKE2b-256 431bc8f95b67ff9ae24fc424d11c0ec2b467089450dc1ca29c34b7ba31b3ecc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for relativedb-0.1.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1697539c395de3a024970cd93dcddfa93a7dd896403a97b95feb2cf73114ef02
MD5 0ccd295030493f9b69228b71e0d65263
BLAKE2b-256 e9563076fc097e5aad7d974aa327dd5ba1c765b97c2cc7e836151f61801ecd3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for relativedb-0.1.2-py3-none-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 1f209af69ba50fa11e865f0d8d74116a0d606d24a81bcb7af854034161e16eae
MD5 f059093278aea8e64cc0864fe9e95d49
BLAKE2b-256 5428d4808f2808be286407248fd9f913b096ebdafd6aed66ce88ca5d525c5fc6

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