Skip to main content

graphrag_core/persistence/
mod.rs

1//! Persistence layer for GraphRAG knowledge graphs
2//!
3//! This module provides storage backends for persisting knowledge graphs to disk
4//! and loading them back into memory for fast querying.
5//!
6//! ## Supported Formats
7//!
8//! - **Parquet**: Columnar format for entities, relationships, chunks (Apache Arrow ecosystem)
9//! - **LanceDB**: Vector storage for embeddings (Lance columnar format)
10//! - **JSON**: Human-readable backup format (already implemented in core)
11//! - **GraphML**: Export format for visualization tools (already implemented in core)
12//!
13//! ## Architecture
14//!
15//! ```text
16//! workspace/
17//! ├── default/
18//! │   ├── entities.parquet
19//! │   ├── relationships.parquet
20//! │   ├── chunks.parquet
21//! │   ├── documents.parquet
22//! │   ├── vectors.lance/
23//! │   ├── graph.json
24//! │   └── metadata.toml
25//! └── project_a/
26//!     └── ...
27//! ```
28//!
29//! ## Example
30//!
31//! ```no_run
32//! use graphrag_core::{KnowledgeGraph, persistence::WorkspaceManager};
33//!
34//! # fn example() -> graphrag_core::Result<()> {
35//! // Create workspace manager
36//! let workspace = WorkspaceManager::new("./workspace")?;
37//!
38//! // Save graph to default workspace
39//! let graph = KnowledgeGraph::new();
40//! workspace.save_graph(&graph, "default")?;
41//!
42//! // Load graph from workspace
43//! let loaded_graph = workspace.load_graph("default")?;
44//! # Ok(())
45//! # }
46//! ```
47
48use crate::core::Result;
49
50// Submodules
51pub mod workspace;
52
53#[cfg(feature = "persistent-storage")]
54pub mod parquet;
55
56// Lance storage temporarily disabled due to version conflicts
57// TODO: Re-enable when lancedb dependencies are resolved
58// #[cfg(feature = "lance-storage")]
59// pub mod lance;
60
61// Re-exports (workspace always available)
62pub use workspace::{WorkspaceManager, WorkspaceMetadata, WorkspaceInfo};
63
64#[cfg(feature = "persistent-storage")]
65pub use parquet::{ParquetPersistence, ParquetConfig};
66
67// Lance storage temporarily disabled
68// #[cfg(feature = "lance-storage")]
69// pub use lance::{LanceVectorStore, LanceConfig};
70
71/// Persistence trait for knowledge graphs
72pub trait Persistence {
73    /// Save knowledge graph to storage
74    fn save(&self, path: &str) -> Result<()>;
75
76    /// Load knowledge graph from storage
77    fn load(path: &str) -> Result<Self>
78    where
79        Self: Sized;
80
81    /// Check if storage exists
82    fn exists(path: &str) -> bool;
83
84    /// Get storage size in bytes
85    fn size(path: &str) -> Result<u64>;
86}