From c0e5ce04cedbf3bc4511e73ed2e2276e21c2f978 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Thu, 6 Nov 2025 14:13:55 +0100 Subject: [PATCH] Fix: fixes session history test for multiuser mode (#1746) ## Description Fixes failing session history test ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Screenshots/Videos (if applicable) ## Pre-submission Checklist - [x] **I have tested my changes thoroughly before submitting this PR** - [x] **This PR contains minimal changes necessary to address the issue/feature** - [x] My code follows the project's coding standards and style guidelines - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added necessary documentation (if applicable) - [x] All new and existing tests pass - [x] I have searched existing PRs to ensure this change hasn't been submitted already - [x] I have linked any relevant issues in the description - [x] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --- .../persist_sessions_in_knowledge_graph.py | 2 +- cognee/tasks/memify/cognify_session.py | 7 ++++--- cognee/tests/test_conversation_history.py | 6 +++--- .../modules/memify_tasks/test_cognify_session.py | 12 ++++++++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cognee/memify_pipelines/persist_sessions_in_knowledge_graph.py b/cognee/memify_pipelines/persist_sessions_in_knowledge_graph.py index c0ba0a4d9..92d64c156 100644 --- a/cognee/memify_pipelines/persist_sessions_in_knowledge_graph.py +++ b/cognee/memify_pipelines/persist_sessions_in_knowledge_graph.py @@ -40,7 +40,7 @@ async def persist_sessions_in_knowledge_graph_pipeline( extraction_tasks = [Task(extract_user_sessions, session_ids=session_ids)] enrichment_tasks = [ - Task(cognify_session), + Task(cognify_session, dataset_id=dataset_to_write[0].id), ] result = await memify( diff --git a/cognee/tasks/memify/cognify_session.py b/cognee/tasks/memify/cognify_session.py index 7c276169a..f53f9afb1 100644 --- a/cognee/tasks/memify/cognify_session.py +++ b/cognee/tasks/memify/cognify_session.py @@ -6,7 +6,7 @@ from cognee.shared.logging_utils import get_logger logger = get_logger("cognify_session") -async def cognify_session(data): +async def cognify_session(data, dataset_id=None): """ Process and cognify session data into the knowledge graph. @@ -16,6 +16,7 @@ async def cognify_session(data): Args: data: Session string containing Question, Context, and Answer information. + dataset_name: Name of dataset. Raises: CogneeValidationError: If data is None or empty. @@ -28,9 +29,9 @@ async def cognify_session(data): logger.info("Processing session data for cognification") - await cognee.add(data, node_set=["user_sessions_from_cache"]) + await cognee.add(data, dataset_id=dataset_id, node_set=["user_sessions_from_cache"]) logger.debug("Session data added to cognee with node_set: user_sessions") - await cognee.cognify() + await cognee.cognify(datasets=[dataset_id]) logger.info("Session data successfully cognified") except CogneeValidationError: diff --git a/cognee/tests/test_conversation_history.py b/cognee/tests/test_conversation_history.py index 6b5b737f1..783baf563 100644 --- a/cognee/tests/test_conversation_history.py +++ b/cognee/tests/test_conversation_history.py @@ -56,10 +56,10 @@ async def main(): """DataCo is a data analytics company. They help businesses make sense of their data.""" ) - await cognee.add(text_1, dataset_name) - await cognee.add(text_2, dataset_name) + await cognee.add(data=text_1, dataset_name=dataset_name) + await cognee.add(data=text_2, dataset_name=dataset_name) - await cognee.cognify([dataset_name]) + await cognee.cognify(datasets=[dataset_name]) user = await get_default_user() diff --git a/cognee/tests/unit/modules/memify_tasks/test_cognify_session.py b/cognee/tests/unit/modules/memify_tasks/test_cognify_session.py index c23640fbd..8c2448287 100644 --- a/cognee/tests/unit/modules/memify_tasks/test_cognify_session.py +++ b/cognee/tests/unit/modules/memify_tasks/test_cognify_session.py @@ -16,9 +16,11 @@ async def test_cognify_session_success(): patch("cognee.add", new_callable=AsyncMock) as mock_add, patch("cognee.cognify", new_callable=AsyncMock) as mock_cognify, ): - await cognify_session(session_data) + await cognify_session(session_data, dataset_id="123") - mock_add.assert_called_once_with(session_data, node_set=["user_sessions_from_cache"]) + mock_add.assert_called_once_with( + session_data, dataset_id="123", node_set=["user_sessions_from_cache"] + ) mock_cognify.assert_called_once() @@ -101,7 +103,9 @@ async def test_cognify_session_with_special_characters(): patch("cognee.add", new_callable=AsyncMock) as mock_add, patch("cognee.cognify", new_callable=AsyncMock) as mock_cognify, ): - await cognify_session(session_data) + await cognify_session(session_data, dataset_id="123") - mock_add.assert_called_once_with(session_data, node_set=["user_sessions_from_cache"]) + mock_add.assert_called_once_with( + session_data, dataset_id="123", node_set=["user_sessions_from_cache"] + ) mock_cognify.assert_called_once()