Skip to content

Commit

Permalink
Merge pull request #415 from topoteretes/feature/cog-871-remove-dupli…
Browse files Browse the repository at this point in the history
…cate-edges-from-the-cognify-graph

fix: Fixes duplicated edges in cognify by limiting the recursion dept…
  • Loading branch information
Vasilije1990 authored Jan 8, 2025
2 parents 6ed2c23 + bd644a1 commit 35892f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cognee/api/v1/cognify/cognify_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def run_cognify_pipeline(dataset: Dataset, user: User, graph_model: BaseMo
summarization_model = cognee_config.summarization_model,
task_config = { "batch_size": 10 }
),
Task(add_data_points, task_config = { "batch_size": 10 }),
Task(add_data_points, only_root = True, task_config = { "batch_size": 10 }),
]

pipeline = run_tasks(tasks, data_documents, "cognify_pipeline")
Expand Down
3 changes: 2 additions & 1 deletion cognee/modules/graph/utils/get_graph_from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async def get_graph_from_model(
added_nodes: dict,
added_edges: dict,
visited_properties: dict = None,
only_root = False,
include_root = True,
):
if str(data_point.id) in added_nodes:
Expand Down Expand Up @@ -86,7 +87,7 @@ async def get_graph_from_model(
}))
added_edges[str(edge_key)] = True

if str(field_value.id) in added_nodes:
if str(field_value.id) in added_nodes or only_root:
continue

property_nodes, property_edges = await get_graph_from_model(
Expand Down
3 changes: 2 additions & 1 deletion cognee/tasks/storage/add_data_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .index_data_points import index_data_points


async def add_data_points(data_points: list[DataPoint]):
async def add_data_points(data_points: list[DataPoint], only_root = False):
nodes = []
edges = []

Expand All @@ -19,6 +19,7 @@ async def add_data_points(data_points: list[DataPoint]):
added_nodes = added_nodes,
added_edges = added_edges,
visited_properties = visited_properties,
only_root = only_root,
) for data_point in data_points
])

Expand Down

0 comments on commit 35892f9

Please sign in to comment.