Skip to content

Commit

Permalink
Delete bad, unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem committed Nov 30, 2024
1 parent 6d395a1 commit ff8c499
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 94 deletions.
3 changes: 1 addition & 2 deletions py/core/pipes/kg/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ async def cluster_kg(

num_communities = await self.database_provider.graph_handler.perform_graph_clustering(
collection_id=collection_id,
# graph_id=graph_id,
leiden_params=leiden_params,
) # type: ignore
)

logger.info(
f"Clustering completed. Generated {num_communities} communities."
Expand Down
96 changes: 4 additions & 92 deletions py/core/providers/database/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,58 +1710,6 @@ async def add_entities_v3(

# return True

async def add_relationships_v3(
self, id: UUID, relationship_ids: list[UUID], copy_data: bool = True
) -> bool:
"""
Add relationships to the graph.
"""
QUERY = f"""
UPDATE {self._get_table_name("relationship")}
SET graph_ids = array_append(graph_ids, $1)
WHERE id = ANY($2)
"""
await self.connection_manager.execute_query(
QUERY, [id, relationship_ids]
)

if copy_data:
QUERY = f"""
INSERT INTO {self._get_table_name("graph_relationship")}
SELECT * FROM {self._get_table_name("relationship")}
WHERE id = ANY($1)
"""
await self.connection_manager.execute_query(
QUERY, [relationship_ids]
)

return True

async def remove_relationships(
self, id: UUID, relationship_ids: list[UUID], delete_data: bool = True
) -> bool:
"""
Remove relationships from the graph.
"""
QUERY = f"""
UPDATE {self._get_table_name("relationship")}
SET graph_ids = array_remove(graph_ids, $1)
WHERE id = ANY($2)
"""
await self.connection_manager.execute_query(
QUERY, [id, relationship_ids]
)

if delete_data:
QUERY = f"""
DELETE FROM {self._get_table_name("graph_relationship")} WHERE id = ANY($1)
"""
await self.connection_manager.execute_query(
QUERY, [relationship_ids]
)

return True

async def update(
self,
graph_id: UUID,
Expand Down Expand Up @@ -2236,30 +2184,6 @@ async def delete_node_via_document_id(
return None
return None

##################### RELATIONSHIP METHODS #####################

# DEPRECATED
async def add_relationships(
self,
relationships: list[Relationship],
table_name: str = "relationship",
): # type: ignore
"""
Upsert relationships into the relationship table. These are raw relationships extracted from the document.
Args:
relationships: list[Relationship]: list of relationships to upsert
table_name: str: name of the table to upsert into
Returns:
result: asyncpg.Record: result of the upsert operation
"""
return await _add_objects(
objects=[ele.to_dict() for ele in relationships],
full_table_name=self._get_table_name(table_name),
connection_manager=self.connection_manager,
)

async def get_all_relationships(
self,
collection_id: UUID | None,
Expand Down Expand Up @@ -2360,7 +2284,7 @@ async def get(

# Build conditions and parameters for listing relationships
conditions = ["parent_id = $1"]
params = [parent_id]
params: list[Any] = [parent_id]
param_index = 2

if entity_names:
Expand Down Expand Up @@ -2748,10 +2672,8 @@ async def delete_graph_for_collection(

async def perform_graph_clustering(
self,
collection_id: UUID | None,
# graph_id: UUID | None,
collection_id: UUID,
leiden_params: dict[str, Any],
use_community_cache: bool = False,
) -> int:
"""
Leiden clustering algorithm to cluster the knowledge graph relationships into communities.
Expand All @@ -2770,8 +2692,6 @@ async def perform_graph_clustering(
check_directed: bool = True,
"""

start_time = time.time()

# # relationships = await self.get_all_relationships(
# # collection_id, collection_id # , graph_id
# # )
Expand Down Expand Up @@ -3079,8 +2999,6 @@ async def graph_search(
print("output = ", output)
yield output

####################### GRAPH CLUSTERING METHODS #######################

async def _create_graph_and_cluster(
self, relationships: list[Relationship], leiden_params: dict[str, Any]
) -> Any:
Expand All @@ -3096,11 +3014,7 @@ async def _create_graph_and_cluster(

logger.info(f"Graph has {len(G.nodes)} nodes and {len(G.edges)} edges")

hierarchical_communities = await self._compute_leiden_communities(
G, leiden_params
)

return hierarchical_communities
return await self._compute_leiden_communities(G, leiden_params)

async def _cluster_and_add_community_info(
self,
Expand Down Expand Up @@ -3456,7 +3370,7 @@ async def update_entity_descriptions(self, entities: list[Entity]):
inputs = [
(
entity.name,
entity.graph_id,
entity.parent_id,
entity.description,
entity.description_embedding,
)
Expand All @@ -3465,8 +3379,6 @@ async def update_entity_descriptions(self, entities: list[Entity]):

await self.connection_manager.execute_many(query, inputs) # type: ignore

####################### PRIVATE METHODS ##########################


def _json_serialize(obj):
if isinstance(obj, UUID):
Expand Down

0 comments on commit ff8c499

Please sign in to comment.