1use crate::{
2 Edge, EdgeId, EdgeWithVector, Node, NodeId, NodeWithVector, SearchQuery, SearchResult,
3 error::VecGraphError,
4};
5use async_trait::async_trait;
6
7#[async_trait]
8pub trait GraphStore: Send + Sync {
9 async fn insert_node(&self, node: &Node) -> Result<(), VecGraphError>;
10
11 async fn insert_node_with_vector(&self, node: &NodeWithVector) -> Result<(), VecGraphError>;
12
13 async fn insert_nodes_with_vector(
14 &self,
15 nodes: &[NodeWithVector],
16 ) -> Result<(), VecGraphError> {
17 for node in nodes {
18 self.insert_node_with_vector(node).await?;
19 }
20 Ok(())
21 }
22
23 async fn get_node(&self, id: &NodeId) -> Result<Option<Node>, VecGraphError>;
24
25 async fn delete_node(&self, id: &NodeId) -> Result<(), VecGraphError>;
26
27 async fn insert_edge(&self, edge: &Edge) -> Result<(), VecGraphError>;
28
29 async fn insert_edge_with_vector(&self, edge: &EdgeWithVector) -> Result<(), VecGraphError>;
30
31 async fn insert_edges_with_vector(
32 &self,
33 edges: &[EdgeWithVector],
34 ) -> Result<(), VecGraphError> {
35 for edge in edges {
36 self.insert_edge_with_vector(edge).await?;
37 }
38 Ok(())
39 }
40
41 async fn get_edge(&self, id: &EdgeId) -> Result<Option<Edge>, VecGraphError>;
42
43 async fn get_edges_for_node(&self, node_id: &NodeId) -> Result<Vec<Edge>, VecGraphError>;
44
45 async fn get_edges_targeting_node(&self, node_id: &NodeId) -> Result<Vec<Edge>, VecGraphError>;
46
47 async fn delete_edge(&self, id: &EdgeId) -> Result<(), VecGraphError>;
48
49 async fn get_edge_vector(&self, id: &EdgeId) -> Result<Option<Vec<f32>>, VecGraphError>;
50
51 async fn get_node_vector(&self, id: &NodeId) -> Result<Option<Vec<f32>>, VecGraphError>;
52
53 async fn set_name_mapping(
54 &self,
55 kind: &str,
56 name: &str,
57 node_id: &NodeId,
58 ) -> Result<(), VecGraphError>;
59
60 async fn get_name_mapping(
61 &self,
62 kind: &str,
63 name: &str,
64 ) -> Result<Option<NodeId>, VecGraphError>;
65
66 async fn delete_name_mapping(&self, kind: &str, name: &str) -> Result<(), VecGraphError>;
67
68 async fn search(&self, request: &SearchQuery) -> Result<Vec<SearchResult>, VecGraphError>;
69}