Skip to main content

grpc_verify/
grpc_verify.rs

1use synapse_core::server::proto::semantic_engine_client::SemanticEngineClient;
2use synapse_core::server::proto::{
3    HybridSearchRequest, IngestRequest, Provenance, ReasoningRequest, ReasoningStrategy,
4    SearchMode, Triple,
5};
6
7#[tokio::main]
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Connecting to Synapse gRPC server...");
10    let mut client = SemanticEngineClient::connect("http://[::1]:50051").await?;
11
12    println!("✅ Connected!");
13
14    // 1. Ingest Data
15    let triple = Triple {
16        subject: "http://example.org/Socrates".to_string(),
17        predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type".to_string(),
18        object: "http://example.org/Human".to_string(),
19        provenance: Some(Provenance {
20            source: "client_test".to_string(),
21            timestamp: "now".to_string(),
22            method: "grpc".to_string(),
23        }),
24        embedding: vec![],
25    };
26
27    let triple2 = Triple {
28        subject: "http://example.org/Human".to_string(),
29        predicate: "http://www.w3.org/2000/01/rdf-schema#subClassOf".to_string(),
30        object: "http://example.org/Mortal".to_string(),
31        provenance: Some(Provenance {
32            source: "client_test".to_string(),
33            timestamp: "now".to_string(),
34            method: "grpc".to_string(),
35        }),
36        embedding: vec![],
37    };
38
39    println!("Sending IngestRequest...");
40    let response = client
41        .ingest_triples(IngestRequest {
42            triples: vec![triple, triple2],
43            namespace: "test_verification".to_string(),
44        })
45        .await?;
46    println!("Response: {:?}", response.into_inner());
47
48    // 2. Apply Reasoning (RDFS Transitivity)
49    println!("\nApplying RDFS Reasoning (Internal)...");
50    let reasoning_response = client
51        .apply_reasoning(ReasoningRequest {
52            namespace: "test_verification".to_string(),
53            strategy: ReasoningStrategy::Rdfs as i32,
54            materialize: false,
55        })
56        .await?;
57    println!("Reasoning Result: {:?}", reasoning_response.into_inner());
58
59    // 3. Hybrid Search
60    println!("\nPerforming Hybrid Search for 'Socrates'...");
61    let search_response = client
62        .hybrid_search(HybridSearchRequest {
63            query: "Socrates".to_string(),
64            namespace: "test_verification".to_string(),
65            vector_k: 5,
66            graph_depth: 1,
67            mode: SearchMode::Hybrid as i32,
68            limit: 10,
69        })
70        .await?;
71
72    println!("Search Results:");
73    for result in search_response.into_inner().results {
74        println!(
75            " - [Score: {:.4}] {} ({})",
76            result.score, result.content, result.uri
77        );
78    }
79
80    Ok(())
81}