A Streamlit application for exploring RelationalAI knowledge graph models, running natural language queries, and building business rules — all powered by Claude.
The app has three tabs:
- Model Explorer — Browse entities, properties, relationships, and subtypes in your knowledge graph model
- NL Query — Ask natural language questions and get auto-generated PyRel queries with results
- Rule Builder — Describe business rules in plain English and have them decomposed, code-generated, and merged into your model
flowchart LR
User["User"] --> UI["Streamlit UI"]
UI --> Explore["Model Explorer"]
UI --> Query["NL Query"]
UI --> Build["Rule Builder"]
Explore --> Parser["Model Parser"]
Parser --> ModelFiles[("PyRel Models")]
Query --> Claude["Claude API"]
Build --> Claude
Claude --> Sanitize["Code Sanitizer"]
Sanitize --> Runner["PyRel Runner"]
Runner --> SF[("Snowflake + RAI")]
Build --> Merge["Merge into Model"]
Merge --> ModelFiles
Model Explorer — Parses .py model files and displays concepts, properties, and relationships.
NL Query — Converts natural language questions into PyRel queries via Claude, sanitizes them, and executes against Snowflake/RAI.
Rule Builder — Takes a plain English rule through four stages: decompose (Claude plans the rule) → generate (Claude writes PyRel code) → sanitize (validate & fix) → merge (insert into model file).
- Python 3.11+
- A Snowflake account with RelationalAI installed
- An Anthropic API key for Claude
- Data loaded into Snowflake tables matching your model schema
-
Clone the repository:
git clone https://github.com/manish-code125/rai-rule-builder.git cd rai-rule-builder -
Install dependencies:
pip install -r requirements.txt
-
Configure credentials:
cp .env.example .env # Edit .env and add your Anthropic API key cp raiconfig.yaml.example raiconfig.yaml # Edit raiconfig.yaml with your Snowflake connection details
-
Run the app:
./run.sh # Or directly: python3 -m streamlit run app/main.pyThe app will open at
http://localhost:8501.
rai-rule-builder/
├── app/ # Streamlit application
│ ├── main.py # Main UI (3 tabs)
│ ├── rule_builder.py # Rule generation & code sanitization
│ ├── pyrel_runner.py # Query execution & model loading
│ ├── model_parser.py # Model entity/relationship parsing
│ ├── nl_query.py # NL-to-query conversion
│ ├── llm_client.py # Anthropic API client
│ └── prompts/ # LLM prompt templates
├── src/models/ # PyRel example models
│ ├── amd_cdo_demo.py # AMD CDO restaurant analytics model
│ ├── amd_food_truck.py # Food truck model with business rules
│ └── movie_wiki.py # Movie wiki knowledge graph model
├── .claude/ # Claude Code skills & knowledge base
│ ├── rai_configuration/ # Config, connections, engine management
│ ├── rai_cortex_integration/ # Snowflake Cortex AI integration
│ ├── rai_onboarding/ # Getting started with PyRel v1
│ ├── rai_ontology_design/ # Knowledge graph modeling patterns
│ ├── rai_pyrel_coding/ # PyRel language reference & examples
│ ├── rai_querying/ # Query construction, joins, export
│ ├── rai_rules_authoring/ # Rule authoring patterns
│ ├── rai_prescriptive_problem_discovery/ # Problem discovery
│ ├── rai_prescriptive_problem_formulation/ # Optimization formulation
│ ├── rai_prescriptive_solver_management/ # Solver config & debugging
│ └── rai_prescriptive_results_interpretation/ # Results analysis
├── validate_loyalty_rescue.py # Validation script for Loyalty Rescue rule
├── loyalty_rescue_validation_results.txt # Query results
├── requirements.txt
├── run.sh
├── raiconfig.yaml.example
└── .env.example
Food truck analytics model with 15+ base entities and computed business rules including:
- HighChurnRiskCustomer — Customers with churn score > 0.7
- HighROIPromotion — Promotions with ROI > 1.5
- CannibalizationRiskHotspot — Locations where trucks with overlapping cuisine and close proximity risk cannibalizing each other's sales
- LoyaltyRescueTarget — High-churn customers whose favorite food truck has a high-ROI promotion they're not being targeted by, matched on cuisine preference
Restaurant analytics model with customer, order, food truck, menu, promotion, and inventory entities.
Movie knowledge graph with films, actors, directors, genres, awards, and relationships.
- Create a new
.pyfile undersrc/models/ - Define your model using PyRel v1 semantics (
relationalai.semantics) - Register it in
app/pyrel_runner.py(MODEL_REGISTRY), or upload through the app's Model Explorer tab
The .claude/ directory contains 12 skill categories that enhance Claude Code's understanding of PyRel v1:
| Skill | Purpose |
|---|---|
rai_configuration |
Config files, Snowflake/DuckDB connections, engine management |
rai_onboarding |
Getting started guide for new PyRel v1 projects |
rai_ontology_design |
Knowledge graph modeling — concepts, properties, relationships |
rai_pyrel_coding |
PyRel syntax, expressions, standard library |
rai_querying |
Queries, aggregations, joins, DataFrame export |
rai_rules_authoring |
Business rule patterns and code generation |
rai_cortex_integration |
Snowflake Cortex AI + RAI integration |
rai_prescriptive_problem_discovery |
Identifying optimization opportunities |
rai_prescriptive_problem_formulation |
Variables, constraints, objectives |
rai_prescriptive_solver_management |
Solver config, debugging, scenarios |
rai_prescriptive_results_interpretation |
Analyzing optimization results |
These skills are automatically loaded when using Claude Code in this project.
Private — internal use only.