DuckDB Connector

View as Markdown

KumoRFM can connect directly to DuckDB databases, automatically inferring table metadata and relationships from the schema.

Installation

The DuckDB backend requires the ADBC DuckDB driver:

$pip install kumoai[duckdb]

Quick Start

Connect to a file-based DuckDB database:

1import kumoai.rfm as rfm
2
3graph = rfm.Graph.from_duckdb(connection="my_database.duckdb")

This will:

  1. Connect to the DuckDB database
  2. Discover all non-temporary, non-internal tables automatically
  3. Infer column metadata (data types, semantic types, primary keys, time columns)
  4. Detect foreign key relationships
  5. Print a summary of the inferred metadata and links

Specifying Tables

Control which tables to include and customize their configuration:

1graph = rfm.Graph.from_duckdb(
2 connection="my_database.duckdb",
3 tables=[
4 "USERS",
5 {"name": "ORDERS", "source_name": "ORDERS_SNAPSHOT"},
6 {"name": "ITEMS", "primary_key": "ITEM_ID"},
7 ],
8)

Table configuration options:

KeyDescriptionRequired
nameThe table name used in PQL queriesYes
source_nameThe actual table name in the database (if different from name)No
primary_keyOverride the auto-detected primary keyNo
time_columnThe name of the time column for this tableNo
end_time_columnThe name of the end time column for this tableNo
columnsSelected source columns or column specs, including expression columnsNo

Connection Options

In-memory database:

1from kumoai.rfm.backend.duckdb import connect
2
3conn = connect() # in-memory DuckDB database
4graph = rfm.Graph.from_duckdb(connection=conn)

From a file path:

1graph = rfm.Graph.from_duckdb(connection="path/to/database.duckdb")

From an existing ADBC connection:

1from kumoai.rfm.backend.duckdb import connect
2
3conn = connect("path/to/database.duckdb")
4graph = rfm.Graph.from_duckdb(connection=conn)

From a connection config dict:

1graph = rfm.Graph.from_duckdb(
2 connection={"uri": "path/to/database.duckdb"},
3)

Controlling Metadata Inference

1graph = rfm.Graph.from_duckdb(
2 connection="my_database.duckdb",
3 infer_metadata=False,
4 verbose=False,
5)
6
7graph.infer_metadata()
8graph.infer_links()

Manual Edge Specification

Override automatic link detection by providing edges explicitly:

1graph = rfm.Graph.from_duckdb(
2 connection="my_database.duckdb",
3 edges=[
4 ("ORDERS", "USER_ID", "USERS"),
5 ("ORDERS", "ITEM_ID", "ITEMS"),
6 ],
7)