| Crates.io | lnmp-sfe |
| lib.rs | lnmp-sfe |
| version | 0.5.16 |
| created_at | 2025-11-19 11:11:45.411173+00 |
| updated_at | 2025-12-19 10:04:49.196868+00 |
| description | Semantic Fidelity Engine for LNMP - semantic dictionary, equivalence mapping, and context profiling |
| homepage | |
| repository | https://github.com/lnmplang/lnmp-protocol |
| max_upload_size | |
| id | 1939908 |
| size | 86,144 |
Semantic Fidelity Engine for LNMP (LLM Native Minimal Protocol).
FID Registry: All examples use official Field IDs from
registry/fids.yaml.
This crate provides the semantic dictionary system that maps field IDs to human-readable names and provides equivalence mappings for semantic normalization.
use lnmp_sfe::SemanticDictionary;
// Load dictionary from YAML file
let dict = SemanticDictionary::load_from_file("dictionary.yaml")?;
// Get field name
if let Some(name) = dict.get_field_name(12) {
println!("Field 12 is: {}", name);
}
// Get equivalence mapping
if let Some(canonical) = dict.get_equivalence(7, "yes") {
println!("'yes' maps to: {}", canonical);
}
fields:
12:
name: user_id
type: integer
7:
name: is_active
type: boolean
equivalences:
yes: "1"
true: "1"
no: "0"
false: "0"
23:
name: roles
type: string_array
equivalences:
admin: administrator
dev: developer
The Semantic Fidelity Engine includes context profiling capabilities to help LLMs prioritize which records to use in RAG (Retrieval-Augmented Generation) systems and other applications.
use lnmp_sfe::{ContextScorer, ContextPrioritizer, ScoringWeights};
use lnmp_envelope::EnvelopeBuilder;
// Create scorer
let scorer = ContextScorer::new();
// Score an envelope
let now = current_timestamp_ms();
let profile = scorer.score_envelope(&envelope, now);
println!("Freshness: {:.2}", profile.freshness_score);
println!("Importance: {}", profile.importance);
println!("Risk: {:?}", profile.risk_level);
println!("Confidence: {:.2}", profile.confidence);
// Select top-K contexts for LLM prompt
let weights = ScoringWeights::new(0.8, 0.1, 0.1); // 80% freshness
let top_5 = ContextPrioritizer::select_top_k(contexts, 5, weights);
// Filter by criteria
let high_quality = ContextPrioritizer::filter_by_threshold(contexts, 0.6);
let very_fresh = ContextPrioritizer::filter_by_freshness(contexts, 0.9);
// Rank all contexts
let ranked = ContextPrioritizer::rank_for_llm(contexts, weights);
Add importance levels to YAML:
fields:
12:
name: user_id
type: integer
importance: 200 # High importance (0-255)
context_scoring.rs - Basic context scoringrag_prioritization.rs - RAG system prioritizationcargo run --example context_scoring
cargo run --example rag_prioritization
Licensed under either of Apache License, Version 2.0 or MIT license at your option.