query-engine/README.md
2026-04-09 11:37:46 +02:00

103 lines
2.7 KiB
Markdown

## Query Engine
An experimental Rust project for building query-engine components.
Right now the repository is centered on a chase-based reasoning core plus a
small interactive frontend. The broader target shape is a query engine with
clearer front-end, planning, optimization, and execution boundaries.
### Current scope
- Chase-based rule evaluation over facts, rules, and substitutions
- Restricted-chase style materialization with active-trigger checks
- Provenance-oriented explanations for derived answers
- Script, REPL, and local web UI for experimentation
### Intended direction
The medium-term direction is to evolve this project from a copied
`chase-rs` codebase into a more general query-engine playground with:
- explicit front-end and parsing layers
- internal planning representations
- clearer separation between logical meaning and execution strategy
- support for multiple query-engine experiments instead of only chase logic
The current code does not yet implement a SQL front end, logical plan, or
physical plan. The repository naming, docs, and user-facing surfaces now
reflect that more honestly.
### Quickstart
#### Rust API
```rust
use query_engine::{Atom, Instance, Term, chase};
use query_engine::chase::rule::RuleBuilder;
let instance: Instance = vec![
Atom::new("Parent", vec![Term::constant("alice"), Term::constant("bob")]),
Atom::new("Parent", vec![Term::constant("bob"), Term::constant("carol")]),
]
.into_iter()
.collect();
let rule1 = RuleBuilder::new()
.when("Parent", vec![Term::var("X"), Term::var("Y")])
.then("Ancestor", vec![Term::var("X"), Term::var("Y")])
.build();
let rule2 = RuleBuilder::new()
.when("Ancestor", vec![Term::var("X"), Term::var("Y")])
.when("Parent", vec![Term::var("Y"), Term::var("Z")])
.then("Ancestor", vec![Term::var("X"), Term::var("Z")])
.build();
let result = chase(instance, &[rule1, rule2]);
assert!(result.terminated);
assert_eq!(result.instance.facts_for_predicate("Ancestor").len(), 3);
```
#### CLI
```bash
cargo run -- repl
cargo run -- gui
cargo run -- script examples/scripts/ancestor.chase
```
#### REPL language
```text
fact Parent(alice, bob).
rule Parent(?X, ?Y) -> Ancestor(?X, ?Y).
run.
query Ancestor(?X, ?Y)?
explain Ancestor(alice, carol)?
show facts
show rules
reset
help
```
### Development
For non-trivial changes, run:
```bash
cargo test
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check
```
### Notes
This repository is still centered on a rule-engine core. The longer-term goal
is to grow it into a broader query-engine project without claiming SQL,
logical-planning, or physical-planning support before those layers exist.
### License
This project is licensed under [BSD-3](LICENSE).