Skip to main content

rete_core/
lib.rs

1//! Core on-disk types for the Rete graph file format.
2//!
3//! See `docs/SPEC.md` for the full design. This crate owns the byte-level
4//! layout (header, directory, blocks) and is deliberately free of any I/O or
5//! query logic so it compiles cleanly to both native and `wasm32`.
6
7#![deny(rustdoc::broken_intra_doc_links)]
8#![warn(missing_docs)]
9
10/// The engine version, as published on crates.io.
11///
12/// Language bindings re-export this so a caller can always tell which engine is
13/// embedded in their wheel, npm package, or bundle. That is the question behind
14/// "does my install support feature X?", and it is not answerable from the
15/// binding's own version, which tracks the binding. Client versions match this
16/// crate's `MAJOR.MINOR` (see `scripts/sync_versions.py`) while their patch
17/// component moves independently for binding-only fixes.
18pub const VERSION: &str = env!("CARGO_PKG_VERSION");
19
20#[doc(hidden)]
21pub mod bgp;
22#[doc(hidden)]
23pub mod block_cache;
24pub mod build_trace;
25#[doc(hidden)]
26pub mod card_derive;
27#[doc(hidden)]
28pub mod card_input;
29#[doc(hidden)]
30pub mod card_queries;
31#[doc(hidden)]
32pub mod chunk_cache;
33#[doc(hidden)]
34pub mod dict;
35#[doc(hidden)]
36pub mod dictionary;
37#[doc(hidden)]
38pub mod extbuild;
39mod extbuild_sections;
40mod extsort;
41#[doc(hidden)]
42pub mod file;
43#[doc(hidden)]
44pub mod geo;
45pub mod geo3;
46#[doc(hidden)]
47pub mod header;
48#[doc(hidden)]
49pub mod index;
50
51pub mod ingest;
52pub mod iri;
53pub mod label_index;
54pub mod manifest;
55#[doc(hidden)]
56pub mod meta;
57#[cfg(feature = "parallel")]
58#[doc(hidden)]
59pub mod parallel;
60#[doc(hidden)]
61pub mod pyramid;
62mod quad;
63#[doc(hidden)]
64pub mod reach;
65#[doc(hidden)]
66pub mod reader;
67#[doc(hidden)]
68pub mod reason;
69pub mod recard;
70#[doc(hidden)]
71pub mod results;
72mod row;
73#[doc(hidden)]
74pub mod schema_pyramid;
75pub mod schema_section;
76#[doc(hidden)]
77pub mod service;
78#[doc(hidden)]
79pub mod shacl;
80#[doc(hidden)]
81pub mod sparql;
82#[doc(hidden)]
83pub mod terms;
84#[doc(hidden)]
85pub mod text_index;
86mod text_index_spill;
87#[doc(hidden)]
88pub mod tiling;
89#[doc(hidden)]
90pub mod triples;
91#[doc(hidden)]
92pub mod varint;
93pub mod write_opts;
94
95/// Stable file-format, reader, and in-memory build API.
96pub mod format {
97    pub use crate::file::{
98        append_sections, attach_build_info, content_hash_parts, plan_build_info, read_build_info,
99        replace_metadata, verify, BuildInfoPlan, ByteRange, DumpPlan, FileError, LayoutSegment,
100        PyramidLayout, Rete, TermTriple, TripleProvenance, CODEC_NONE, CODEC_ZSTD, RDF_TYPE,
101    };
102    pub use crate::header::{
103        Header, HeaderError, Section, SectionKind, CURRENT_FORMAT_VERSION, HEADER_LEN, MAGIC,
104        MIN_STABLE_READ_VERSION,
105    };
106    pub use crate::index::ScanPlan;
107    pub use crate::ingest::{
108        assemble_dataset, assemble_dataset_with, assemble_dataset_with_layout,
109        assemble_dataset_with_opts, assemble_dataset_with_opts_algo, assemble_dataset_with_perms,
110        parse, parse_quads, parse_rdfxml, parse_statements, parse_statements_audited_surface,
111        parse_turtle, parse_turtle_surface, BuildStats, DeferredMetadata, FinalCounts, GraphLayout,
112        IngestError, IntoMetadata, QuotedTripleSurface, RawQuad, RawTriple,
113    };
114    pub use crate::recard::{plan_card_rewrite, rewrite_card, CardRewritePlan, REWRITE_CHUNK};
115}
116
117/// Stable **Dataset Card** API — both halves of a card, so that every writer
118/// (`rete build --card-file`, the browser builder, any language binding, any
119/// third-party tool) produces the same card from the same graph.
120///
121/// - The **curated** half ([`crate::card_input`]) is the write-time rules a
122///   hand-authored card document must satisfy: the reserved top level, the
123///   `theme` IRI requirement, the bounded `extra` bag.
124/// - The **derived** half ([`crate::card_derive`] + [`crate::card_queries`])
125///   is the profile computed from the
126///   graph's own statements — predicate/class histograms, vocabularies,
127///   datatypes, languages, the class-link quotient, hubs, affordance signals
128///   and the tiered starter-query library. [`card_derive::derive_card`] is the entry point
129///   for an in-memory quad slice; [`card_derive::derive_card_encoded`] for a streaming build
130///   that only has a dictionary + id-triples; [`card_derive::CardTripleSource`] for anything
131///   else.
132///
133/// Derivation is **opt-in**: it walks the graph a second time, so no build
134/// spends that pass unless the caller asks for a card.
135pub mod card {
136    pub use crate::card_derive::{
137        curated_counts_card, derive_card, derive_card_encoded, derive_card_from,
138        derive_card_streaming, load_card, CardInput, CardTripleSource, ClassLink, Coherence,
139        Creator, DatasetCard, ExampleQuery, LabelIndexSignal, PermutationsSignal, Publisher,
140        QuotedTriplesSignal, Signals, StreamReport, TextIndexSignal, Tier, CARD_TOP_N, GEO_ASWKT,
141        GEO_HASGEOMETRY, O_LITERAL, QUOTED_TRIPLE_SURFACE_RDF12, QUOTED_TRIPLE_SURFACE_RDF_STAR,
142    };
143    pub use crate::card_input::{
144        canonicalize_json, check_description_len, compose_curated_card, json_depth,
145        normalize_description, normalize_extra, normalize_string_list, normalize_themes,
146        validate_curated_card, CARD_DESCRIPTION_MAX_BYTES, CARD_EXTRA_MAX_BYTES,
147        CARD_EXTRA_MAX_DEPTH, CARD_EXTRA_MAX_KEYS, CARD_EXTRA_MAX_KEY_BYTES, CURATED_CARD_FIELDS,
148        UNKNOWN_FIELD_HINT,
149    };
150    pub use crate::card_queries::{
151        audit, audit_examples, claim_of, claim_of_query, example_query_id, generate, Claim,
152        Finding, Observation, Recorded, Substitution, Verdict, STARTER_MAX_BYTES,
153        STARTER_SCAN_BUDGET,
154    };
155}
156
157/// Stable SPARQL, graph-pattern, federation, and result API.
158pub mod query {
159    pub use crate::bgp::{Binding, PatternTerm, TriplePattern};
160    pub use crate::file::TripleProvenance;
161    pub use crate::results::{push_json_string, results_envelope_json};
162    pub use crate::service::{
163        parse_sparql_json_results, sparql_json_ask, sparql_json_results, ServiceClient,
164    };
165    pub use crate::sparql::{
166        eval_query, eval_query_partitioned, eval_query_reasoned, eval_query_with,
167        eval_query_with_warnings, eval_select_communities, eval_sparql, eval_sparql_reasoned,
168        partition_plan, query_predicates, routed_triple_pattern, summary_query_shape,
169        warnings_json, CommunityPartial, CommunitySelect, PartitionPlan, QueryOpts, QueryOutput,
170        QueryWarning, RoutedTriplePattern, SparqlError, SummaryQueryShape, WarningSeverity,
171    };
172}
173
174/// Stable byte-range and lazy-open API for local or remote `.rete` files.
175pub mod range {
176    pub use crate::block_cache::{auto_block, BlockCacheReader, DEFAULT_BLOCK, DEFAULT_CACHE_CAP};
177    pub use crate::file::{
178        read_card_and_build_info_ranged, read_card_and_build_info_with_header,
179        read_metadata_ranged, read_schema_coherence_ranged, read_schema_ranged,
180        read_schema_summary_ranged, read_text_index_token_table_len_ranged, ByteRange,
181        LayoutSegment, SearchView, SummaryView,
182    };
183    pub use crate::reader::{
184        detect_polyglot_base, CountingReader, OffsetReader, RangeReader, SliceReader,
185        POLYGLOT_DIGITS, POLYGLOT_MARKER,
186    };
187}
188
189/// Stable integrity and SHACL validation API.
190pub mod validation {
191    pub use crate::file::verify;
192    pub use crate::shacl::{
193        validate_shacl, DataGraph, GraphView, ReteGraph, Severity, ShaclError, ShaclShapes,
194        ValidationReport, ValidationResult,
195    };
196}
197
198/// Stable RDFS/OWL reasoning and schema-coherence API.
199pub mod reasoning {
200    pub use crate::file::{
201        read_schema_coherence_ranged, schema_coherence, schema_summary, TermTriple,
202    };
203    pub use crate::reason::{reason, Inconsistency, Reasoning, REASON_RULESET};
204    pub use crate::sparql::{eval_query_reasoned, eval_sparql_reasoned};
205}
206
207#[doc(hidden)]
208pub use bgp::{eval_bgp, Binding, PatternTerm, TriplePattern};
209#[doc(hidden)]
210pub use block_cache::{auto_block, BlockCacheReader, DEFAULT_BLOCK, DEFAULT_CACHE_CAP};
211#[doc(hidden)]
212pub use dict::{DictSection, DictSectionBuilder};
213#[doc(hidden)]
214pub use dictionary::{Dictionary, DictionaryBuilder};
215#[doc(hidden)]
216pub use file::{
217    append_sections, attach_build_info, build_pyramid_meta, build_pyramid_meta_algo,
218    build_pyramid_meta_layout, build_pyramid_meta_with, compute_text_index, plan_build_info,
219    read_build_info, read_card_and_build_info_ranged, read_card_and_build_info_with_header,
220    read_metadata_ranged, read_schema_coherence_ranged, read_schema_ranged,
221    read_schema_summary_ranged, read_text_index_token_table_len_ranged, replace_metadata,
222    schema_classes, schema_coherence, schema_summary, spill_threshold_for, split_memory_budget,
223    verify, verify_ranged, write_dataset, write_dataset_with_metadata, write_file, BuildInfoPlan,
224    ByteRange, DumpPlan, FixedOverhead, LayoutSegment, MemoryBudget, PyramidLayout, Rete,
225    SearchView, SummaryView, TermTriple, TripleProvenance, CODEC_NONE, CODEC_ZSTD,
226    DEFAULT_EXPORT_BUDGET_MB, DEFAULT_QUERY_BUDGET_MB, DEFAULT_TILE_BUDGET, RDF_TYPE,
227};
228#[doc(hidden)]
229pub use header::{
230    Header, HeaderError, Section, SectionKind, CURRENT_FORMAT_VERSION, HEADER_LEN, MAGIC,
231    MIN_STABLE_READ_VERSION,
232};
233#[doc(hidden)]
234pub use index::{GraphIndex, GraphIndexBuilder, IndexPermutation, Pattern, PermSet, ScanPlan};
235pub use ingest::GraphLayout;
236pub use iri::{
237    iri_content_defect, sanitize_iri_content, sanitize_term, term_defect, IriDefect, IriReport,
238};
239#[doc(hidden)]
240pub use label_index::{read_label_index_entries_ranged, LabelIndex};
241#[doc(hidden)]
242pub use meta::{
243    CharSet, ClassNode, ClassRelation, CommunityDescriptor, LabelEntry, LevelLinks, LevelRollup,
244    PredStat, PyramidMeta,
245};
246#[doc(hidden)]
247pub use pyramid::{
248    build_dendrogram, louvain_one_level, louvain_one_level_stats, project_graph, Dendrogram, Graph,
249    LevelStats, Partition, PyramidAlgo, MAX_LOUVAIN_PASSES,
250};
251#[doc(hidden)]
252pub use reach::{batch_reach_serial, build_adjacency, reach_one};
253#[doc(hidden)]
254pub use reader::{
255    detect_polyglot_base, CountingReader, OffsetReader, RangeReader, SliceReader, POLYGLOT_DIGITS,
256    POLYGLOT_MARKER,
257};
258#[doc(hidden)]
259pub use reason::{reason, Inconsistency, Reasoning, REASON_RULESET};
260#[doc(hidden)]
261pub use results::{push_json_string, results_envelope_json};
262#[doc(hidden)]
263pub use schema_pyramid::build_schema_pyramid;
264#[doc(hidden)]
265pub use schema_section::SchemaMeta;
266#[doc(hidden)]
267pub use service::{parse_sparql_json_results, sparql_json_ask, sparql_json_results, ServiceClient};
268#[doc(hidden)]
269pub use shacl::{
270    validate_shacl, DataGraph, GraphView, ReteGraph, Severity, ShaclError, ShaclShapes,
271    ValidationReport, ValidationResult,
272};
273#[doc(hidden)]
274pub use sparql::{
275    eval_query, eval_query_partitioned, eval_query_reasoned, eval_query_with,
276    eval_query_with_warnings, eval_select_communities, eval_sparql, eval_sparql_reasoned,
277    parse_select, partition_plan, query_predicates, routed_triple_pattern, summary_query_shape,
278    warnings_json, Agg, CommunityPartial, CommunitySelect, FExpr, GraphTarget, GroupSpec, Op,
279    PartitionPlan, PathAst, Plan, QueryOpts, QueryOutput, QueryWarning, Rep, RoutedTriplePattern,
280    Select, SparqlError, SummaryQueryShape, WarningSeverity,
281};
282#[doc(hidden)]
283pub use terms::{NodeId, ObjectId, PredicateId, SubjectId, TermToken};
284#[doc(hidden)]
285pub use text_index::{
286    tokenize, IntoTextIndex, TextIndex, TextIndexBuilder, TextIndexGraphs, TextIndexPredicates,
287    TextIndexScope,
288};
289#[doc(hidden)]
290pub use tiling::{choose_round_for_budget, summarize, tile_by_community, SuperEdge, Tile};
291#[doc(hidden)]
292pub use triples::{GroupDirectory, Triple, TripleBlock, TripleBlockBuilder, ZoneMap};