-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation and deletion of config files
- Loading branch information
1 parent
cd204ee
commit f18cfaa
Showing
4 changed files
with
109 additions
and
13,993 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# @langchain/langgraph-checkpoint-firebase | ||
|
||
Implementation of a [LangGraph.js](https://github.com/langchain-ai/langgraphjs) CheckpointSaver that uses a FireBase instance. | ||
|
||
The `FirebaseSaver` class is an implementation of the `BaseCheckpointSaver` interface that uses Firebase Realtime Database for persistence. It is part of the `@langchain/langgraph-checkpoint` library and provides scalable, real-time management of checkpoints in LangGraph.js. | ||
|
||
--- | ||
|
||
## Features | ||
|
||
- **Firebase Persistence**: Leverages Firebase's real-time capabilities to store checkpoints and metadata. | ||
- **Thread Management**: Isolates states using thread-based checkpointing for multi-tenant or parallel use cases. | ||
- **Pending Writes**: Handles intermediate writes for partially executed graph nodes. | ||
- **Real-Time Updates**: Takes advantage of Firebase's dynamic data updates for live applications. | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
### Prerequisites | ||
- Firebase Realtime Database instance | ||
- Node.js with TypeScript | ||
|
||
### Install Dependencies | ||
```bash | ||
npm install @langchain/langgraph-checkpoint firebase | ||
|
||
### Usage | ||
|
||
```ts | ||
import { initializeApp } from "firebase/app"; | ||
import { getDatabase } from "firebase/database"; | ||
import { FirebaseSaver } from "@langchain/langgraph-checkpoint-firebase"; | ||
const writeConfig = { | ||
configurable: { | ||
thread_id: "1", | ||
checkpoint_ns: "" | ||
} | ||
}; | ||
const readConfig = { | ||
configurable: { | ||
thread_id: "1" | ||
} | ||
}; | ||
const writeConfig = { | ||
configurable: { | ||
thread_id: "1", | ||
checkpoint_ns: "" | ||
} | ||
}; | ||
const readConfig = { | ||
configurable: { | ||
thread_id: "1" | ||
} | ||
}; | ||
const firebaseConfig = { | ||
apiKey: "REPLACE-WITH-YOUR-API-KEY", | ||
authDomain: "REPLACE-WITH-YOUR-localhost", | ||
projectId: "REPLACE-WITH-YOUR-TEST-PROJECT", | ||
databaseURL: process.env.FIREBASEURL || "http://localhost:9000", // Use emulator URL | ||
}; | ||
process.env.FIREBASE_URL = process.env.FIREBASEURL || "http://localhost:9000" | ||
const app = initializeApp(firebaseConfig); | ||
database = getDatabase(app); | ||
const checkpoint = { | ||
v: 1, | ||
ts: "2024-07-31T20:14:19.804150+00:00", | ||
id: "1ef4f797-8335-6428-8001-8a1503f9b875", | ||
channel_values: { | ||
my_key: "meow", | ||
node: "node" | ||
}, | ||
channel_versions: { | ||
__start__: 2, | ||
my_key: 3, | ||
start:node: 3, | ||
node: 3 | ||
}, | ||
versions_seen: { | ||
__input__: {}, | ||
__start__: { | ||
__start__: 1 | ||
}, | ||
node: { | ||
start:node: 2 | ||
} | ||
}, | ||
pending_sends: [], | ||
} | ||
// store checkpoint | ||
await checkpointer.put(writeConfig, checkpoint, {}, {}); | ||
// load checkpoint | ||
await checkpointer.get(readConfig); | ||
// list checkpoints | ||
for await (const checkpoint of checkpointer.list(readConfig)) { | ||
console.log(checkpoint); | ||
} | ||
await client.close(); | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.