<!-- .github/pull_request_template.md --> ## Description This PR introduces a new memify pipeline to save cache sessions in cognee. The QA sessions are added to the main knowledge base as separate documents. ## Type of Change <!-- Please check the relevant option --> - [ ] Bug fix (non-breaking change that fixes an issue) - [x] 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) None ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [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.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
import cognee
|
|
|
|
from cognee.exceptions import CogneeValidationError, CogneeSystemError
|
|
from cognee.shared.logging_utils import get_logger
|
|
|
|
logger = get_logger("cognify_session")
|
|
|
|
|
|
async def cognify_session(data):
|
|
"""
|
|
Process and cognify session data into the knowledge graph.
|
|
|
|
Adds session content to cognee with a dedicated "user_sessions" node set,
|
|
then triggers the cognify pipeline to extract entities and relationships
|
|
from the session data.
|
|
|
|
Args:
|
|
data: Session string containing Question, Context, and Answer information.
|
|
|
|
Raises:
|
|
CogneeValidationError: If data is None or empty.
|
|
CogneeSystemError: If cognee operations fail.
|
|
"""
|
|
try:
|
|
if not data or (isinstance(data, str) and not data.strip()):
|
|
logger.warning("Empty session data provided to cognify_session task, skipping")
|
|
raise CogneeValidationError(message="Session data cannot be empty", log=False)
|
|
|
|
logger.info("Processing session data for cognification")
|
|
|
|
await cognee.add(data, node_set=["user_sessions_from_cache"])
|
|
logger.debug("Session data added to cognee with node_set: user_sessions")
|
|
await cognee.cognify()
|
|
logger.info("Session data successfully cognified")
|
|
|
|
except CogneeValidationError:
|
|
raise
|
|
except Exception as e:
|
|
logger.error(f"Error cognifying session data: {str(e)}")
|
|
raise CogneeSystemError(message=f"Failed to cognify session data: {str(e)}", log=False)
|