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