vectorizer_sdk/models/
graph.rs

1//! Graph models for the Vectorizer SDK
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Graph node representing a document/file
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct GraphNode {
10    /// Unique node identifier
11    pub id: String,
12    /// Node type (e.g., "document", "file", "chunk")
13    pub node_type: String,
14    /// Node metadata
15    pub metadata: HashMap<String, serde_json::Value>,
16}
17
18/// Graph edge representing a relationship between nodes
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct GraphEdge {
21    /// Edge identifier
22    pub id: String,
23    /// Source node ID
24    pub source: String,
25    /// Target node ID
26    pub target: String,
27    /// Relationship type
28    pub relationship_type: String,
29    /// Edge weight (0.0 to 1.0)
30    pub weight: f32,
31    /// Edge metadata
32    pub metadata: HashMap<String, serde_json::Value>,
33    /// Creation timestamp
34    pub created_at: String,
35}
36
37/// Relationship type between nodes
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
40pub enum RelationshipType {
41    /// Documents are semantically similar
42    SimilarTo,
43    /// Document references another document
44    References,
45    /// Document contains another document
46    Contains,
47    /// Document is derived from another document
48    DerivedFrom,
49}
50
51/// Neighbor information
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct NeighborInfo {
54    /// Neighbor node
55    pub node: GraphNode,
56    /// Edge connecting to neighbor
57    pub edge: GraphEdge,
58}
59
60/// Related node information
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct RelatedNodeInfo {
63    /// Related node
64    pub node: GraphNode,
65    /// Distance in hops
66    pub distance: usize,
67    /// Relationship weight
68    pub weight: f32,
69}
70
71/// Request to find related nodes
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct FindRelatedRequest {
74    /// Maximum number of hops
75    pub max_hops: Option<usize>,
76    /// Relationship type filter
77    pub relationship_type: Option<String>,
78}
79
80/// Response for finding related nodes
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct FindRelatedResponse {
83    /// List of related nodes
84    pub related: Vec<RelatedNodeInfo>,
85}
86
87/// Request to find path between nodes
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct FindPathRequest {
90    /// Collection name
91    pub collection: String,
92    /// Source node ID
93    pub source: String,
94    /// Target node ID
95    pub target: String,
96}
97
98/// Response for finding path
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct FindPathResponse {
101    /// Path as list of nodes
102    pub path: Vec<GraphNode>,
103    /// Whether path was found
104    pub found: bool,
105}
106
107/// Request to create an edge
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct CreateEdgeRequest {
110    /// Collection name
111    pub collection: String,
112    /// Source node ID
113    pub source: String,
114    /// Target node ID
115    pub target: String,
116    /// Relationship type
117    pub relationship_type: String,
118    /// Optional edge weight
119    pub weight: Option<f32>,
120}
121
122/// Response for creating an edge
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct CreateEdgeResponse {
125    /// Created edge ID
126    pub edge_id: String,
127    /// Success status
128    pub success: bool,
129    /// Status message
130    pub message: String,
131}
132
133/// Response for listing nodes
134#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct ListNodesResponse {
136    /// List of nodes
137    pub nodes: Vec<GraphNode>,
138    /// Total count
139    pub count: usize,
140}
141
142/// Response for getting neighbors
143#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct GetNeighborsResponse {
145    /// List of neighbors
146    pub neighbors: Vec<NeighborInfo>,
147}
148
149/// Response for listing edges
150#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct ListEdgesResponse {
152    /// List of edges
153    pub edges: Vec<GraphEdge>,
154    /// Total count
155    pub count: usize,
156}
157
158/// Request to discover edges
159#[derive(Debug, Clone, Serialize, Deserialize)]
160pub struct DiscoverEdgesRequest {
161    /// Similarity threshold (0.0 to 1.0)
162    pub similarity_threshold: Option<f32>,
163    /// Maximum edges per node
164    pub max_per_node: Option<usize>,
165}
166
167/// Response for discovering edges
168#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct DiscoverEdgesResponse {
170    /// Success status
171    pub success: bool,
172    /// Number of edges created
173    pub edges_created: usize,
174    /// Status message
175    pub message: String,
176}
177
178/// Response for discovery status
179#[derive(Debug, Clone, Serialize, Deserialize)]
180pub struct DiscoveryStatusResponse {
181    /// Total number of nodes
182    pub total_nodes: usize,
183    /// Number of nodes with edges
184    pub nodes_with_edges: usize,
185    /// Total number of edges
186    pub total_edges: usize,
187    /// Progress percentage
188    pub progress_percentage: f64,
189}