Skip to main content

CategoryLayer

Struct CategoryLayer 

Source
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: CategoryGraph

The 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: SpatialQuality

Pre-computed spatial properties of the category layout on S². Used for bridge quality scoring, confidence signals, and routing.

Implementations§

Source§

impl CategoryLayer

Source

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.
  • projection is used to project category centroids and measure per-point certainty for inner sphere threshold decisions.

Inner spheres are automatically constructed for categories that:

  1. Have ≥ 20 members
  2. 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.

Source

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.

Source

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.

Source

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.

Source

pub fn num_categories(&self) -> usize

Number of categories.

Source

pub fn get_category(&self, name: &str) -> Option<&CategorySummary>

Look up a category by name.

Source

pub fn category_neighbors( &self, category_name: &str, k: usize, ) -> Vec<&CategorySummary>

Get the k nearest neighbor categories to the given category.

Source

pub fn bridge_items( &self, source_category: &str, target_category: &str, max_bridges: usize, ) -> Vec<&BridgeItem>

Get bridge items between two categories.

Source

pub fn category_path( &self, source_category: &str, target_category: &str, ) -> Option<CategoryPath>

Find the shortest path between two categories through the category graph.

Source

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.

Source

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).

Source

pub fn has_inner_sphere(&self, category_name: &str) -> bool

Whether a given category has an inner sphere.

Source

pub fn get_inner_sphere(&self, category_name: &str) -> Option<&InnerSphere>

Get the inner sphere for a category, if one exists.

Source

pub fn num_inner_spheres(&self) -> usize

Number of categories that have inner spheres.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> CategoryLayer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CategoryLayer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more