use crate::framework::ChaoticSemanticFramework;
use crate::retrieval::{GraphRagConfig, GraphRagResult, graph_rag_retrieve};
use csm_core_lib::error::Result;
use csm_core_lib::hyperdim::HVec10240;
use tracing::instrument;
impl ChaoticSemanticFramework {
#[instrument(err, skip(self, query, config))]
pub async fn probe_with_graph(
&self,
query: HVec10240,
config: GraphRagConfig,
) -> Result<Vec<GraphRagResult>> {
if config.anchor_top_k > 0 {
self.validate_top_k(config.anchor_top_k)?;
}
if config.final_top_k > 0 {
self.validate_top_k(config.final_top_k)?;
}
let (concepts, associations) = {
let sing = self.singularity.read().await;
let ns = self.namespace.read().await;
(sing.all_concepts(&ns), sing.all_associations(&ns))
};
graph_rag_retrieve(&query, &concepts, &associations, &config)
}
#[instrument(err, skip(self, text, config))]
pub async fn probe_text_with_graph(
&self,
text: &str,
config: GraphRagConfig,
) -> Result<Vec<GraphRagResult>> {
let embedding = self.embedding_provider.embed(text).await?;
let query = self
.embedding_provider
.project(&embedding, &self.projection);
self.probe_with_graph(query, config).await
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use super::*;
#[tokio::test]
async fn probe_with_graph_returns_relevant_results() {
let fw = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
let vector = HVec10240::random();
fw.inject_concept("graph".to_string(), vector)
.await
.unwrap();
let config = GraphRagConfig {
anchor_top_k: 5,
max_hops: 2,
min_assoc_strength: 0.1,
similarity_weight: 0.7,
graph_weight: 0.3,
final_top_k: 5,
};
let results = fw.probe_with_graph(vector, config).await.unwrap();
assert!(
!results.is_empty(),
"probe_with_graph must return at least one result"
);
}
}