pub(super) const UNBOUND_MEMORY_PREDICATE: &str =
"NOT EXISTS (SELECT 1 FROM memory_entities me WHERE me.memory_id = m.id)";
pub(super) const NULL_DESCRIPTION_PREDICATE: &str = "(description IS NULL OR description = '')";
pub(super) const LOW_QUALITY_DESCRIPTION_PREDICATE: &str = "(
description LIKE '%is a software component%'
OR description LIKE '%is a software system%'
OR description LIKE '%is a software application%'
OR description LIKE '%in the software project%'
OR description LIKE '%in the context of software%'
OR description LIKE '%of the software system%'
OR description LIKE '%in the software system%'
OR description LIKE '%software/system design%'
OR description LIKE '%configuration file%'
OR description LIKE '%enhances chatbot%'
OR description LIKE '%chatbot response%'
OR description LIKE '%European digital identity%'
)";
const LOW_QUALITY_MARKERS: &[&str] = &[
"is a software component",
"is a software system",
"is a software application",
"in the software project",
"in the context of software",
"of the software system",
"in the software system",
"software/system design",
"configuration file",
"enhances chatbot",
"chatbot response",
"european digital identity",
];
pub(crate) fn is_low_quality_description(desc: &str) -> bool {
let d = desc.trim();
if d.is_empty() {
return true;
}
let lower = d.to_ascii_lowercase();
LOW_QUALITY_MARKERS.iter().any(|m| lower.contains(m))
}
pub(super) const SHORT_BODY_PREDICATE: &str = "LENGTH(COALESCE(m.body,'')) < ?2";
pub(super) const GENERIC_DESCRIPTION_PREDICATE: &str = "(description LIKE '%ingested%' \
OR description LIKE '%imported%' OR description LIKE '%added%' \
OR length(description) < 30)";
pub(super) fn entity_description_scan_predicate(force_redescribe: bool) -> String {
if force_redescribe {
format!("({NULL_DESCRIPTION_PREDICATE} OR {LOW_QUALITY_DESCRIPTION_PREDICATE})")
} else {
NULL_DESCRIPTION_PREDICATE.to_string()
}
}
pub(super) const HIGH_WEIGHT_PREDICATE: &str = "r.weight >= 0.7";
pub(super) const GENERIC_RELATION_PREDICATE: &str = "r.relation = 'applies_to'";
pub(super) fn reembed_memory_predicate(dim: usize) -> String {
format!(
"NOT EXISTS (SELECT 1 FROM memory_embeddings me WHERE me.memory_id = m.id \
AND me.dim = {dim} AND LENGTH(me.embedding) > 0)"
)
}
pub(super) fn reembed_entity_predicate(dim: usize) -> String {
format!(
"NOT EXISTS (SELECT 1 FROM entity_embeddings ev WHERE ev.entity_id = e.id \
AND ev.dim = {dim} AND LENGTH(ev.embedding) > 0)"
)
}
pub(super) fn reembed_chunk_predicate(dim: usize) -> String {
format!(
"NOT EXISTS (SELECT 1 FROM chunk_embeddings ce WHERE ce.chunk_id = c.id \
AND ce.dim = {dim} AND LENGTH(ce.embedding) > 0)"
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn boilerplate_software_component_is_low_quality() {
assert!(is_low_quality_description(
"Foo is a software component in the software project"
));
}
#[test]
fn legitimate_architecture_decision_is_not_low_quality() {
assert!(!is_low_quality_description(
"software architecture decision for auth"
));
}
#[test]
fn software_development_process_is_not_low_quality() {
assert!(!is_low_quality_description(
"Documents the software development process for the billing team"
));
}
#[test]
fn empty_description_is_low_quality() {
assert!(is_low_quality_description(""));
assert!(is_low_quality_description(" "));
}
#[test]
fn chatbot_boilerplate_is_low_quality() {
assert!(is_low_quality_description(
"Module that enhances chatbot response quality"
));
}
#[test]
fn configuration_file_boilerplate_is_low_quality() {
assert!(is_low_quality_description(
"A configuration file used by the build system"
));
}
#[test]
fn specific_domain_prose_is_not_low_quality() {
assert!(!is_low_quality_description(
"OAuth2 token refresh endpoint used by the mobile client"
));
}
#[test]
fn quality_post_filter_rejects_boilerplate_done_candidates() {
let bad = "A software component that provides configuration file support";
assert!(is_low_quality_description(bad));
let good =
"ICMS P05 rule for NFC-e ordered invoice sequences in Brazilian state tax";
assert!(!is_low_quality_description(good));
}
}