### Undirected Graph Setup Example Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Initial setup for an undirected graph. ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up an undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define the same nodes and edges ``` -------------------------------- ### Declare variables and objectives Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/prescriptive/problem/problem_class/index Example demonstrating the setup of a model, variable declaration, and objective minimization. ```python >>> from relationalai.semantics import Float, Model >>> from relationalai.semantics.reasoners.prescriptive import Problem >>> m = Model("demo") >>> x = m.Relationship(f"{Float:x}") >>> p = Problem(m, Float) >>> p.solve_for(x, name="x", lower=0) >>> p.minimize(x) ``` -------------------------------- ### Get Top 3 Products by Revenue Per Store Source: https://docs.relational.ai/api/python/v1.0/semantics/std/aggregates/top/index Example demonstrating how to get the top 3 products by revenue for each store. This requires defining `Product`, `revenue`, `Store`, and ensuring the `per(Store)` clause is correctly applied. ```python >>> select(Product).where(aggregates.top(3, Product.revenue).per(Store).where(Product.store == Store)) ``` -------------------------------- ### CompilerConfig Examples Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/compilerconfig_class/index Examples demonstrating how to configure compiler settings. ```APIDOC ## Examples Minimal YAML (in ``raiconfig.yaml``): ```yaml default_connection: sf connections: sf: type: snowflake # ... compiler: strict: true soft_type_errors: true ``` Configure compiler settings using a dict: ```python >>> from relationalai.config import create_config >>> cfg = create_config( ... compiler={"dry_run": True, "strict": True, "soft_type_errors": True}, ... ) ``` Configure compiler settings using an explicit CompilerConfig instance: ```python >>> from relationalai.config import create_config, CompilerConfig >>> cfg = create_config( ... compiler=CompilerConfig(dry_run=True, strict=True, soft_type_errors=True), ... ) ``` ``` -------------------------------- ### Get Job Details Example Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/get_job/index Example of how to call the get_job procedure to retrieve details for a specific job. ```sql CALL relationalai.api.get_job('predictive', 'abc123'); ``` -------------------------------- ### LogicReasonerConfig Examples Source: https://docs.relational.ai/api/python/v1.0/config/config_reasoners_fields/logicreasonerconfig_class/index Examples of how to configure the logic reasoner. ```APIDOC ## Examples ### Minimal YAML Configuration ```yaml default_connection: sf connections: sf: type: snowflake # ... reasoners: logic: incremental_maintenance: "on" ``` ### Python Configuration using `create_config` ```python from relationalai.config import create_config # Configure logic reasoner settings using a dict cfg = create_config(reasoners={ "logic": { "use_lqp": True, "lqp": {"semantics_version": "1"} } }) # Configure logic reasoner settings using an explicit LogicReasonerConfig instance from relationalai.config import LogicReasonerConfig cfg = create_config( reasoners={ "logic": LogicReasonerConfig( use_lqp=True, lqp={"semantics_version": "1"} ) } ) ``` ``` -------------------------------- ### JobsConfig Examples Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/jobsconfig_class/index Examples demonstrating how to configure JobsConfig. ```APIDOC ## Examples ### Minimal YAML Configuration ```yaml default_connection: sf connections: sf: type: snowflake # ... jobs: print_progress: true enable_guard_rails: true ``` ### Python Dictionary Configuration ```python from relationalai.config import create_config cfg = create_config( connections={"sf": {...}}, jobs={ "print_progress": True, "enable_guard_rails": True, }, ) ``` ### Explicit JobsConfig Instance Configuration ```python from relationalai.config import create_config, JobsConfig cfg = create_config( connections={"sf": {...}}, jobs=JobsConfig( print_progress=True, enable_guard_rails=True, ), ) ``` ``` -------------------------------- ### Register Queries Example Source: https://docs.relational.ai/api/python/v1.0/agent/cortex/queries/querycatalog_class/index Usage example demonstrating how to register a partial function as a query. ```python >>> from functools import partial >>> def top_customers(model, limit=10): ... return model.query(...) >>> queries = QueryCatalog(partial(top_customers, jaffle_model)) ``` -------------------------------- ### Example DeploymentConfig Initialization Source: https://docs.relational.ai/api/python/v1.0/agent/cortex/deployment_config/deploymentconfig_class/index Instantiates DeploymentConfig with essential parameters for agent deployment. This example sets the database, schema, agent name, and warehouse. ```python config = DeploymentConfig( database="APPS", schema="AUSTIN", agent_name="jaffle_assistant", warehouse="COMPUTE_WH", llm="claude-sonnet-4-5", ) ``` -------------------------------- ### ReasonerConfig Usage Examples Source: https://docs.relational.ai/api/python/v1.0/config/config_reasoners_fields/reasonerconfig_class/index Examples demonstrating how to configure reasoner defaults using YAML and Python. ```APIDOC ## Examples ### Minimal YAML Configuration ```yaml default_connection: sf connections: sf: type: snowflake # ... reasoners: logic: size: HIGHMEM_X64_S query_timeout_mins: 30 ``` ### Python Configuration using `create_config` (dict) ```python >>> from relationalai.config import create_config >>> cfg = create_config(reasoners={ ... "logic": { ... "size": "HIGHMEM_X64_S", ... "query_timeout_mins": 30, ... } ... }) ``` ### Python Configuration using `create_config` and `ReasonerConfig` instance ```python >>> from relationalai.config import create_config, ReasonerConfig >>> cfg = create_config( ... reasoners={"predictive": ReasonerConfig(size="HIGHMEM_X64_S", query_timeout_mins=30)}, ... ) ``` ``` -------------------------------- ### ExecutionConfig Examples Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/executionconfig_class/index Examples demonstrating how to configure ExecutionConfig. ```APIDOC ## Examples ### Minimal YAML Configuration ```yaml default_connection: sf connections: sf: type: snowflake # ... execution: metrics: true retries: enabled: true max_attempts: 5 base_delay_s: 0.5 max_delay_s: 10.0 ``` ### Python Dictionary Configuration ```python >>> from relationalai.config import create_config >>> cfg = create_config( ... execution={ ... "metrics": True, ... "retries": {"enabled": True, "max_attempts": 5, "base_delay_s": 0.5, "max_delay_s": 10.0}, ... }, ... ) ``` ### Explicit ExecutionConfig Instance Configuration ```python >>> from relationalai.config import create_config, ExecutionConfig >>> cfg = create_config( ... execution=ExecutionConfig( ... metrics=True, ... retries=ExecutionConfig.RetriesConfig(enabled=True, max_attempts=5, base_delay_s=0.5, max_delay_s=10.0), ... ), ... ) ``` ``` -------------------------------- ### Define and Solve a Decision Problem Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/prescriptive/index Quick start example demonstrating how to define a model, create a problem with specified variable types, set constraints, and solve it using a specified solver. ```python from relationalai.semantics import Model, Float, Integer from relationalai.semantics.reasoners.prescriptive import Problem model = Model("my_problem") p = Problem(model, Float) # Float for HiGHS/Gurobi/Ipopt, Integer for MiniZinc x = model.Relationship(f"{Float:x}") y = model.Relationship(f"{Float:y}") p.solve_for(x, name="x", lower=0, upper=10) p.solve_for(y, name="y", lower=0, upper=10) p.minimize(x**2 + y**2) p.satisfy(model.require(x + y >= 5)) p.solve("highs") ``` -------------------------------- ### Compute Shortest Path Distances in an Unweighted Graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating the setup of an unweighted graph and the calculation of all-pairs shortest path lengths using the full parameter. ```python >>> from relationalai.semantics import Model, Integer >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up an unweighted, undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3, n4 = [Node.new(id=i) for i in range(1, 5)] >>> model.define(n1, n2, n3, n4) >>> model.define( ... Edge.new(src=n1, dst=n2), ... Edge.new(src=n2, dst=n3), ... Edge.new(src=n3, dst=n3), ... Edge.new(src=n2, dst=n4), ... ) >>> >>> # 3. Select the shortest path length between all pairs of nodes >>> start, end = Node.ref("start"), Node.ref("end") >>> length = Integer.ref("length") >>> dist = graph.distance(full=True) >>> model.select(start.id, end.id, length).where(dist(start, end, length)).inspect() id id_2 length 0 1 1 0 1 1 2 1 2 1 3 2 3 1 4 2 4 2 1 1 5 2 2 0 6 2 3 1 7 2 4 1 8 3 1 2 9 3 2 1 10 3 3 0 11 3 4 2 12 4 1 2 13 4 2 1 14 4 3 2 15 4 4 0 ``` -------------------------------- ### join function usage examples Source: https://docs.relational.ai/api/python/v1.0/semantics/std/strings/join/index Examples demonstrating how to join strings with default and custom separators. ```python >>> strings.join(["FIRST", "MIDDLE", "LAST"]) # defaults to empty string separator >>> strings.join([Person.first, Person.last], " ") >>> strings.join([Person.first, "the best", Person.last], " | ") ``` -------------------------------- ### Example: Get Transaction Details Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/get_transaction/index Demonstrates calling the procedure with a specific transaction ID and shows the resulting output format. ```sql -- Retrieve the details for the transaction with ID '02c8fa31-1234-5678-90ab-abcdef123456'. CALL relationalai.api.get_transaction('02c8fa31-1234-5678-90ab-abcdef123456'); /*+--------------------------------------+---------------+-----------+--------------+-----------+--------------------------+----------+-------------------------------+-------------------------------+--------------+ | ID | DATABASE_NAME | STATE | ABORT_REASON | READ_ONLY | CREATED_BY | DURATION | CREATED_ON | FINISHED_AT | ENGINE_NAME | |--------------------------------------+---------------+-----------+--------------+-----------+--------------------------+----------+-------------------------------+-------------------------------+--------------| | 02c8fa31-1234-5678-90ab-abcdef123456 | MyModel | COMPLETED | NULL | TRUE | john.doe@company.com | 7643 | 2024-10-28 08:00:12.123 -0700 | 2024-10-28 08:00:19.766 -0700 | john_doe | +--------------------------------------+---------------+-----------+--------------+-----------+--------------------------+----------+-------------------------------+-------------------------------+--------------+ */ ``` -------------------------------- ### Creating DataConfig Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/dataconfig_class/index Examples of how to create and configure DataConfig instances. ```APIDOC ## Creating DataConfig ### Minimal YAML Configuration ```yaml default_connection: sf connections: sf: type: snowflake # ... data: wait_for_stream_sync: false download_url_type: external ``` ### Python Dictionary Configuration ```python from relationalai.config import create_config cfg = create_config( data={"wait_for_stream_sync": False, "download_url_type": "external"}, ) ``` ### Explicit DataConfig Instance Configuration ```python from relationalai.config import create_config, DataConfig cfg = create_config( data=DataConfig(wait_for_stream_sync=False, download_url_type="external"), ) ``` ``` -------------------------------- ### Enable Warm Engine Usage Example Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/app/enable_warm_engine/index Example of calling the procedure to enable a warm engine of a specific size. ```sql -- Enable a warm engine of size HIGHMEM_X64_S CALL relationalai.app.enable_warm_engine('HIGHMEM_X64_S'); /*+----------------------------------------------------------+ | Successfully disabled warm engines of size HIGHMEM_X64_S | +----------------------------------------------------------+ */ ``` -------------------------------- ### Install RelationalAI Docs Skill via Agent Prompt Source: https://docs.relational.ai/build/agents/documentation/index Provide this prompt to your AI agent to have it download and install the RelationalAI Docs skill. The agent will handle placing it in the preferred skills location. ```text Download the RelationalAI Docs skill from https://docs.relational.ai/skill.md and install it in your preferred skills location. ``` -------------------------------- ### GET /config/explain Source: https://docs.relational.ai/api/cli/v1.0/config/explain/index Explains the active configuration settings and their source origins. ```APIDOC ## GET config:explain ### Description Displays the currently active configuration values and identifies the source (provenance) of each setting. ### Method CLI Command (rai config:explain) ### Endpoint config:explain ### Parameters #### Options - **--verbose, -v** (Boolean) - Optional - Show full provenance details. Default: False. ### Request Example rai config:explain --verbose ### Response #### Success Response (0) - **config_map** (Object) - A key-value map of configuration settings including their source file or environment variable origin. ``` -------------------------------- ### bottom usage examples Source: https://docs.relational.ai/api/python/v1.0/semantics/std/aggregates/bottom/index Examples demonstrating how to use the bottom function to retrieve lowest-priced products and least selling products per category. ```python >>> select(Product).where(aggregates.bottom(10, Product.price)) ``` ```python >>> select(Product).where(aggregates.bottom(5, Product.units_sold).per(Category).where(Product.category == Category)) ``` -------------------------------- ### Directed Graph Reachability Examples Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Examples demonstrating full reachability, reachability from a subset, and reachability to a subset in a directed graph. ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up a directed graph >>> model = Model("test_model") >>> graph = Graph(model, directed=True, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3 = [Node.new(id=i) for i in range(1, 4)] >>> model.define(n1, n2, n3) >>> model.define( ... Edge.new(src=n1, dst=n2), ... Edge.new(src=n3, dst=n2), ... ) >>> >>> # 3. Select all reachable pairs and inspect >>> from_node, to_node = Node.ref("start"), Node.ref("end") >>> reachable = graph.reachable(full=True) >>> model.select(from_node.id, to_node.id).where(reachable(from_node, to_node)).inspect() id id_2 0 1 1 1 1 2 2 2 2 3 3 2 4 3 3 ``` ```python >>> # 4. Use 'from_' parameter to get reachability from specific nodes >>> # Define a subset containing nodes 1 and 3 >>> subset = model.Relationship(f"{Node:node} is in from subset") >>> node = Node.ref() >>> model.where(model.union(node.id == 1, node.id == 3)).define(subset(node)) >>> >>> # Get reachability from nodes in the subset to all other nodes >>> reachable_from = graph.reachable(from_=subset) >>> model.select(from_node.id, to_node.id).where( ... reachable_from(from_node, to_node) ... ).inspect() id id_2 0 1 1 1 1 2 2 3 2 3 3 3 ``` ```python >>> # 5. Use 'to' parameter to get reachability to specific nodes >>> # Define a different subset containing node 2 >>> to_subset = model.Relationship(f"{Node:node} is in to subset") >>> node = Node.ref() >>> model.where(node.id == 2).define(to_subset(node)) >>> >>> # Get reachability from all nodes to node 2 >>> reachable_to = graph.reachable(to=to_subset) >>> model.select(from_node.id, to_node.id).where( ... reachable_to(from_node, to_node) ... ).inspect() id id_2 0 1 2 1 2 2 2 3 2 ``` -------------------------------- ### Create and Start a Job (Sync) Source: https://docs.relational.ai/api/python/v1.0/services/jobs/client_sync/jobsclientsync_class/index Start a new job or transaction and return a non-blocking operation handle. The 'reasoner_name' specifies which reasoner to use. ```python JobsClientSync.create( reasoner_type: str, reasoner_name: str, payload: dict[str, Any], *, timeout_mins: int | None = None ) -> JobOperationSync ``` -------------------------------- ### Resume a reasoner Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/resume_reasoner_async/index Example call to resume a logic reasoner named my_reasoner. ```sql CALL relationalai.api.resume_reasoner_async('logic', 'my_reasoner'); ``` -------------------------------- ### Get Number of Triangles in a Graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index This example demonstrates how to set up a directed graph and then use the `num_triangles()` method to count the unique triangles within it. Ensure the `relationalai` library is installed and imported. ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up a directed graph >>> model = Model("test_model") >>> graph = Graph(model, directed=True, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3, n4 = [Node.new(id=i) for i in range(1, 5)] >>> model.define(n1, n2, n3, n4) >>> model.define( ... Edge.new(src=n1, dst=n3), ... Edge.new(src=n2, dst=n1), ... Edge.new(src=n3, dst=n2), ... Edge.new(src=n3, dst=n4), ... Edge.new(src=n1, dst=n4), ... ) >>> >>> # 3. Inspect the number of unique triangles >>> graph.num_triangles().inspect() num_triangles 0 1 ``` -------------------------------- ### Create a Reasoner with Python Source: https://docs.relational.ai/manage/compute-resources/index Use `connect_sync()` to establish a client connection and then call `client.reasoners.create_ready()` to provision a reasoner. This example creates a 'Logic' reasoner with auto-suspension enabled. ```python from relationalai.client import connect_sync with connect_sync() as client: # Create a HIGHMEM_X64_S Logic reasoner configured to auto-suspend after 60 minutes of inactivity. client.reasoners.create_ready( "Logic", "my_reasoner", reasoner_size="HIGHMEM_X64_S", auto_suspend_mins=60, ) ``` -------------------------------- ### Compute out-neighbors in a directed graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating the setup of a directed graph and the retrieval of all out-neighbor relationships. ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up a directed graph >>> model = Model("test_model") >>> graph = Graph(model, directed=True, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3, n4 = [Node.new(id=i) for i in range(1, 5)] >>> model.define(n1, n2, n3, n4) >>> model.define( ... Edge.new(src=n1, dst=n2), ... Edge.new(src=n2, dst=n3), ... Edge.new(src=n3, dst=n3), ... Edge.new(src=n2, dst=n4) ... ) >>> >>> # 3. Select the IDs from the out-neighbor relationship and inspect >>> node, outneighbor_node = Node.ref("node"), Node.ref("outneighbor_node") >>> outneighbor = graph.outneighbor() >>> model.select( ... node.id, ... outneighbor_node.id ... ).where( ... outneighbor(node, outneighbor_node) ... ).inspect() id id_2 0 1 2 1 2 3 2 2 4 3 3 3 ``` -------------------------------- ### Deploy a Cortex Agent Source: https://docs.relational.ai/api/python/v1.0/agent/cortex/cortex_agent_manager/cortexagentmanager_class/index Example demonstrating the initialization of a manager and the deployment of an agent with custom tools and imports. ```python >>> session = create_config().get_session(SnowflakeConnection) >>> manager = CortexAgentManager( ... session=session, ... config=DeploymentConfig( ... agent_name="EXAMPLE_CORTEX", ... database="EXAMPLE", ... schema="CORTEX", ... warehouse="DEMOWAREHOUSE", ... ), ... ) >>> def init_tools(model): ... init_model(model) ... return ToolRegistry().add( ... model=model, description="Customers and orders") >>> manager.deploy( ... init_tools=init_tools, imports=discover_imports()) ``` -------------------------------- ### Display Problem Summary Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/prescriptive/problem/problem_class/index Examples showing how to display the full problem configuration or a specific subconcept. ```python >>> from relationalai.semantics import Float, Model >>> from relationalai.semantics.reasoners.prescriptive import Problem >>> m = Model("demo") >>> x = m.Relationship(f"{Float:x}") >>> p = Problem(m, Float) >>> x_vars = p.solve_for(x, name="x", lower=0) >>> p.minimize(x) >>> p.display() ``` ```python >>> p.display(x_vars) ``` -------------------------------- ### Calculate Average Clustering Coefficient Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating the setup of an undirected graph and the calculation of its average clustering coefficient. ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up an undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3, n4, n5 = [Node.new(id=i) for i in range(1, 6)] >>> model.define(n1, n2, n3, n4, n5) >>> model.define( ... Edge.new(src=n1, dst=n2), ... Edge.new(src=n1, dst=n3), ... Edge.new(src=n1, dst=n4), ... Edge.new(src=n1, dst=n5), ... Edge.new(src=n2, dst=n3), ... ) >>> >>> # 3. Inspect the average clustering coefficient >>> graph.average_clustering_coefficient().inspect() coefficient 0 0.433333 ``` -------------------------------- ### Compute Community Assignments in a Weighted Graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating the setup for a weighted, undirected graph to compute community assignments. ```python >>> # 1. Set up a weighted, undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=True) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges >>> n1, n2, n3, n4, n5, n6 = [Node.new(id=i) for i in range(1, 7)] >>> model.define(n1, n2, n3, n4, n5, n6) >>> model.define( ... # First embedded three-clique. ... Edge.new(src=n1, dst=n2, weight=1.0), ... Edge.new(src=n1, dst=n3, weight=1.0), ... Edge.new(src=n2, dst=n3, weight=1.0), ``` -------------------------------- ### Render Tutorial List Component Source: https://docs.relational.ai/build/tutorials/index Displays a list of tutorial links from the specified directory. ```astro ``` -------------------------------- ### Constrain Distance Computation with from_ Parameter Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example showing how to restrict the distance calculation to start from a specific subset of nodes. ```python >>> # 4. Use 'from_' parameter to get distances from specific nodes >>> # Define a subset containing nodes 1 and 3 >>> subset = model.Relationship(f"{Node:node} is in from subset") >>> node = Node.ref() >>> model.where(model.union(node.id == 1, node.id == 3)).define(subset(node)) >>> >>> # Get distances from nodes in the subset to all other nodes >>> dist_from = graph.distance(from_=subset) >>> model.select(start.id, end.id, length).where( ... dist_from(start, end, length) ... ).inspect() id id_2 length 0 1 1 0 1 1 2 1 2 1 3 2 3 1 4 2 4 3 1 2 5 3 2 1 6 3 3 0 7 3 4 2 ``` -------------------------------- ### Counting Nodes in a Graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating the setup of a graph model, definition of nodes and edges, and the retrieval of the node count using num_nodes(). ```python >>> from relationalai.semantics import Model >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up the graph and concepts >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define some nodes >>> node1, node2, node3, node4 = [Node.new(id=i) for i in range(1, 5)] >>> model.define(node1, node2, node3, node4) >>> >>> # 3. Define the full set of edges >>> model.define( ... Edge.new(src=node1, dst=node2), ... Edge.new(src=node2, dst=node3), ... Edge.new(src=node3, dst=node3), ... Edge.new(src=node2, dst=node4), ... ) >>> >>> # 4. The relationship contains the number of nodes >>> graph.num_nodes().inspect() num_nodes 0 4 ``` -------------------------------- ### Match prefixes with re.match Source: https://docs.relational.ai/build/guides/reasoning/rules-based/match-text-with-patterns/index Demonstrates using re.match to filter concepts based on a prefix pattern. The example identifies tickets with subjects starting with the [P0] tag. ```python from relationalai.semantics import Integer, Model, String from relationalai.semantics.std import re m = Model("SupportModel") Ticket = m.Concept("Ticket") CriticalTicket = m.Concept("CriticalTicket", extends=[Ticket]) m.define( Ticket.new(id=201, subject="[P0] Outage: login"), Ticket.new(id=202, subject="Re: [P0] outage"), Ticket.new(id=203, subject="[P1] Degraded performance"), ) m.define(CriticalTicket(Ticket)).where(re.match(r"\[P0\]", Ticket.subject)) df = m.select(CriticalTicket.id, CriticalTicket.subject).to_df() print(df) ``` -------------------------------- ### Initialize Async Client Source: https://docs.relational.ai/api/python/v1.0/client/client/client_class/index Construct the async-first root client. Use this when already writing async code. Close the client using `await client.aclose()` or an `async with` statement. ```python Client(core: ClientCore) ``` -------------------------------- ### Calculate Eigenvector Centrality for Weighted Graph Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Computes the eigenvector centrality for each node in a weighted, undirected graph. Similar setup to the unweighted example, but edges are defined with weights. ```python >>> # 1. Set up a weighted, undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=True) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges with weights >>> n1, n2, n3, n4 = [Node.new(id=i) for i in range(1, 5)] >>> model.define(n1, n2, n3, n4) >>> model.define( ... Edge.new(src=n1, dst=n2, weight=0.8), ... Edge.new(src=n2, dst=n3, weight=0.7), ... Edge.new(src=n3, dst=n3, weight=2.0), ... Edge.new(src=n2, dst=n4, weight=1.5) ... ) >>> >>> # 3. Select the eigenvector centrality for each node and inspect >>> node, centrality = Node.ref("node"), Float.ref("centrality") >>> eigenvector_centrality = graph.eigenvector_centrality() >>> model.select(node.id, centrality).where(eigenvector_centrality(node, centrality)).inspect() id centrality 0 1 0.157327 1 2 0.473250 2 3 0.815024 3 4 0.294988 ``` -------------------------------- ### Get Top 10 Highest-Paid Employees Source: https://docs.relational.ai/api/python/v1.0/semantics/std/aggregates/top/index Example of using the `top` aggregate to select the top 10 employees based on their salary. Ensure `Employee` and `salary` are defined in your model. ```python >>> select(Employee).where(aggregates.top(10, Employee.salary)) ``` -------------------------------- ### Verify and Run Jobs with Execution Logging Source: https://docs.relational.ai/build/guides/configuration/execution/index Demonstrates how to verify that the logging configuration is loaded and how to initialize Python logging to capture and display PyRel execution logs. ```python from relationalai.semantics import Model m = Model("MyModel") print(m.config.execution.logging) import logging logging.basicConfig(level=logging.INFO) logging.getLogger("relationalai.client.execution").setLevel(logging.INFO) m.select("hello world").to_df() ``` -------------------------------- ### Install PyRel Source: https://docs.relational.ai/build/setup/jupyter/index Install the relationalai Python package using pip. Ensure you are in the same Python environment where Jupyter is installed. ```sh python -m pip install relationalai ``` -------------------------------- ### Load configuration from file Source: https://docs.relational.ai/api/python/v1.0/config/index Use create_config to automatically discover and load the configuration file. ```python >>> from relationalai.config import create_config >>> cfg = create_config() >>> session = cfg.get_session(name="sf") ``` -------------------------------- ### CLI Init Command Source: https://docs.relational.ai/llms.txt Creates or validates the raiconfig.yaml file using the CLI. ```APIDOC ## CLI Init Command ### Description Creates or validates the `raiconfig.yaml` file. ### Method CLI Command ### Endpoint `init` ### Documentation Link https://docs.relational.ai/api/cli/v1.0/init/index.md ``` -------------------------------- ### Inspect configuration with rai config:explain Source: https://docs.relational.ai/release-notes/python/1.0.4/index Use these commands to view the active configuration settings and their provenance. ```sh rai config:explain rai config:explain --verbose ``` -------------------------------- ### Delete a reasoner example Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/delete_reasoner/index Example usage for deleting a logic reasoner named my_reasoner. ```sql CALL relationalai.api.delete_reasoner('logic', 'my_reasoner'); ``` -------------------------------- ### GET reasoners:get Source: https://docs.relational.ai/api/cli/v1.0/reasoners/get/index Retrieves details for a specific reasoner based on its type and name. ```APIDOC ## GET reasoners:get ### Description Retrieves a specific reasoner by its type and name. ### Method GET ### Endpoint reasoners:get ### Parameters #### Query Parameters - **--type** (text) - Optional - Reasoner type (Logic/Prescriptive/Predictive). - **--name** (text) - Optional - Reasoner name. ### Request Example rai reasoners:get --type Logic --name my_reasoner ### Response #### Success Response (200) - **reasoner** (object) - The details of the requested reasoner. ``` -------------------------------- ### Initialize ClientSync Source: https://docs.relational.ai/api/python/v1.0/client/client_sync/clientsync_class/index Constructor for the synchronous root client. ```python ClientSync(core: ClientCore) ``` -------------------------------- ### Configure Data Settings Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/dataconfig_class/index Examples of configuring data settings using YAML, a dictionary, or a DataConfig instance. ```yaml default_connection: sf connections: sf: type: snowflake # ... data: wait_for_stream_sync: false download_url_type: external ``` ```python >>> from relationalai.config import create_config >>> cfg = create_config( ... data={"wait_for_stream_sync": False, "download_url_type": "external"}, ... ) ``` ```python >>> from relationalai.config import create_config, DataConfig >>> cfg = create_config( ... data=DataConfig(wait_for_stream_sync=False, download_url_type="external"), ... ) ``` -------------------------------- ### Configuration Management Overview Source: https://docs.relational.ai/api/python/v1.0/config/config_fields/index Overview of how to structure and apply configuration settings for the RelationalAI Python SDK. ```APIDOC ## Configuration Management ### Description Configure the RelationalAI environment using either a YAML configuration file (raiconfig.yaml) or programmatically via the `create_config` factory function. ### Configuration Classes - **ExecutionConfig**: Manages execution middleware behavior. - **DataConfig**: Manages data loading, streaming, and export settings. - **CompilerConfig**: Manages query translation and compiler behavior. - **ModelConfig**: Manages model execution defaults. - **DebugConfig**: Manages debug server and error-reporting settings. - **JobsConfig**: Manages job execution parameters. ### Usage Example ```python import relationalai as rai # Programmatic configuration config = rai.create_config({ "execution": {"timeout": 300}, "data": {"streaming": True} }) ``` ``` -------------------------------- ### GET jobs:get Source: https://docs.relational.ai/api/cli/v1.0/jobs/get/index Retrieves details for a specific job based on its type and optional ID. ```APIDOC ## GET jobs:get ### Description Retrieves a job by its type and optional identifier. This command allows users to inspect the status and details of Logic, Prescriptive, or Predictive jobs. ### Method GET ### Endpoint rai jobs:get ### Parameters #### Query Parameters - **--type** (text) - Required - Job type (Logic/Prescriptive/Predictive). - **--id** (text) - Optional - The specific job identifier. - **--include** (choice[]) - Optional - Repeat to include expansions (e.g., --include details --include events). ### Request Example rai jobs:get --type Logic --id 12345 --include details ### Response #### Success Response (200) - **job_details** (object) - The requested job information including status, type, and associated events if requested. #### Response Example { "id": "12345", "type": "Logic", "status": "completed", "details": { ... } } ``` -------------------------------- ### Unweighted Graph Louvain Example Source: https://docs.relational.ai/api/python/v1.0/semantics/reasoners/graph/core/graph_class/index Example demonstrating community detection on an undirected, unweighted dumbbell graph. ```python >>> from relationalai.semantics import Model, Integer >>> from relationalai.semantics.reasoners.graph import Graph >>> >>> # 1. Set up an undirected graph >>> model = Model("test_model") >>> graph = Graph(model, directed=False, weighted=False) >>> Node, Edge = graph.Node, graph.Edge >>> >>> # 2. Define nodes and edges for a dumbbell graph >>> n1, n2, n3, n4, n5, n6 = [Node.new(id=i) for i in range(1, 7)] >>> model.define(n1, n2, n3, n4, n5, n6) >>> model.define( ... # The first three-clique. ... Edge.new(src=n1, dst=n2), Edge.new(src=n1, dst=n3), Edge.new(src=n2, dst=n3), ... # The second three-clique. ... Edge.new(src=n4, dst=n5), Edge.new(src=n4, dst=n6), Edge.new(src=n5, dst=n6), ... # The connection between the three-cliques. ... Edge.new(src=n1, dst=n4) ... ) >>> >>> # 3. Compute community assignments and inspect >>> node, label = Node.ref("node"), Integer.ref("label") >>> louvain = graph.louvain() >>> model.select(node.id, label).where(louvain(node, label)).inspect() id label 0 1 2 1 2 2 2 3 2 3 4 1 4 5 1 5 6 1 ``` -------------------------------- ### rai init Source: https://docs.relational.ai/api/cli/v1.0/init/index Initializes or validates the project configuration file. ```APIDOC ## CLI COMMAND: rai init ### Description Create or validate the raiconfig.yaml configuration file for the project. ### Usage rai init [OPTIONS] ### Options - **--migrate** (Boolean) - Optional - Migrate raiconfig.toml to raiconfig.yaml immediately. Default: False. ``` -------------------------------- ### upper function usage examples Source: https://docs.relational.ai/api/python/v1.0/semantics/std/strings/upper/index Examples showing how to use the upper function within select and where clauses. ```python >>> select(strings.upper(Person.last_name)) >>> select(City.name).where(strings.upper(City.province) == "ONTARIO") ``` -------------------------------- ### strip function usage examples Source: https://docs.relational.ai/api/python/v1.0/semantics/std/strings/strip/index Examples demonstrating how to use the strip function within select and where clauses. ```python >>> select(strings.strip(Person.name)) >>> select(Text.content).where(strings.strip(Text.content) == "string with spaces") ``` -------------------------------- ### Python Range Function Source: https://docs.relational.ai/api/python/v1.0/semantics/std/common/range/index Generates a sequence of integers within a specified range. Supports single argument for stop, two arguments for start and stop, and three arguments for start, stop, and step. The start is inclusive, and the stop is exclusive. ```python range(*args: IntegerValue) -> Expression ``` ```python >>> common.range(10) ``` ```python >>> common.range(5, 15) ``` ```python >>> common.range(0, 20, 2) ``` -------------------------------- ### Client Initialization and Usage Source: https://docs.relational.ai/api/python/v1.0/client/client/client_class/index The async-first root client for interacting with RelationalAI. Use this when your application is already asynchronous. It can be constructed via `await relationalai.client.connect(...)` or `await from_session(...)` and closed using `await client.aclose()` or an `async with` statement. ```APIDOC ## Client Class ### Description Async-first root client. Use this client when you are already writing async code. ### Initialization - Construct via `await relationalai.client.connect(...)` or `await from_session(...)`. - Close via `await client.aclose()` or `async with ...`. ### Key Differences vs ClientSync - `.reasoners` returns an async `ReasonersClient` (methods are `async def`, so you `await`). ### Logging/Representation - Sensitive fields (config, auth tokens, sessions/transports) are excluded from `repr(...)`. ``` -------------------------------- ### Cancel Blob GC Execution Example Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/cancel_blob_gc/index Example of calling the procedure to request cancellation of the current Blob GC pass. ```sql CALL relationalai.api.cancel_blob_gc(); ``` -------------------------------- ### Execute show_warm_engines with full path Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/show_warm_engines/index Example of calling the procedure using the fully qualified path and viewing the resulting output table. ```sql CALL relationalai.api.show_warm_engines(); /*+-------+---------------+--------------------------------+-----------------------------+---------+-------------------------------+-------------------------------+ | TYPE | SIZE | NAME | COMPUTE_POOL | STATUS | CREATED_ON | READY_ON | |-------+---------------+--------------------------------+-----------------------------+---------+--------------------------0----+-------------------------------| | LOGIC | HIGHMEM_X64_S | WARM_ENGINE_LOGIC_a57c7945da89 | RELATIONAL_AI_HIGHMEM_X64_S | READY | 2026-01-28 07:16:55.707 -0800 | 2026-01-28 07:19:31.244 -0800 | | LOGIC | HIGHMEM_X64_M | WARM_ENGINE_LOGIC_9f7d942067d9 | RELATIONAL_AI_HIGHMEM_X64_M | PENDING | 2026-01-28 07:17:05.645 -0800 | NULL | +-------+---------------+--------------------------------+-----------------------------+---------+-------------------------------+-------------------------------+ */ ``` -------------------------------- ### Initialize a RelationalAI Semantic Model Source: https://docs.relational.ai/api/python/v1.0/semantics/index Demonstrates how to import necessary components and instantiate a new semantic model in Python. ```python from relationalai.semantics import Model, define, select, where, String, Integer m = Model() ``` -------------------------------- ### Load and Verify raiconfig.yaml Source: https://docs.relational.ai/build/guides/configuration/files/index Instantiate a Model and verify the default connection settings from the loaded configuration. ```python from relationalai.semantics import Model m = Model("MyModel") session = m.config.get_session() # Verify that the default connection has the expected value: print(m.config.default_connection) ``` -------------------------------- ### Install plugins in Claude Code Source: https://docs.relational.ai/build/agents/skills/index Use the plugin commands within the Claude Code interface to add and install the RelationalAI skills. ```text /plugin marketplace add RelationalAI/rai-agent-skills /plugin install rai@RelationalAI # or use the wizard /plugin ``` -------------------------------- ### Retry Configuration Example Source: https://docs.relational.ai/build/guides/configuration/execution/index This example demonstrates how to configure and access retry settings within the Relational AI LLMs TXT model configuration. ```APIDOC ## Configure Retries ### Description This section explains how to configure the retry policy for job submissions in Relational AI LLMs TXT. The retry policy controls how the system handles transient errors by automatically retrying failed requests. ### Method Configuration via Python SDK ### Endpoint N/A (Configuration within the application) ### Parameters #### Request Body (Conceptual - applied via SDK) - **retries.enabled** (boolean) - Required - Enables or disables the retry mechanism. Defaults to `True`. - **retries.max_attempts** (integer) - Required - The total number of times PyRel will try to submit the job, including the first try. Defaults to `5`. - **retries.base_delay_s** (float) - Required - The initial wait time in seconds between retries. PyRel increases this wait time after each failed try. Defaults to `0.25`. - **retries.max_delay_s** (float) - Required - The longest time in seconds PyRel will wait before it tries again. Defaults to `5.0`. - **retries.jitter** (float) - Required - A factor that adds a small random amount to the wait time to prevent all jobs from retrying at the exact same moment. Defaults to `0.2`. ### Request Example ```python from pyrel.config import Config, ExecutionConfig, RetriesConfig retries_cfg = RetriesConfig( enabled=True, max_attempts=5, base_delay_s=0.25, max_delay_s=5.0, jitter=0.2, ) execution_cfg = ExecutionConfig(retries=retries_cfg) cfg = Config(execution=execution_cfg) m = Model("MyModel", config=cfg) print(m.config.execution.retries.enabled) print(m.config.execution.retries.max_attempts) print(m.config.execution.retries.base_delay_s) print(m.config.execution.retries.max_delay_s) print(m.config.execution.retries.jitter) ``` ### Response #### Success Response (200) Configuration is applied and accessible via the model's config object. No direct HTTP response. #### Response Example ``` True 5 0.25 5.0 0.2 ``` ### Notes - These checks confirm that PyRel loaded the retry policy you configured. - A real retry only occurs when a request fails with a retryable transient error, so these examples do not demonstrate a retry in progress. ### Related - [Create configuration in code](/build/guides/configuration/programmatic) - [ExecutionConfig API reference](/api/python/latest/config/config_fields/executionconfig_class) - [Configure compilation behavior](/build/guides/configuration/compilation) - [Configure data sync behavior](/build/guides/configuration/data-sync) ``` -------------------------------- ### Configuration using a Dictionary Source: https://docs.relational.ai/api/python/v1.0/config/connections/snowflake/programmaticaccesstokenauth_class/index Example of creating a programmatic config using a plain dictionary, without directly importing the authenticator class. ```APIDOC ## Configuration using a Dictionary ### Description Create a programmatic config using a plain dict (no authenticator import). ### Method None (This is a configuration example, not an API endpoint) ### Endpoint None ### Parameters None ### Request Example ```python from relationalai.config import Config cfg = Config(connections={ "sf": { "type": "snowflake", "authenticator": "programmatic_access_token", "account": "my_account", "warehouse": "my_warehouse", "token": "my_pat", } }) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### SQL Query Example for Reasoners Source: https://docs.relational.ai/api/sql/2026.3.29-58b69bc-1/api/reasoners/index Examples of SQL queries to interact with the 'reasoners' view, including listing all reasoners and filtering for specific statuses. ```APIDOC ## SQL Queries for Reasoners ### Description Provides examples of SQL queries to retrieve information from the `relationalai.api.reasoners` view. ### Method N/A (SQL Query) ### Endpoint N/A (SQL Query) ### Parameters N/A (SQL Query) ### Request Body N/A (SQL Query) ### Response N/A (SQL Query) ### Request Example List all reasoners: ```sql SELECT * FROM relationalai.api.reasoners; ``` Filter for idle reasoners (ready and scheduled to suspend): ```sql SELECT * FROM relationalai.api.reasoners WHERE status = 'READY' AND suspends_at IS NOT NULL; ``` See [Compute Resources](/manage/compute-resources#view-available-reasoners) for more usage patterns. ``` -------------------------------- ### Create a logic reasoner via CLI Source: https://docs.relational.ai/build/guides/configuration/reasoners/index Use the CLI to provision a new logic reasoner before configuring it in PyRel. ```bash rai reasoners:create --type logic --name team_logic --size HIGHMEM_X64_S --wait ```