Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkpoint): add support for options.filter in MemorySaver.list #583

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion libs/checkpoint/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class MemorySaver extends BaseCheckpointSaver {
options?: CheckpointListOptions
): AsyncGenerator<CheckpointTuple> {
// eslint-disable-next-line prefer-const
let { before, limit } = options ?? {};
let { before, limit, filter } = options ?? {};
const threadIds = config.configurable?.thread_id
? [config.configurable?.thread_id]
: Object.keys(this.storage);
Expand Down Expand Up @@ -209,6 +209,16 @@ export class MemorySaver extends BaseCheckpointSaver {
metadataStr
)) as CheckpointMetadata;

if (
filter &&
!Object.entries(filter).every(
([key, value]) =>
(metadata as unknown as Record<string, unknown>)[key] === value
)
) {
continue;
}

// Limit search results
if (limit !== undefined) {
if (limit <= 0) break;
Expand Down
Loading