feat(dynamodb): per-document TTL support and automatic provisioning (#22) - #263
Merged
codeforstartups merged 2 commits intoSep 28, 2026
Conversation
codeforstartups
approved these changes
Sep 28, 2026
codeforstartups
left a comment
Owner
There was a problem hiding this comment.
Great feature — per-document TTL via DynamoDB's native Time-To-Live. ttl_seconds on Document / upsert() (and a batch default), computes the Unix epoch, stores it in the ttl attribute, and enables TTL on the table during provisioning. Perfect for session memory / ephemeral cache entries. IAM policy + README updated. Verified: ruff clean, 10 tests pass, CI green incl. typecheck. Merging — thanks @shivamm-gupta! 🙌
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22
Context & Motivation
Ephemeral vector documents (session context, temporary cache entries, expiring credentials, or transient user uploads) often require automated lifecycle management. Storing them indefinitely in DynamoDB increases storage costs and necessitates costly custom scan-and-delete cleanup jobs.
This PR adds native Time to Live (TTL) support for documents in
dynavec:ttl_secondsper document (onDocumentor dict) or as a batch default ondb.upsert(...)andns.upsert(...).int(time.time() + ttl_seconds)) and persists it into DynamoDB'sttlattribute.ensure_table,ensure_ttl, andprovision_all).ttlinSearchResult.ttl/.to_dict()and preserves existing TTL across updates when not overridden.Changes
src/dynavec/config.py: Addeddynamodb_enable_ttl: bool = Trueanddynamodb_ttl_attribute: str = "ttl"toDynavecConfig.src/dynavec/models.py:ttl_seconds: int | None = NonetoDocumentdataclass with positive-value validation.ttl: int | None = NonetoSearchResultdataclass and.to_dict().src/dynavec/stores/dynamodb.py:TTL_ATTR = "ttl"._build_itemandcheck_item_sizeto handlettl.put_manyandput_versionedto accept and writettlattributes.get_manyandget_versionedto hydratettl.src/dynavec/client.py:ttl_secondsparameter toupsert()andupdate()._prepareto compute epoch timestamps fromttl_seconds.ttlintoSearchResulton search andget().src/dynavec/namespace.py: Addedttl_secondstoNamespaceView.upsertandNamespaceView.update.src/dynavec/provisioning.py: Addedensure_ttland updatedensure_tableto enable TTL idempotently.docs/iam-policy.json&README.md: Addeddynamodb:DescribeTimeToLiveanddynamodb:UpdateTimeToLiveto IAM permissions and added documentation section for TTL usage.tests/test_dynamodb_ttl.py: Added 10 offline unit tests covering validation, upsert/update TTL computations, overrides, preservation, hydration, and table provisioning with moto.Testing
pytest tests/test_dynamodb_ttl.py- 10 passedpytestfull test suite - all 620+ passedruff check- clean