From c6ec22a5a0d70960a068a8ec95cfd8fd5083e7e0 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Tue, 19 Aug 2025 13:36:22 +0200 Subject: [PATCH] feat: adds scores to Feedback node --- cognee/modules/retrieval/user_qa_feedback.py | 3 ++- cognee/modules/retrieval/utils/models.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cognee/modules/retrieval/user_qa_feedback.py b/cognee/modules/retrieval/user_qa_feedback.py index bca59e7f8..45b5b0ec0 100644 --- a/cognee/modules/retrieval/user_qa_feedback.py +++ b/cognee/modules/retrieval/user_qa_feedback.py @@ -28,7 +28,7 @@ class UserQAFeedback(BaseFeedback): async def add_feedback(self, feedback_text: str) -> List[str]: feedback_sentiment = await LLMGateway.acreate_structured_output( text_input=feedback_text, - system_prompt="You are a sentiment analysis assistant. For each piece of user feedback you receive, return exactly one of: Positive, Negative, or Neutral classification", + system_prompt="You are a sentiment analysis assistant. For each piece of user feedback you receive, return exactly one of: Positive, Negative, or Neutral classification and a corresponding score from -5 (worst negative) to 5 (best positive)", response_model=UserFeedbackEvaluation, ) @@ -43,6 +43,7 @@ class UserQAFeedback(BaseFeedback): id=feedback_id, feedback=feedback_text, sentiment=feedback_sentiment.evaluation.value, + score=feedback_sentiment.score, belongs_to_set=feedbacks_node_set, ) diff --git a/cognee/modules/retrieval/utils/models.py b/cognee/modules/retrieval/utils/models.py index 69ffa9a5f..a71e881a9 100644 --- a/cognee/modules/retrieval/utils/models.py +++ b/cognee/modules/retrieval/utils/models.py @@ -2,8 +2,7 @@ from typing import Optional from cognee.infrastructure.engine.models.DataPoint import DataPoint from cognee.modules.engine.models.node_set import NodeSet from enum import Enum -from pydantic import BaseModel, ValidationError - +from pydantic import BaseModel, Field, confloat class CogneeUserInteraction(DataPoint): """User - Cognee interaction""" @@ -19,6 +18,7 @@ class CogneeUserFeedback(DataPoint): feedback: str sentiment: str + score: float belongs_to_set: Optional[NodeSet] = None @@ -32,5 +32,8 @@ class UserFeedbackSentiment(str, Enum): class UserFeedbackEvaluation(BaseModel): """User - User feedback evaluation""" - + score: confloat(ge=-5, le=5) = Field( + ..., + description="Sentiment score from -5 (negative) to +5 (positive)" + ) evaluation: UserFeedbackSentiment