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

Wheels bundle the native inference engine for macOS arm64 (Apple Silicon; CPU and Metal). On other platforms the package installs from source; build the engine from the repository (cpp/ with CMake) and point RELATIVEDB_RT_LIB at the built librt_c.

Quickstart: 90-day churn from your own DataFrames

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:

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.0.tar.gz (103.8 kB view details)

Uploaded Source

Built Distribution

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

relativedb-0.1.0-py3-none-macosx_13_0_arm64.whl (289.0 kB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

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

File metadata

  • Download URL: relativedb-0.1.0.tar.gz
  • Upload date:
  • Size: 103.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for relativedb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 655891990bb1d6599dbe5a9e90fc5b5dacd4d0219583ec71383a5b0cc0580a9d
MD5 3f92f4c8fda49cc8f4333e26c371dc5b
BLAKE2b-256 0b73329df07e433c04736de360c1c205bca8d74f95aedf4209a52036d2c26eaf

See more details on using hashes here.

File details

Details for the file relativedb-0.1.0-py3-none-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for relativedb-0.1.0-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ce6c7ba09598cd32b493839652c5383144150aa14db3952f3f7d98d8e7b48008
MD5 13101144d4d07ca02c419e43430f54bf
BLAKE2b-256 0f9ba80738381d3c1825c0c8d271072da5af1f2ba9912478ef5a8ef79fabd5ce

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