MemoryGraphStore<T>
Models & Types · AiDotNet.RetrievalAugmentedGeneration.Graph
In-memory implementation of IGraphStore using dictionaries for fast lookups.
Implements: IGraphStore<T>
For Beginners
This stores your graph in the computer’s memory (RAM).
Pros:
- Very fast (everything in RAM)
- Simple to use (no setup required)
Cons:
- Data lost when app closes
- Limited by available RAM
- Not thread-safe (single-threaded use only)
Good for:
- Development and testing
- Small to medium graphs (<100K nodes)
- Temporary graphs that don’t need persistence
Not good for:
- Production systems requiring persistence
- Very large graphs (>1M nodes)
- Multi-process or multi-threaded access to the same graph
For persistent storage, use FileGraphStore or Neo4jGraphStore instead.
How It Works
This implementation provides high-performance graph storage entirely in RAM. All operations are O(1) or O(degree) complexity. Data is lost when the application stops.
Thread Safety: This class is NOT thread-safe. Callers must ensure proper
synchronization when accessing from multiple threads. For thread-safe operations,
use external locking or consider using FileGraphStore which provides
thread-safe access via ConcurrentDictionary.
Constructors
| Constructor | Summary |
|---|---|
MemoryGraphStore() |
Initializes a new instance of the MemoryGraphStore class. |
Properties
| Property | Summary |
|---|---|
int EdgeCount { get; } |
|
int NodeCount { get; } |
Methods
| Method | Summary |
|---|---|
GraphEdge<T> GetEdge(string edgeId) |
|
GraphNode<T> GetNode(string nodeId) |
|
IEnumerable<GraphEdge<T>> GetAllEdges() |
|
IEnumerable<GraphEdge<T>> GetIncomingEdges(string nodeId) |
|
IEnumerable<GraphEdge<T>> GetOutgoingEdges(string nodeId) |
|
IEnumerable<GraphNode<T>> GetAllNodes() |
|
IEnumerable<GraphNode<T>> GetNodesByLabel(string label) |
|
Task AddEdgeAsync(GraphEdge<T> edge) |
|
Task AddNodeAsync(GraphNode<T> node) |
|
Task ClearAsync() |
|
Task<GraphEdge<T>> GetEdgeAsync(string edgeId) |
|
Task<GraphNode<T>> GetNodeAsync(string nodeId) |
|
Task<IEnumerable<GraphEdge<T>>> GetAllEdgesAsync() |
|
Task<IEnumerable<GraphEdge<T>>> GetIncomingEdgesAsync(string nodeId) |
|
Task<IEnumerable<GraphEdge<T>>> GetOutgoingEdgesAsync(string nodeId) |
|
Task<IEnumerable<GraphNode<T>>> GetAllNodesAsync() |
|
Task<IEnumerable<GraphNode<T>>> GetNodesByLabelAsync(string label) |
|
Task<bool> RemoveEdgeAsync(string edgeId) |
|
Task<bool> RemoveNodeAsync(string nodeId) |
|
bool RemoveEdge(string edgeId) |
|
bool RemoveNode(string nodeId) |
|
void AddEdge(GraphEdge<T> edge) |
|
void AddNode(GraphNode<T> node) |
|
void Clear() |