FileGraphStore<T>
Models & Types Β· AiDotNet.RetrievalAugmentedGeneration.Graph
File-based implementation of IGraphStore with persistent storage on disk.
Implements: IDisposable, IGraphStore<T>
For Beginners
This stores your graph on disk so it survives restarts.
How it works:
- When you add a node, itβs written to nodes.dat
- The position (offset) is recorded in node_index.db
- To retrieve a node, we look up its offset and read from that position
- Everything is saved to disk automatically
Pros:
- πΎ Data persists across restarts
- π Can handle graphs larger than RAM
- π Simple file-based storage (no database required)
Cons:
- π Slower than in-memory (disk I/O overhead)
- π Not suitable for concurrent access from multiple processes
- π¦ No compression (files can be large)
Good for:
- Applications that need to save graph state
- Graphs up to a few million nodes
- Single-process applications
Not good for:
- Real-time systems requiring sub-millisecond latency
- Multi-process concurrent access
- Distributed systems (use Neo4j or similar instead)
How It Works
This implementation provides persistent graph storage using files:
- nodes.dat: Binary file containing serialized nodes
- edges.dat: Binary file containing serialized edges
- node_index.db: B-Tree index mapping node IDs to file offsets
- edge_index.db: B-Tree index mapping edge IDs to file offsets
Constructors
| Constructor | Summary |
|---|---|
FileGraphStore(string storageDirectory, WriteAheadLog wal) |
Initializes a new instance of the FileGraphStore 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() |
|
void Dispose() |
Disposes the file graph store, ensuring all changes are flushed to disk. |