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_progress;
25pub mod build_record;
26pub mod build_trace;
27#[doc(hidden)]
28pub mod card_derive;
29#[doc(hidden)]
30pub mod card_input;
31#[doc(hidden)]
32pub mod card_queries;
33#[doc(hidden)]
34pub mod chunk_cache;
35#[doc(hidden)]
36pub mod dict;
37#[doc(hidden)]
38pub mod dictionary;
39#[doc(hidden)]
40pub mod extbuild;
41mod extbuild_remap;
42mod extbuild_sections;
43mod extbuild_spill;
44mod extbuild_v06;
45mod extsort;
46#[doc(hidden)]
47pub mod file;
48#[doc(hidden)]
49pub mod geo;
50pub mod geo3;
51#[doc(hidden)]
52pub mod guard;
53#[doc(hidden)]
54pub mod header;
55pub mod hll;
56#[doc(hidden)]
57pub mod index;
58
59pub mod ingest;
60pub mod iri;
61pub mod label_index;
62pub mod manifest;
63#[doc(hidden)]
64pub mod meta;
65#[cfg(feature = "parallel")]
66#[doc(hidden)]
67pub mod parallel;
68#[doc(hidden)]
69pub mod pyramid;
70mod quad;
71#[doc(hidden)]
72pub mod reach;
73#[doc(hidden)]
74pub mod reader;
75#[doc(hidden)]
76pub mod reason;
77pub mod recard;
78#[doc(hidden)]
79pub mod results;
80mod row;
81#[doc(hidden)]
82pub mod schema_pyramid;
83pub mod schema_section;
84#[doc(hidden)]
85pub mod service;
86#[doc(hidden)]
87pub mod shacl;
88#[doc(hidden)]
89pub mod sparql;
90/// The memory available to this process and the default query budget sized
91/// from it (native targets only).
92#[cfg(not(target_arch = "wasm32"))]
93pub mod sysmem;
94#[doc(hidden)]
95pub mod terms;
96#[doc(hidden)]
97pub mod text_index;
98mod text_index_spill;
99#[doc(hidden)]
100pub mod tiling;
101#[doc(hidden)]
102pub mod triples;
103pub mod v06;
104#[doc(hidden)]
105pub mod varint;
106pub mod write_opts;
107
108/// Stable file-format, reader, and in-memory build API.
109pub mod format {
110    pub use crate::file::{
111        append_sections, attach_build_info, content_hash_parts, plan_build_info, read_build_info,
112        replace_metadata, verify, BuildInfoPlan, ByteRange, DumpPlan, FileError, LayoutSegment,
113        PyramidLayout, Rete, TermTriple, TripleProvenance, CODEC_NONE, CODEC_ZSTD, RDF_TYPE,
114    };
115    pub use crate::header::{
116        Header, HeaderError, Section, SectionKind, CURRENT_FORMAT_VERSION, HEADER_LEN,
117        LEGACY_FORMAT_VERSION, MAGIC, MIN_STABLE_READ_VERSION,
118    };
119    pub use crate::index::ScanPlan;
120    pub use crate::ingest::{
121        assemble_dataset, assemble_dataset_with, assemble_dataset_with_layout,
122        assemble_dataset_with_opts, assemble_dataset_with_opts_algo, assemble_dataset_with_perms,
123        parse, parse_quads, parse_rdfxml, parse_statements, parse_statements_audited_surface,
124        parse_turtle, parse_turtle_surface, BuildStats, DeferredMetadata, FinalCounts, GraphLayout,
125        IngestError, IntoMetadata, QuotedTripleSurface, RawQuad, RawTriple,
126    };
127    #[cfg(not(target_arch = "wasm32"))]
128    pub use crate::recard::commit_card_append;
129    pub use crate::recard::{
130        card_append_hash, plan_card_append, plan_card_rewrite, rewrite_card, CardAppendPlan,
131        CardRewritePlan, REWRITE_CHUNK,
132    };
133}
134
135/// Stable **Dataset Card** API — both halves of a card, so that every writer
136/// (`rete build --card-file`, the browser builder, any language binding, any
137/// third-party tool) produces the same card from the same graph.
138///
139/// - The **curated** half ([`crate::card_input`]) is the write-time rules a
140///   hand-authored card document must satisfy: the reserved top level, the
141///   `theme` IRI requirement, the bounded `extra` bag.
142/// - The **derived** half ([`crate::card_derive`] + [`crate::card_queries`])
143///   is the profile computed from the
144///   graph's own statements — predicate/class histograms, vocabularies,
145///   datatypes, languages, the class-link quotient, hubs, affordance signals
146///   and the tiered starter-query library. [`card_derive::derive_card`] is the entry point
147///   for an in-memory quad slice; [`card_derive::derive_card_encoded`] for a streaming build
148///   that only has a dictionary + id-triples; [`card_derive::CardTripleSource`] for anything
149///   else.
150///
151/// Derivation is **opt-in**: it walks the graph a second time, so no build
152/// spends that pass unless the caller asks for a card.
153pub mod card {
154    pub use crate::card_derive::{
155        curated_counts_card, derive_card, derive_card_encoded, derive_card_from,
156        derive_card_streaming, load_card, CardInput, CardTripleSource, ClassLink, Coherence,
157        Creator, DatasetCard, ExampleQuery, LabelIndexSignal, PermutationsSignal, Publisher,
158        QuotedTriplesSignal, Signals, StreamReport, TextIndexSignal, Tier, CARD_TOP_N, GEO_ASWKT,
159        GEO_HASGEOMETRY, NS_TALLY_CAP, NS_TALLY_ENTRY_BYTES, O_LITERAL,
160        QUOTED_TRIPLE_SURFACE_RDF12, QUOTED_TRIPLE_SURFACE_RDF_STAR,
161    };
162    pub use crate::card_input::{
163        canonicalize_json, check_description_len, compose_curated_card, json_depth,
164        normalize_description, normalize_extra, normalize_string_list, normalize_themes,
165        validate_curated_card, CARD_DESCRIPTION_MAX_BYTES, CARD_EXTRA_MAX_BYTES,
166        CARD_EXTRA_MAX_DEPTH, CARD_EXTRA_MAX_KEYS, CARD_EXTRA_MAX_KEY_BYTES, CURATED_CARD_FIELDS,
167        UNKNOWN_FIELD_HINT,
168    };
169    pub use crate::card_queries::{
170        audit, audit_examples, claim_of, claim_of_query, example_query_id, generate, Claim,
171        Finding, Observation, Recorded, Substitution, Verdict, STARTER_MAX_BYTES,
172        STARTER_SCAN_BUDGET,
173    };
174}
175
176/// Stable SPARQL, graph-pattern, federation, and result API.
177pub mod query {
178    pub use crate::bgp::{Binding, PatternTerm, TriplePattern};
179    pub use crate::file::TripleProvenance;
180    pub use crate::results::{push_json_string, results_envelope_json};
181    pub use crate::service::{
182        parse_sparql_json_results, sparql_json_ask, sparql_json_results, ServiceClient,
183    };
184    pub use crate::sparql::{
185        eval_query, eval_query_partitioned, eval_query_reasoned, eval_query_with,
186        eval_query_with_warnings, eval_select_communities, eval_sparql, eval_sparql_reasoned,
187        partition_plan, query_predicates, routed_triple_pattern, summary_query_shape,
188        warnings_json, CommunityPartial, CommunitySelect, PartitionPlan, QueryOpts, QueryOutput,
189        QueryWarning, RoutedTriplePattern, SparqlError, SummaryQueryShape, WarningSeverity,
190    };
191}
192
193/// Stable byte-range and lazy-open API for local or remote `.rete` files.
194pub mod range {
195    pub use crate::block_cache::{auto_block, BlockCacheReader, DEFAULT_BLOCK, DEFAULT_CACHE_CAP};
196    pub use crate::file::{
197        read_card_and_build_info_ranged, read_card_and_build_info_with_header,
198        read_metadata_ranged, read_schema_coherence_ranged, read_schema_ranged,
199        read_schema_summary_ranged, read_text_index_token_table_len_ranged, ByteRange,
200        LayoutSegment, SearchView, SummaryView,
201    };
202    pub use crate::reader::{
203        detect_polyglot_base, BytesReader, CountingReader, OffsetReader, PrefixReader, RangeReader,
204        SliceReader, POLYGLOT_DIGITS, POLYGLOT_MARKER,
205    };
206}
207
208/// Stable integrity and SHACL validation API.
209pub mod validation {
210    pub use crate::file::verify;
211    pub use crate::shacl::{
212        validate_shacl, DataGraph, GraphView, ReteGraph, Severity, ShaclError, ShaclShapes,
213        ValidationReport, ValidationResult,
214    };
215}
216
217/// Stable RDFS/OWL reasoning and schema-coherence API.
218pub mod reasoning {
219    pub use crate::file::{
220        read_schema_coherence_ranged, schema_coherence, schema_summary, TermTriple,
221    };
222    pub use crate::reason::{reason, Inconsistency, Reasoning, REASON_RULESET};
223    pub use crate::sparql::{eval_query_reasoned, eval_sparql_reasoned};
224}
225
226#[doc(hidden)]
227pub use bgp::{eval_bgp, Binding, PatternTerm, TriplePattern};
228#[doc(hidden)]
229pub use block_cache::{auto_block, BlockCacheReader, DEFAULT_BLOCK, DEFAULT_CACHE_CAP};
230#[doc(hidden)]
231pub use dict::{DictSection, DictSectionBuilder};
232#[doc(hidden)]
233pub use dictionary::{Dictionary, DictionaryBuilder};
234#[doc(hidden)]
235pub use file::{
236    append_sections, attach_build_info, build_pyramid_meta, build_pyramid_meta_algo,
237    build_pyramid_meta_layout, build_pyramid_meta_with, compute_text_index, plan_build_info,
238    read_build_info, read_card_and_build_info_ranged, read_card_and_build_info_with_header,
239    read_metadata_ranged, read_schema_coherence_ranged, read_schema_ranged,
240    read_schema_summary_ranged, read_text_index_token_table_len_ranged, replace_metadata,
241    schema_classes, schema_coherence, schema_summary, spill_threshold_for, split_memory_budget,
242    verify, verify_ranged, write_dataset, write_dataset_v05, write_dataset_with_metadata,
243    write_dataset_with_metadata_v05, write_file, write_file_v05, BuildInfoPlan, ByteRange,
244    DumpPlan, FixedOverhead, LayoutSegment, MemoryBudget, PyramidLayout, Rete, SearchView,
245    SummaryView, TermTriple, TripleProvenance, CODEC_NONE, CODEC_ZSTD, DEFAULT_EXPORT_BUDGET_MB,
246    DEFAULT_QUERY_BUDGET_MB, DEFAULT_TILE_BUDGET, RDF_TYPE,
247};
248#[doc(hidden)]
249pub use header::{
250    Header, HeaderError, Section, SectionKind, CURRENT_FORMAT_VERSION, HEADER_LEN,
251    LEGACY_FORMAT_VERSION, MAGIC, MIN_STABLE_READ_VERSION,
252};
253#[doc(hidden)]
254pub use index::{GraphIndex, GraphIndexBuilder, IndexPermutation, Pattern, PermSet, ScanPlan};
255pub use ingest::GraphLayout;
256pub use iri::{
257    iri_content_defect, sanitize_iri_content, sanitize_term, term_defect, IriDefect, IriReport,
258};
259#[doc(hidden)]
260pub use label_index::{read_label_index_entries_ranged, LabelIndex};
261#[doc(hidden)]
262pub use meta::{
263    CharSet, ClassNode, ClassRelation, CommunityDescriptor, LabelEntry, LevelLinks, LevelRollup,
264    PredStat, PyramidMeta,
265};
266#[doc(hidden)]
267pub use pyramid::{
268    build_dendrogram, louvain_one_level, louvain_one_level_stats, project_graph, Dendrogram, Graph,
269    LevelStats, Partition, PyramidAlgo, MAX_LOUVAIN_PASSES,
270};
271#[doc(hidden)]
272pub use reach::{batch_reach_serial, build_adjacency, reach_one};
273#[doc(hidden)]
274pub use reader::{
275    detect_polyglot_base, BytesReader, CountingReader, OffsetReader, PrefixReader, RangeReader,
276    SliceReader, POLYGLOT_DIGITS, POLYGLOT_MARKER,
277};
278#[doc(hidden)]
279pub use reason::{reason, Inconsistency, Reasoning, REASON_RULESET};
280#[doc(hidden)]
281pub use results::{push_json_string, results_envelope_json};
282#[doc(hidden)]
283pub use schema_pyramid::build_schema_pyramid;
284#[doc(hidden)]
285pub use schema_section::SchemaMeta;
286#[doc(hidden)]
287pub use service::{parse_sparql_json_results, sparql_json_ask, sparql_json_results, ServiceClient};
288#[doc(hidden)]
289pub use shacl::{
290    validate_shacl, DataGraph, GraphView, ReteGraph, Severity, ShaclError, ShaclShapes,
291    ValidationReport, ValidationResult,
292};
293#[doc(hidden)]
294pub use sparql::{
295    eval_query, eval_query_partitioned, eval_query_reasoned, eval_query_with,
296    eval_query_with_warnings, eval_select_communities, eval_sparql, eval_sparql_reasoned,
297    parse_select, partition_plan, query_predicates, routed_triple_pattern, summary_query_shape,
298    warnings_json, Agg, CommunityPartial, CommunitySelect, FExpr, GraphTarget, GroupSpec, Op,
299    PartitionPlan, PathAst, Plan, QueryOpts, QueryOutput, QueryWarning, Rep, RoutedTriplePattern,
300    Select, SparqlError, SummaryQueryShape, WarningSeverity,
301};
302#[cfg(not(target_arch = "wasm32"))]
303pub use sysmem::{
304    available_memory, default_query_budget_mb, MIN_DEFAULT_QUERY_BUDGET_MB, QUERY_BUDGET_ENV,
305};
306#[doc(hidden)]
307pub use terms::{NodeId, ObjectId, PredicateId, SubjectId, TermToken};
308#[doc(hidden)]
309pub use text_index::{
310    tokenize, IntoTextIndex, TextIndex, TextIndexBuilder, TextIndexGraphs, TextIndexPredicates,
311    TextIndexScope,
312};
313#[doc(hidden)]
314pub use tiling::{choose_round_for_budget, summarize, tile_by_community, SuperEdge, Tile};
315#[doc(hidden)]
316pub use triples::{GroupDirectory, Triple, TripleBlock, TripleBlockBuilder, ZoneMap};
317
318// HTTP(S) range reads for native hosts (the `http` feature): the reader the
319// CLI and the Python and R clients share. Its docs are the module's own (an
320// outer doc here would move their intra-doc links to this scope).
321#[cfg(feature = "http")]
322pub mod http;