@@ -64,68 +64,70 @@ let is_valid = tree.verify(proof, b"user:alice", Some(b"Alice Johnson"));
6464
6565``` rust
6666use prollytree :: git :: GitVersionedKvStore ;
67- use prollytree :: diff :: IgnoreConflictsResolver ;
68-
69- let mut store = GitVersionedKvStore :: <32 >:: init (" ./data" )? ;
70-
71- // Version your data like Git
67+ use std :: process :: Command ;
68+ use std :: fs;
69+
70+ // Setup: Create a temporary Git repository (in real use, you'd have an existing repo)
71+ let repo_path = " /tmp/demo_git_repo" ;
72+ fs :: remove_dir_all (repo_path ). ok (); // Clean up
73+ fs :: create_dir_all (repo_path )? ;
74+
75+ // Initialize Git repository
76+ Command :: new (" git" ). args (& [" init" ]). current_dir (repo_path ). output ()? ;
77+ Command :: new (" git" ). args (& [" config" , " user.name" , " Demo" ]). current_dir (repo_path ). output ()? ;
78+ Command :: new (" git" ). args (& [" config" , " user.email" , " demo@example.com" ]). current_dir (repo_path ). output ()? ;
79+
80+ // Initial git commit
81+ fs :: write (format! (" {}/README.md" , repo_path ), " # Demo" )? ;
82+ Command :: new (" git" ). args (& [" add" , " ." ]). current_dir (repo_path ). output ()? ;
83+ Command :: new (" git" ). args (& [" commit" , " -m" , " Initial" ]). current_dir (repo_path ). output ()? ;
84+
85+ // Switch to repo directory and create dataset
86+ std :: env :: set_current_dir (repo_path )? ;
87+ fs :: create_dir_all (" data" )? ;
88+ let mut store = GitVersionedKvStore :: <32 >:: init (" data" )? ;
89+
90+ // Now use Git-backed versioned storage
7291store . insert (b " config/api_key" . to_vec (), b " secret123" . to_vec ())? ;
7392store . commit (" Initial config" )? ;
7493
75- // Create and switch to a new branch for experiments
76- store . create_branch (" feature/optimization" )? ;
77- // Use regular git to switch branches: git checkout feature/optimization
78- store . insert (b " config/timeout" . to_vec (), b " 60" . to_vec ())? ;
79- store . commit (" Increase timeout" )? ;
94+ // Retrieve data
95+ if let Some (value ) = store . get (b " config/api_key" ) {
96+ println! (" Retrieved: {}" , String :: from_utf8 (value )? );
97+ }
8098
81- // Switch back to main and merge
82- // Use regular git to switch: git checkout main
83- store . merge (" feature/optimization" , & IgnoreConflictsResolver )? ;
99+ // Add more data and commit
100+ store . insert (b " config/timeout" . to_vec (), b " 30" . to_vec ())? ;
101+ store . commit (" Add timeout config" )? ;
102+
103+ // Create branches for parallel development
104+ store . create_branch (" experimental" )? ;
105+ println! (" Git-backed storage with full version control!" );
84106```
85107
86- ### SQL Interface with ProllyTree
108+ ### Multiple Storage Backends
87109
88110``` rust
89- use prollytree :: sql :: ProllyStorage ;
90- use gluesql_core :: prelude :: Glue ;
91-
92- // Create ProllyTree storage backend
93- let storage = ProllyStorage :: <32 >:: new (" ./data" )? ;
94- let mut glue = Glue :: new (storage );
111+ use prollytree :: tree :: {ProllyTree , Tree };
112+ use prollytree :: storage :: {InMemoryNodeStorage , FileNodeStorage };
95113
96- // Execute SQL operations
97- glue . execute (" CREATE TABLE users (id INTEGER, name TEXT)" ). await ? ;
98- glue . execute (" INSERT INTO users VALUES (1, 'Alice Johnson')" ). await ? ;
114+ // In-memory storage (fast, temporary)
115+ let mem_storage = InMemoryNodeStorage :: <32 >:: new ();
116+ let mut mem_tree = ProllyTree :: new (mem_storage , Default :: default ());
117+ mem_tree . insert (b " session:abc123" . to_vec (), b " active" . to_vec ());
99118
100- // Query the data
101- let result = glue . execute ( " SELECT * FROM users WHERE id = 1 " ) . await ? ;
102- println! ( " Query result: {:?} " , result );
103- ```
119+ // File-based storage (persistent)
120+ let file_storage = FileNodeStorage :: < 32 > :: new ( " ./tree_data " . into ()) ;
121+ let mut file_tree = ProllyTree :: new ( file_storage , Default :: default () );
122+ file_tree . insert ( b " user:alice " . to_vec (), b " Alice Johnson " . to_vec ());
104123
105- ### AI Agent Memory
124+ // Both trees support the same operations
125+ if let Some (node ) = mem_tree . find (b " session:abc123" ) {
126+ println! (" Session found in memory storage" );
127+ }
106128
107- ``` rust
108- use prollytree :: agent :: {AgentMemorySystem , MemoryQuery };
109-
110- let mut memory = AgentMemorySystem :: init_with_thread_safe_git (
111- " ./agent_memory" , " agent_001" . to_string (), None
112- )? ;
113-
114- // Store conversation context
115- memory . short_term. store_conversation_turn (
116- " session_123" , " user" , " What's the weather today?" , None
117- ). await ? ;
118-
119- // Store persistent knowledge
120- memory . semantic. store_fact (
121- " weather" , " temperature" ,
122- json! ({" location" : " Tokyo" , " temp" : " 22°C" }),
123- 0.9 , " weather_api"
124- ). await ? ;
125-
126- // Query and checkpoint
127- let memories = memory . semantic. query (MemoryQuery :: text (" Tokyo" )). await ? ;
128- let checkpoint = memory . checkpoint (" Weather conversation" ). await ? ;
129+ // For SQL functionality, see examples/sql.rs
130+ println! (" Multiple storage backends working!" );
129131```
130132
131133## Feature Flags
@@ -165,9 +167,9 @@ Run benchmarks: `cargo bench`
165167# Install git-prolly CLI
166168cargo install prollytree --features git
167169
168- # First setup a git repository and then create a dataset
170+ # Setup git repository and create dataset
169171git init my-repo && cd my-repo
170- git-prolly init my-data # Creates subdirectory for dataset
172+ mkdir my-data && git-prolly init my-data # Create dataset directory
171173cd my-data
172174git-prolly set " user:alice" " Alice Johnson"
173175git-prolly commit -m " Add user"
0 commit comments