IGraphStore<T>
Interfaces · AiDotNet.Interfaces
Defines the contract for graph storage backends that manage nodes and edges.
Known implementations: FileGraphStore<T>, MemoryGraphStore<T>
For Beginners
A graph store is like a filing system for connected information.
Think of it like organizing a network of friends:
- Nodes are people (Alice, Bob, Charlie)
- Edges are relationships (Alice KNOWS Bob, Bob WORKS_WITH Charlie)
- The graph store remembers all these connections
Different implementations might:
- MemoryGraphStore: Keep everything in RAM (fast but lost when app closes)
- FileGraphStore: Save to disk (slower but survives restarts)
- Neo4jGraphStore: Use a professional graph database (production-scale)
This interface lets you swap storage backends without changing your code!
How It Works
A graph store provides persistent or in-memory storage for knowledge graphs, enabling efficient storage and retrieval of entities (nodes) and their relationships (edges). Implementations can range from simple in-memory dictionaries to distributed graph databases.
Properties
| Property | Summary |
|---|---|
int EdgeCount { get; } |
Gets the total number of edges in the graph store. |
int NodeCount { get; } |
Gets the total number of nodes in the graph store. |
Methods
| Method | Summary |
|---|---|
GraphEdge<T> GetEdge(string edgeId) |
Retrieves an edge by its unique identifier. |
GraphNode<T> GetNode(string nodeId) |
Retrieves a node by its unique identifier. |
IEnumerable<GraphEdge<T>> GetAllEdges() |
Gets all edges currently stored in the graph. |
IEnumerable<GraphEdge<T>> GetIncomingEdges(string nodeId) |
Gets all incoming edges to a specific node. |
IEnumerable<GraphEdge<T>> GetOutgoingEdges(string nodeId) |
Gets all outgoing edges from a specific node. |
IEnumerable<GraphNode<T>> GetAllNodes() |
Gets all nodes currently stored in the graph. |
IEnumerable<GraphNode<T>> GetNodesByLabel(string label) |
Gets all nodes with a specific label. |
Task AddEdgeAsync(GraphEdge<T> edge) |
Asynchronously adds an edge to the graph. |
Task AddNodeAsync(GraphNode<T> node) |
Asynchronously adds a node to the graph or updates it if it already exists. |
Task ClearAsync() |
Asynchronously removes all nodes and edges from the graph. |
Task<GraphEdge<T>> GetEdgeAsync(string edgeId) |
Asynchronously retrieves an edge by its unique identifier. |
Task<GraphNode<T>> GetNodeAsync(string nodeId) |
Asynchronously retrieves a node by its unique identifier. |
Task<IEnumerable<GraphEdge<T>>> GetAllEdgesAsync() |
Asynchronously gets all edges currently stored in the graph. |
Task<IEnumerable<GraphEdge<T>>> GetIncomingEdgesAsync(string nodeId) |
Asynchronously gets all incoming edges to a specific node. |
Task<IEnumerable<GraphEdge<T>>> GetOutgoingEdgesAsync(string nodeId) |
Asynchronously gets all outgoing edges from a specific node. |
Task<IEnumerable<GraphNode<T>>> GetAllNodesAsync() |
Asynchronously gets all nodes currently stored in the graph. |
Task<IEnumerable<GraphNode<T>>> GetNodesByLabelAsync(string label) |
Asynchronously gets all nodes with a specific label. |
Task<bool> RemoveEdgeAsync(string edgeId) |
Asynchronously removes an edge from the graph. |
Task<bool> RemoveNodeAsync(string nodeId) |
Asynchronously removes a node and all its connected edges from the graph. |
bool RemoveEdge(string edgeId) |
Removes an edge from the graph. |
bool RemoveNode(string nodeId) |
Removes a node and all its connected edges from the graph. |
void AddEdge(GraphEdge<T> edge) |
Adds an edge to the graph representing a relationship between two nodes. |
void AddNode(GraphNode<T> node) |
Adds a node to the graph or updates it if it already exists. |
void Clear() |
Removes all nodes and edges from the graph. |