langgraph/libs/checkpoint/tests
Elior Nataf Lackritz cd95887ec5
perf(checkpoint): stop InMemoryStore search at the requested page (#9633)
`InMemoryStore.search` built an `(item, vectors)` pair for every item in
every matching namespace, then kept `candidates[offset:offset + limit]`.
A `limit=10` search on a 10,000-item namespace took 1.9 ms, nearly all
of it building candidates the slice then dropped. Paging a namespace 100
items at a time, as deepagents' `StoreBackend` does for `ls`, `glob` and
`grep`, rebuilt the whole listing for every page.

Without a filter, and without a query the store can embed, the result is
exactly that slice, so `_filter_items` now stops once it has `offset +
limit` matches. The namespace prefix test also becomes one tuple
compare: a namespace shorter than the prefix slices to itself, so it can
never equal the prefix.

Median of four alternating rounds on main and on this branch, Python
3.14:

| workload | main | this PR | speedup |
|---|---|---|---|
| `search(ns, limit=10)` on a 1,000-item namespace | 70 µs | 4 µs | 17x
|
| same, 10,000 items | 1.92 ms | 4 µs | about 490x |
| graph node that searches 1,000 memories (`limit=5`) and adds one, 20
steps | 3.41 ms | 1.86 ms | 1.83x |
| same, 10,000 memories | 39.4 ms | 1.83 ms | 21.5x |
| paging 5,000 items 100 at a time | 47.1 ms | 30.1 ms | 1.57x |
| `search` over 10,000 one-item namespaces | 23.4 ms | 15.5 ms | 1.51x |
| `search` with a filter, `get`, `put` | | | about 1x |

A filter keeps the full scan, so a filter that raises on some item (a
range operator on a missing key) still raises the same way. Negative
`offset` or `limit` keep it too, since a slice counts those from the
end.

## Test plan
- [x] `test_search_pages_match_full_listing` pages plain and filtered
searches across nested and look-alike namespaces and compares each page
with the full listing. It passes on main too, since the results are
unchanged.
2026-11-13 00:08:22 +00:00
..
__init__.py langgraph checkpoint: new library for checkpoint interfaces (#1163) 2024-07-31 16:45:52 -04:00
embed_test_utils.py Add in-mem vector search (#2547) 2024-11-27 14:53:24 -08:00
test_encrypted.py chore: enforce PLC0415 in tests for the remaining packages (#8547) 2026-08-07 09:40:18 -04:00
test_jsonplus.py fix(checkpoint): keep serialized data when an object can't be rebuilt (#9251) 2026-10-08 16:01:46 -04:00
test_memory.py fix(checkpoint): default InMemorySaver delta history to the latest checkpoint (#9257) 2026-10-10 00:59:20 +00:00
test_redis_cache.py fix(checkpoint): preserve non-ascii text in InMemoryStore embeddings (#6111) 2025-09-09 17:52:11 +00:00
test_store.py perf(checkpoint): stop InMemoryStore search at the requested page (#9633) 2026-11-13 00:08:22 +00:00