From 6c0def79d80f45147781354e06a8e9364756d294 Mon Sep 17 00:00:00 2001 From: Preston Rasmussen <109292228+prasmussen15@users.noreply.github.com> Date: Tue, 8 Apr 2025 17:59:40 -0400 Subject: [PATCH] Use UUID as cursor (#335) * update pagination * update pagination * Update graphiti_core/edges.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * uuid_cursor --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- graphiti_core/edges.py | 24 ++++++++++++------------ graphiti_core/nodes.py | 24 ++++++++++++------------ pyproject.toml | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/graphiti_core/edges.py b/graphiti_core/edges.py index d1df1ad3..7e7c1868 100644 --- a/graphiti_core/edges.py +++ b/graphiti_core/edges.py @@ -143,9 +143,9 @@ class EpisodicEdge(Edge): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND e.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND e.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -161,11 +161,11 @@ class EpisodicEdge(Edge): n.uuid AS source_node_uuid, m.uuid AS target_node_uuid, e.created_at AS created_at - ORDER BY e.created_at, e.uuid DESC + ORDER BY e.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', @@ -297,9 +297,9 @@ class EntityEdge(Edge): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND e.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND e.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -322,11 +322,11 @@ class EntityEdge(Edge): e.expired_at AS expired_at, e.valid_at AS valid_at, e.invalid_at AS invalid_at - ORDER BY e.created_at, e.uuid DESC + ORDER BY e.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', @@ -430,9 +430,9 @@ class CommunityEdge(Edge): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND e.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND e.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -448,11 +448,11 @@ class CommunityEdge(Edge): n.uuid AS source_node_uuid, m.uuid AS target_node_uuid, e.created_at AS created_at - ORDER BY e.created_at, e.uuid DESC + ORDER BY e.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', diff --git a/graphiti_core/nodes.py b/graphiti_core/nodes.py index 807c2271..f4f50a0c 100644 --- a/graphiti_core/nodes.py +++ b/graphiti_core/nodes.py @@ -216,9 +216,9 @@ class EpisodicNode(Node): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND e.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND e.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -237,11 +237,11 @@ class EpisodicNode(Node): e.source_description AS source_description, e.source AS source, e.entity_edges AS entity_edges - ORDER BY e.created_at, e.uuid DESC + ORDER BY e.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', @@ -348,9 +348,9 @@ class EntityNode(Node): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND n.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND n.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -368,11 +368,11 @@ class EntityNode(Node): n.summary AS summary, labels(n) AS labels, properties(n) AS attributes - ORDER BY n.created_at DESC + ORDER BY n.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', @@ -465,9 +465,9 @@ class CommunityNode(Node): driver: AsyncDriver, group_ids: list[str], limit: int | None = None, - created_at: datetime | None = None, + uuid_cursor: str | None = None, ): - cursor_query: LiteralString = 'AND n.created_at < $created_at' if created_at else '' + cursor_query: LiteralString = 'AND n.uuid < $uuid' if uuid_cursor else '' limit_query: LiteralString = 'LIMIT $limit' if limit is not None else '' records, _, _ = await driver.execute_query( @@ -483,11 +483,11 @@ class CommunityNode(Node): n.group_id AS group_id, n.created_at AS created_at, n.summary AS summary - ORDER BY n.created_at DESC + ORDER BY n.uuid DESC """ + limit_query, group_ids=group_ids, - created_at=created_at, + uuid=uuid_cursor, limit=limit, database_=DEFAULT_DATABASE, routing_='r', diff --git a/pyproject.toml b/pyproject.toml index 3f1413d5..45f0d3ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "graphiti-core" -version = "0.9.0" +version = "0.9.1" description = "A temporal graph building library" authors = [ "Paul Paliychuk ",