feat: adds userfeedback sentiment calculation to feedback search type

This commit is contained in:
hajdul88 2025-07-31 09:39:59 +02:00
parent 65fbfe61c1
commit 7e103a7488
2 changed files with 23 additions and 2 deletions

View file

@ -2,10 +2,12 @@ from typing import Any, Optional
from uuid import NAMESPACE_OID, uuid5, UUID
from cognee.infrastructure.databases.graph import get_graph_engine
from cognee.infrastructure.llm.get_llm_client import get_llm_client
from cognee.modules.engine.models import NodeSet
from cognee.shared.logging_utils import get_logger
from cognee.modules.retrieval.base_feedback import BaseFeedback
from cognee.modules.retrieval.utils.models import CogneeUserFeedback
from cognee.modules.retrieval.utils.models import UserFeedbackEvaluation
from cognee.tasks.storage import add_data_points
logger = get_logger("CompletionRetriever")
@ -25,10 +27,15 @@ class UserQAFeedback(BaseFeedback):
self.last_k = last_k
async def add_feedback(self, feedback_text: str) -> Any:
graph_engine = await get_graph_engine()
llm_client = get_llm_client()
feedback_sentiment = await llm_client.acreate_structured_output(
feedback_text,
"You are a sentiment analysis assistant. For each piece of user feedback you receive, return exactly one of: Positive, Negative, or Neutral classification",
UserFeedbackEvaluation,
)
graph_engine = await get_graph_engine()
last_interaction_ids = await graph_engine.get_last_user_interaction_ids(limit=self.last_k)
print()
nodeset_name = "UserQAFeedbacks"
feedbacks_node_set = NodeSet(id=uuid5(NAMESPACE_OID, name=nodeset_name), name=nodeset_name)
@ -37,6 +44,7 @@ class UserQAFeedback(BaseFeedback):
cognee_user_feedback = CogneeUserFeedback(
id=feedback_id,
feedback=feedback_text,
sentiment=feedback_sentiment.evaluation.value,
belongs_to_set=feedbacks_node_set,
)

View file

@ -1,6 +1,8 @@
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
class CogneeUserInteraction(DataPoint):
@ -16,4 +18,15 @@ class CogneeUserFeedback(DataPoint):
"""User - Cognee Feedback"""
feedback: str
sentiment: str
belongs_to_set: Optional[NodeSet] = None
class UserFeedbackSentiment(str, Enum):
positive = "positive"
negative = "negative"
neutral = "neutral"
class UserFeedbackEvaluation(BaseModel):
evaluation: UserFeedbackSentiment