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.1.tar.gz (103.9 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.1-py3-none-macosx_13_0_arm64.whl (289.1 kB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

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

File metadata

  • Download URL: relativedb-0.1.1.tar.gz
  • Upload date:
  • Size: 103.9 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.1.tar.gz
Algorithm Hash digest
SHA256 a41fed40552f9be50b83c92e7377517a15e75224f27549d82970f6325deebff6
MD5 2edd9f8292f66c341bf094128ca20cee
BLAKE2b-256 2dc8c5eee5ac3658e21e86696e2c0812a863eca37afed1bf80ed5ce0e7e119fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for relativedb-0.1.1-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ebae415c0f65ffde3f591984ac4780dbe49f0a1c644dac9a23a3f72964373a14
MD5 9f7040636a347a73b4a5963b4d2fe38e
BLAKE2b-256 71462f9e637ca2fa95bee84e426e55e16396d131c7ea3898f309fcf6cba5bcd8

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