c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from typing import Any, Dict, List
|
|
from pydantic import BaseModel
|
|
from cognee.eval_framework.evaluation.base_eval_adapter import BaseEvalAdapter
|
|
from cognee.eval_framework.eval_config import EvalConfig
|
|
|
|
from cognee.infrastructure.llm.prompts import render_prompt, read_query_prompt
|
|
from cognee.infrastructure.llm import LLMGateway
|
|
|
|
|
|
class CorrectnessEvaluation(BaseModel):
|
|
"""Response model containing evaluation score and explanation."""
|
|
|
|
score: float
|
|
explanation: str
|
|
|
|
|
|
class DirectLLMEvalAdapter(BaseEvalAdapter):
|
|
def __init__(self):
|
|
"""Initialize adapter with prompt paths from config."""
|
|
config = EvalConfig()
|
|
self.system_prompt_path = config.direct_llm_system_prompt
|
|
self.eval_prompt_path = config.direct_llm_eval_prompt
|
|
|
|
async def evaluate_correctness(
|
|
self, question: str, answer: str, golden_answer: str
|
|
) -> Dict[str, Any]:
|
|
args = {"question": question, "answer": answer, "golden_answer": golden_answer}
|
|
|
|
user_prompt = render_prompt(self.eval_prompt_path, args)
|
|
system_prompt = read_query_prompt(self.system_prompt_path)
|
|
|
|
evaluation = await LLMGateway.acreate_structured_output(
|
|
text_input=user_prompt,
|
|
system_prompt=system_prompt,
|
|
response_model=CorrectnessEvaluation,
|
|
)
|
|
|
|
return {"score": evaluation.score, "reason": evaluation.explanation}
|
|
|
|
async def evaluate_answers(
|
|
self, answers: List[Dict[str, Any]], evaluator_metrics: List[str]
|
|
) -> List[Dict[str, Any]]:
|
|
"""Evaluate a list of answers using specified metrics."""
|
|
if not answers or not evaluator_metrics:
|
|
return []
|
|
|
|
if "correctness" not in evaluator_metrics:
|
|
return [{"metrics": {}, **answer} for answer in answers]
|
|
|
|
results = []
|
|
for answer in answers:
|
|
correctness = await self.evaluate_correctness(
|
|
question=answer["question"],
|
|
answer=answer["answer"],
|
|
golden_answer=answer["golden_answer"],
|
|
)
|
|
results.append({**answer, "metrics": {"correctness": correctness}})
|
|
|
|
return results
|