Skip to content

Commit

Permalink
fix(checkpoint): add support for options.filter in MemorySaver.list
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Oct 11, 2024
1 parent 45e59e6 commit bd83402
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,15 @@ 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

0 comments on commit bd83402

Please sign in to comment.