Skip to main content

ArchitectureKnowledgeGraph

Struct ArchitectureKnowledgeGraph 

Source
pub struct ArchitectureKnowledgeGraph { /* private fields */ }
Expand description

A graph of architectures and their relationships.

Stores nodes contiguously in insertion order and indexes outgoing edges via an adjacency map for O(deg) neighbour lookups. The map is reconstructed from the edge list whenever the graph is loaded from JSON.

Implementations§

Source§

impl ArchitectureKnowledgeGraph

Source

pub fn new() -> Self

Construct an empty graph.

Source

pub fn with_capacity(n: usize) -> Self

Construct an empty graph pre-allocating storage for n nodes.

Source

pub fn len(&self) -> usize

Number of nodes in the graph.

Source

pub fn is_empty(&self) -> bool

Returns true when the graph has no nodes.

Source

pub fn edge_count(&self) -> usize

Number of edges in the graph.

Source

pub fn add_architecture( &mut self, arch_id: impl Into<String>, embedding: Vec<f64>, domain: impl Into<String>, ) -> NodeId

Insert a new architecture into the graph and return its NodeId.

Source

pub fn set_performance( &mut self, node: NodeId, record: PerformanceRecord, ) -> Result<()>

Attach a performance record to an existing node.

Source

pub fn add_edge( &mut self, from: NodeId, to: NodeId, relation: RelationType, weight: f64, ) -> Result<()>

Add a typed weighted edge between two existing nodes.

Rejects edges that reference unknown nodes, that carry a non-finite weight, or whose weight is outside [-1, 1] for Similar edges.

Source

pub fn node(&self, id: NodeId) -> Option<&ArchKnowledgeNode>

Borrow a node by id (returns None if it does not exist).

Source

pub fn nodes(&self) -> &[ArchKnowledgeNode]

Borrow all nodes in insertion order.

Source

pub fn neighbors(&self, id: NodeId) -> Vec<(NodeId, RelationType, f64)>

Outgoing neighbours of id, returned as (target, relation, weight).

Returns an empty vector for nodes with no outgoing edges or for unknown ids.

Source

pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64

Cosine similarity between two vectors.

Returns 0.0 when either vector is the zero vector, when the lengths differ, or when any element is non-finite. This is safer than returning NaN for downstream ranking code.

Source

pub fn find_similar( &self, query_embedding: &[f64], k: usize, ) -> Vec<(NodeId, f64)>

Top-k nodes by cosine similarity to query_embedding, descending.

Nodes whose embeddings are not comparable (mismatched length or zero-norm) are silently skipped. If k is zero or the graph is empty, returns an empty vector.

Source

pub fn auto_add_similar_edges(&mut self, threshold: f64) -> usize

Add Similar edges between every distinct pair of nodes whose cosine similarity meets threshold. Returns the number of edges added.

Only one directed edge (i -> j) with i < j is added per pair to avoid duplicates and self-loops. Edges are skipped when an identical (from, to, Similar) triple already exists.

Source

pub fn propagate_knowledge( &self, start: NodeId, decay: f64, depth: usize, ) -> Result<HashMap<NodeId, f64>>

Random-walk-with-restart from start.

At each of depth iterations every node redistributes decay × score to its outgoing neighbours (weighted by |weight| and normalised to sum to one). The remaining 1 - decay mass restarts at start. Dangling nodes — those without outgoing edges — return all their mass to start, and groups of neighbours whose weights sum to zero share the mass uniformly.

Source

pub fn extract_top_k_transferable( &self, target_domain: &str, query_embedding: &[f64], k: usize, ) -> Vec<(NodeId, f64)>

Find up to k transferable architectures for target_domain.

A node is considered transferable if its own domain matches target_domain, or if any of its outgoing Transfers edges points to a node whose domain matches, or if it is itself the target of a Transfers edge from a node whose domain matches. Among the transferable nodes, the top-k by cosine similarity to query_embedding are returned (descending).

Source

pub fn to_json(&self) -> Result<String>

Serialise the graph to a pretty-printed JSON string.

Source

pub fn from_json(s: &str) -> Result<Self>

Parse a graph from a JSON string previously produced by to_json.

Trait Implementations§

Source§

impl Clone for ArchitectureKnowledgeGraph

Source§

fn clone(&self) -> Self

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 ArchitectureKnowledgeGraph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ArchitectureKnowledgeGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ArchitectureKnowledgeGraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ArchitectureKnowledgeGraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V