Skip to content

select

relationalai.semantics
select(*args: StatementAndSchema) -> Fragment

Return a selection fragment from the active model.

This is a convenience wrapper around Model.select that operates on the single active model. It returns a composable Fragment that can be further refined with Fragment.where, Fragment.define, and Fragment.require, and materialized via Fragment.to_df.

If you have more than one model, call Model.select on the specific model instead.

  • Fragment - A composable query fragment representing the selection.
  • relationalai.util.error.RAIException - If there is no active model, or if multiple models exist and the active model would be ambiguous.

Select a literal value and materialize the result as a pandas DataFrame:

>>> from relationalai.semantics import Model, select, where
>>> m = Model()
>>> select(1).to_df()

Combine with filters:

>>> Person = m.Concept("Person")
>>> define(
... Person.new(name="Alice", age=10),
... Person.new(name="Bob", age=30),
... )
>>> select(Person.name, Person.age).where(Person.age > 21).to_df()

Extract the selected values by unpacking the fragment:

>>> name, age = select(Person.name, Person.age)
>>> where(age >= 18).select(name).to_df()
RelationalAI Documentation
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.0.0
            └──  Breaking Changes