pub struct CategoryLayer {
pub summaries: Vec<CategorySummary>,
pub name_to_index: HashMap<String, usize>,
pub graph: CategoryGraph,
pub inner_spheres: HashMap<usize, InnerSphere>,
pub domain_groups: Vec<DomainGroup>,
pub group_inner_spheres: HashMap<usize, InnerSphere>,
pub spatial_quality: SpatialQuality,
/* private fields */
}Expand description
Category Enrichment Layer: aggregate statistics, inter-category graph, bridge item detection, and automatic inner spheres over a projected SphereQL corpus.
This is a read-only structure computed from an existing pipeline’s data. It adds category-level reasoning without modifying the underlying projection or spatial index.
Fields§
§summaries: Vec<CategorySummary>One summary per unique category, in insertion order.
name_to_index: HashMap<String, usize>Map from category name to index in summaries.
graph: CategoryGraphThe inter-category adjacency graph.
inner_spheres: HashMap<usize, InnerSphere>Inner spheres keyed by category index. Only present for categories that meet the size and EVR-improvement thresholds.
domain_groups: Vec<DomainGroup>Domain groups discovered from category geometry. Default
nearest() routing chooses the closest group via these centroids.
group_inner_spheres: HashMap<usize, InnerSphere>Inner spheres keyed by domain-group index. Built only when the group’s union of members beats the EVR threshold versus the outer projection — the realistic-grouping unit per the v2 routing design (replaces the previous one-per-category default).
spatial_quality: SpatialQualityPre-computed spatial properties of the category layout on S². Used for bridge quality scoring, confidence signals, and routing.
Implementations§
Source§impl CategoryLayer
impl CategoryLayer
Sourcepub fn build<P: Projection>(
categories: &[String],
embeddings: &[Embedding],
projected_positions: &[SphericalPoint],
projection: &P,
evr: f64,
) -> Self
pub fn build<P: Projection>( categories: &[String], embeddings: &[Embedding], projected_positions: &[SphericalPoint], projection: &P, evr: f64, ) -> Self
Build the category enrichment layer from pipeline data.
categories[i]is the category name for item i.embeddings[i]is the raw embedding for item i.projected_positions[i]is the spherical position on the outer sphere.projectionis used to project category centroids and measure per-point certainty for inner sphere threshold decisions.
Inner spheres are automatically constructed for categories that:
- Have ≥ 20 members
- Show ≥ 0.10 EVR improvement over the global projection
Categories with ≥ 80 members additionally try kernel PCA and select it if it improves EVR by ≥ 0.05 over linear PCA.
O(N·C + C²) for the base layer, plus O(n_c²·d) per inner sphere.
Uses PipelineConfig::default for all tunables. Call
Self::build_with_config to override.
Sourcepub fn build_with_config<P: Projection>(
categories: &[String],
embeddings: &[Embedding],
projected_positions: &[SphericalPoint],
projection: &P,
evr: f64,
config: &PipelineConfig,
) -> Self
pub fn build_with_config<P: Projection>( categories: &[String], embeddings: &[Embedding], projected_positions: &[SphericalPoint], projection: &P, evr: f64, config: &PipelineConfig, ) -> Self
Configurable variant of Self::build. Threads a PipelineConfig
through spatial quality, bridge classification, and inner-sphere
gating.
Sourcepub fn annotate_bridge_relations(&mut self, labels: &[String])
pub fn annotate_bridge_relations(&mut self, labels: &[String])
Annotate every bridge with a heuristically inferred RelationType.
Looks at each bridge item’s concept label (indexed into labels
by BridgeItem::item_index) along with its source and target
category names. Bridges whose label doesn’t match any cue remain
relation: None.
Sourcepub fn relation_census(&self) -> HashMap<Option<RelationType>, usize>
pub fn relation_census(&self) -> HashMap<Option<RelationType>, usize>
Histogram of relation types across every bridge in the graph.
None is included as its own bucket so callers can see how many
bridges remain unlabeled after annotation.
Sourcepub fn num_categories(&self) -> usize
pub fn num_categories(&self) -> usize
Number of categories.
Sourcepub fn get_category(&self, name: &str) -> Option<&CategorySummary>
pub fn get_category(&self, name: &str) -> Option<&CategorySummary>
Look up a category by name.
Sourcepub fn category_neighbors(
&self,
category_name: &str,
k: usize,
) -> Vec<&CategorySummary>
pub fn category_neighbors( &self, category_name: &str, k: usize, ) -> Vec<&CategorySummary>
Get the k nearest neighbor categories to the given category.
Sourcepub fn bridge_items(
&self,
source_category: &str,
target_category: &str,
max_bridges: usize,
) -> Vec<&BridgeItem>
pub fn bridge_items( &self, source_category: &str, target_category: &str, max_bridges: usize, ) -> Vec<&BridgeItem>
Get bridge items between two categories.
Sourcepub fn category_path(
&self,
source_category: &str,
target_category: &str,
) -> Option<CategoryPath>
pub fn category_path( &self, source_category: &str, target_category: &str, ) -> Option<CategoryPath>
Find the shortest path between two categories through the category graph.
Sourcepub fn categories_near_embedding<P: Projection>(
&self,
embedding: &Embedding,
projection: &P,
max_angle: f64,
) -> Vec<(usize, f64)>
pub fn categories_near_embedding<P: Projection>( &self, embedding: &Embedding, projection: &P, max_angle: f64, ) -> Vec<(usize, f64)>
Find all categories whose centroid is within max_angle radians
of the given embedding’s projected position.
Sourcepub fn categories_near_embedding_weighted<P: Projection>(
&self,
embedding: &Embedding,
projection: &P,
max_angle: f64,
) -> Vec<(usize, f64, f64, f64)>
pub fn categories_near_embedding_weighted<P: Projection>( &self, embedding: &Embedding, projection: &P, max_angle: f64, ) -> Vec<(usize, f64, f64, f64)>
Certainty-weighted category routing.
Like Self::categories_near_embedding but penalizes routes through
low-certainty projection regions. The effective distance is scaled
by 1 / sqrt(certainty), so poorly-projected queries don’t get
routed to whatever random centroid happens to be angularly close
in the distorted projection.
Returns (category_index, raw_angular_distance, effective_distance, certainty).
Sourcepub fn has_inner_sphere(&self, category_name: &str) -> bool
pub fn has_inner_sphere(&self, category_name: &str) -> bool
Whether a given category has an inner sphere.
Sourcepub fn get_inner_sphere(&self, category_name: &str) -> Option<&InnerSphere>
pub fn get_inner_sphere(&self, category_name: &str) -> Option<&InnerSphere>
Get the inner sphere for a category, if one exists.
Sourcepub fn num_inner_spheres(&self) -> usize
pub fn num_inner_spheres(&self) -> usize
Number of categories that have inner spheres.
Sourcepub fn drill_down_with_projection<P: Projection>(
&self,
category_name: &str,
embedding: &Embedding,
projection: &P,
k: usize,
) -> Vec<DrillDownResult>
pub fn drill_down_with_projection<P: Projection>( &self, category_name: &str, embedding: &Embedding, projection: &P, k: usize, ) -> Vec<DrillDownResult>
Drill down with an explicit outer projection for the fallback case.
When no inner sphere exists, the query is projected using the provided projection and compared against stored outer positions.
Sourcepub fn drill_down_group(
&self,
group_index: usize,
embedding: &Embedding,
k: usize,
) -> Vec<DrillDownResult>
pub fn drill_down_group( &self, group_index: usize, embedding: &Embedding, k: usize, ) -> Vec<DrillDownResult>
Drill down into a domain group’s inner sphere. Returns an empty vec if the group index is unknown or has no inner sphere.
Used by the v2 default nearest() path: route to the closest
group, then run k-NN against the group-level inner positions.
Sourcepub fn nearest_group(&self, pos: &SphericalPoint) -> Option<(usize, f64, f64)>
pub fn nearest_group(&self, pos: &SphericalPoint) -> Option<(usize, f64, f64)>
Index of the domain group whose centroid is nearest to pos,
along with the angular distance to the second-nearest group’s
centroid (or f64::INFINITY if there is only one group).
The default nearest() routing in
SphereQLPipeline drills
into the nearest group’s inner sphere only when
nearest_dist / second_dist < group_routing_alpha; the second
distance is returned alongside so the caller can apply that
gate without recomputing.
Sourcepub fn inner_sphere_stats(&self) -> Vec<InnerSphereReport>
pub fn inner_sphere_stats(&self) -> Vec<InnerSphereReport>
Report which categories have inner spheres, their projection type, and EVR metrics.
Trait Implementations§
Source§impl Clone for CategoryLayer
impl Clone for CategoryLayer
Source§fn clone(&self) -> CategoryLayer
fn clone(&self) -> CategoryLayer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CategoryLayer
impl !UnwindSafe for CategoryLayer
impl Freeze for CategoryLayer
impl Send for CategoryLayer
impl Sync for CategoryLayer
impl Unpin for CategoryLayer
impl UnsafeUnpin for CategoryLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more