get edges by node uuid (#291)

* get edges by node uuid

* lint
This commit is contained in:
Preston Rasmussen 2025-03-13 15:44:02 -04:00 committed by GitHub
parent e83bcbb435
commit daf14a6509
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 7 deletions

View file

@ -337,6 +337,32 @@ class EntityEdge(Edge):
raise GroupsEdgesNotFoundError(group_ids)
return edges
@classmethod
async def get_by_node_uuid(cls, driver: AsyncDriver, node_uuid: str):
query: LiteralString = """
MATCH (n:Entity {uuid: $node_uuid})-[e:RELATES_TO]-(m:Entity)
RETURN DISTINCT
e.uuid AS uuid,
n.uuid AS source_node_uuid,
m.uuid AS target_node_uuid,
e.created_at AS created_at,
e.name AS name,
e.group_id AS group_id,
e.fact AS fact,
e.fact_embedding AS fact_embedding,
e.episodes AS episodes,
e.expired_at AS expired_at,
e.valid_at AS valid_at,
e.invalid_at AS invalid_at
"""
records, _, _ = await driver.execute_query(
query, node_uuid=node_uuid, database_=DEFAULT_DATABASE, routing_='r'
)
edges = [get_entity_edge_from_record(record) for record in records]
return edges
class CommunityEdge(Edge):
async def save(self, driver: AsyncDriver):

View file

@ -39,7 +39,6 @@ from graphiti_core.search.search_config_recipes import (
from graphiti_core.search.search_filters import SearchFilters
from graphiti_core.search.search_utils import (
RELEVANT_SCHEMA_LIMIT,
get_communities_by_nodes,
get_mentioned_nodes,
get_relevant_edges,
get_relevant_nodes,
@ -708,7 +707,7 @@ class Graphiti:
bfs_origin_node_uuids,
)
async def get_episode_mentions(self, episode_uuids: list[str]) -> SearchResults:
async def nodes_and_edges_by_episode(self, episode_uuids: list[str]) -> SearchResults:
episodes = await EpisodicNode.get_by_uuids(self.driver, episode_uuids)
edges_list = await semaphore_gather(
@ -719,9 +718,7 @@ class Graphiti:
nodes = await get_mentioned_nodes(self.driver, episodes)
communities = await get_communities_by_nodes(self.driver, nodes)
return SearchResults(edges=edges, nodes=nodes, communities=communities)
return SearchResults(edges=edges, nodes=nodes, communities=[])
async def add_triplet(self, source_node: EntityNode, edge: EntityEdge, target_node: EntityNode):
if source_node.name_embedding is None:

View file

@ -28,7 +28,7 @@ load_dotenv()
DEFAULT_DATABASE = os.getenv('DEFAULT_DATABASE', None)
USE_PARALLEL_RUNTIME = bool(os.getenv('USE_PARALLEL_RUNTIME', False))
SEMAPHORE_LIMIT = int(os.getenv('SEMAPHORE_LIMIT', 20))
MAX_REFLEXION_ITERATIONS = 2
MAX_REFLEXION_ITERATIONS = int(os.getenv('MAX_REFLEXION_ITERATIONS', 2))
DEFAULT_PAGE_LIMIT = 20

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "graphiti-core"
version = "0.7.9"
version = "0.7.10"
description = "A temporal graph building library"
authors = [
"Paul Paliychuk <paul@getzep.com>",