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
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import List, Optional, Any, Union, Tuple
|
|
import os
|
|
import json
|
|
from cognee.shared.logging_utils import get_logger
|
|
|
|
logger = get_logger()
|
|
|
|
|
|
class BaseBenchmarkAdapter(ABC):
|
|
async def prepare_corpus(self) -> None:
|
|
return None
|
|
|
|
def _filter_instances(
|
|
self,
|
|
instances: List[dict[str, Any]],
|
|
instance_filter: Union[str, List[str], List[int]],
|
|
id_key: str = "id",
|
|
) -> List[dict[str, Any]]:
|
|
"""Filter instances by IDs or indices, or load filter from a JSON file."""
|
|
if isinstance(instance_filter, str):
|
|
logger.info(f"Loading instance filter from file: {instance_filter}")
|
|
if not os.path.isfile(instance_filter):
|
|
raise FileNotFoundError(f"Filter file not found: {instance_filter}")
|
|
|
|
with open(instance_filter, "r", encoding="utf-8") as f:
|
|
try:
|
|
instance_filter = json.load(f)
|
|
except json.JSONDecodeError as e:
|
|
raise ValueError(f"Invalid JSON in filter file: {e}")
|
|
|
|
if all(isinstance(fid, str) for fid in instance_filter):
|
|
logger.info(f"Filtering by {len(instance_filter)} string IDs using key '{id_key}'")
|
|
filtered = [inst for inst in instances if inst.get(id_key) in instance_filter]
|
|
if not filtered:
|
|
logger.warning(f"No instances found with the provided IDs using key '{id_key}'")
|
|
return filtered
|
|
|
|
if all(isinstance(fid, int) for fid in instance_filter):
|
|
logger.info(f"Filtering by {len(instance_filter)} integer indices")
|
|
filtered = [instances[i] for i in instance_filter if 0 <= i < len(instances)]
|
|
if not filtered:
|
|
logger.warning("No instances found at the provided indices")
|
|
return filtered
|
|
|
|
raise ValueError(
|
|
"instance_filter must be a list of string ids, integer indices, or a JSON file path."
|
|
)
|
|
|
|
@abstractmethod
|
|
def load_corpus(
|
|
self,
|
|
limit: Optional[int] = None,
|
|
seed: int = 42,
|
|
load_golden_context: bool = False,
|
|
instance_filter: Optional[Union[str, List[str], List[int]]] = None,
|
|
) -> Tuple[List[str], List[dict[str, Any]]]:
|
|
pass
|