Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix: feature gating for tool_router macro + clippy + tokenizer download

FABIOTESSeeb8ba729ab3
diff --git a/src/align.rs b/src/align.rs
index 3af8601d..70c03cc9 100644
--- a/src/align.rs
+++ b/src/align.rs
@@ -356,6 +356,7 @@ impl AlignmentEngine {
let relation = Self::classify_relation(label_sim, prop_overlap, parent_ovlp);
+ #[allow(unused_mut)]
let mut signals_json = serde_json::json!({
"label_similarity": (label_sim * 1000.0).round() / 1000.0,
"property_overlap": (prop_overlap * 1000.0).round() / 1000.0,
diff --git a/src/main.rs b/src/main.rs
index 6c4e5b23..ec1333f9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -333,14 +333,19 @@ async fn main() -> anyhow::Result<()> {
&model_path,
).await?;
println!(" Model saved: {}", model_path.display());
+ } else {
+ println!("Embedding model already exists: {}", model_path.display());
+ }
+ if !tokenizer_path.exists() {
+ println!("Downloading tokenizer...");
open_ontologies::embed::download_model_file(
open_ontologies::embed::BGE_SMALL_TOKENIZER_URL,
&tokenizer_path,
).await?;
println!(" Tokenizer saved: {}", tokenizer_path.display());
} else {
- println!("Embedding model already exists: {}", model_path.display());
+ println!("Tokenizer already exists: {}", tokenizer_path.display());
}
}
diff --git a/src/server.rs b/src/server.rs
index cec29f09..4e4b47ca 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -301,7 +301,6 @@ pub struct OntoEnforceFeedbackInput {
pub accepted: bool,
}
-#[cfg(feature = "embeddings")]
#[derive(Deserialize, JsonSchema)]
pub struct OntoEmbedInput {
/// Structural embedding dimension. Default: 32
@@ -310,7 +309,6 @@ pub struct OntoEmbedInput {
pub struct_epochs: Option<usize>,
}
-#[cfg(feature = "embeddings")]
#[derive(Deserialize, JsonSchema)]
pub struct OntoSearchInput {
/// Natural language query
@@ -323,7 +321,6 @@ pub struct OntoSearchInput {
pub alpha: Option<f32>,
}
-#[cfg(feature = "embeddings")]
#[derive(Deserialize, JsonSchema)]
pub struct OntoSimilarityInput {
/// First IRI
@@ -1033,9 +1030,12 @@ impl OpenOntologiesServer {
}).to_string()
}
- #[cfg(feature = "postgres")]
#[tool(name = "onto_import_schema", description = "Import a PostgreSQL database schema as an OWL ontology. Introspects tables, columns, primary keys, and foreign keys, then generates OWL classes, datatype/object properties, and cardinality restrictions.")]
async fn onto_import_schema(&self, Parameters(input): Parameters<OntoImportSchemaInput>) -> String {
+ #[cfg(not(feature = "postgres"))]
+ { let _ = input; return r#"{"error":"Compiled without postgres feature. Rebuild with --features postgres"}"#.to_string(); }
+ #[cfg(feature = "postgres")]
+ {
use crate::schema::SchemaIntrospector;
let base_iri = input.base_iri.as_deref().unwrap_or("http://example.org/db/");
@@ -1061,6 +1061,7 @@ impl OpenOntologiesServer {
}).to_string(),
Err(e) => format!(r#"{{"error":"Failed to load: {}"}}"#, e),
}
+ } // cfg(feature = "postgres")
}
#[tool(name = "onto_align", description = "Detect alignment candidates (owl:equivalentClass, skos:exactMatch, rdfs:subClassOf) between two ontologies using label similarity, property overlap, parent overlap, instance overlap, restriction patterns, and graph neighborhood. Auto-applies high-confidence matches above threshold.")]
@@ -1138,9 +1139,12 @@ impl OpenOntologiesServer {
}
}
- #[cfg(feature = "embeddings")]
#[tool(name = "onto_embed", description = "Generate text + structural Poincaré embeddings for all classes in the loaded ontology. Requires the embedding model (run `open-ontologies init` to download). Embeddings enable semantic search via onto_search and improve alignment accuracy.")]
async fn onto_embed(&self, Parameters(input): Parameters<OntoEmbedInput>) -> String {
+ #[cfg(not(feature = "embeddings"))]
+ { let _ = input; return r#"{"error":"Compiled without embeddings feature. Rebuild with --features embeddings"}"#.to_string(); }
+ #[cfg(feature = "embeddings")]
+ {
let embedder = match &self.text_embedder {
Some(e) => e,
None => return r#"{"error":"Embedding model not loaded. Run `open-ontologies init` to download."}"#.to_string(),
@@ -1219,11 +1223,15 @@ impl OpenOntologiesServer {
"struct_dim": struct_dim,
"errors": errors,
}).to_string()
+ } // cfg(feature = "embeddings")
}
- #[cfg(feature = "embeddings")]
#[tool(name = "onto_search", description = "Semantic search over the loaded ontology using natural language. Returns the most similar classes by text meaning, structural position, or both. Requires onto_embed to have been run first.")]
async fn onto_search(&self, Parameters(input): Parameters<OntoSearchInput>) -> String {
+ #[cfg(not(feature = "embeddings"))]
+ { let _ = input; return r#"{"error":"Compiled without embeddings feature. Rebuild with --features embeddings"}"#.to_string(); }
+ #[cfg(feature = "embeddings")]
+ {
let top_k = input.top_k.unwrap_or(10);
let mode = input.mode.as_deref().unwrap_or("product");
let alpha = input.alpha.unwrap_or(0.5);
@@ -1239,7 +1247,7 @@ impl OpenOntologiesServer {
};
let vecstore = self.vecstore.lock().unwrap();
- if vecstore.len() == 0 {
+ if vecstore.is_empty() {
return r#"{"error":"No embeddings loaded. Run onto_embed first."}"#.to_string();
}
@@ -1284,11 +1292,15 @@ impl OpenOntologiesServer {
"mode": mode,
"count": results.len(),
}).to_string()
+ } // cfg(feature = "embeddings")
}
- #[cfg(feature = "embeddings")]
#[tool(name = "onto_similarity", description = "Compute embedding similarity between two IRIs — returns cosine similarity (text), Poincaré distance (structural), and product score.")]
async fn onto_similarity(&self, Parameters(input): Parameters<OntoSimilarityInput>) -> String {
+ #[cfg(not(feature = "embeddings"))]
+ { let _ = input; return r#"{"error":"Compiled without embeddings feature. Rebuild with --features embeddings"}"#.to_string(); }
+ #[cfg(feature = "embeddings")]
+ {
let vecstore = self.vecstore.lock().unwrap();
let text_a = vecstore.get_text_vec(&input.iri_a);
@@ -1321,6 +1333,7 @@ impl OpenOntologiesServer {
"poincare_distance": (poinc * 1000.0).round() / 1000.0,
"product_score": (product * 1000.0).round() / 1000.0,
}).to_string()
+ } // cfg(feature = "embeddings")
}
}
diff --git a/src/structembed.rs b/src/structembed.rs
index 7bb67400..991790a9 100644
--- a/src/structembed.rs
+++ b/src/structembed.rs
@@ -178,8 +178,7 @@ impl StructuralTrainer {
for root in &roots {
let root_emb = embeddings[root].clone();
// Gradient: point toward origin (i.e., the embedding itself, pulling it back)
- let grad_to_origin: Vec<f32> = root_emb.iter().copied().collect();
- let new_root = rsgd_step(&root_emb, &grad_to_origin, lr * 0.5);
+ let new_root = rsgd_step(&root_emb, &root_emb, lr * 0.5);
embeddings.insert(root.clone(), new_root);
}
}