feat: adds new search classes to search.py

This commit is contained in:
hajdul88 2025-08-13 12:29:35 +02:00
parent 657c775cbe
commit 5bc00f1143
3 changed files with 26 additions and 3 deletions

View file

@ -0,0 +1,9 @@
"""
Custom exceptions for the Cognee API.
This module defines a set of exceptions for handling various data errors
"""
from .exceptions import (
UnsupportedSearchTypeError
)

View file

@ -0,0 +1,15 @@
from cognee.exceptions import (
CogneeValidationError,
)
from fastapi import status
class UnsupportedSearchTypeError(CogneeValidationError):
def __init__(
self,
search_type: str,
name: str = "UnsupportedSearchTypeError",
status_code: int = status.HTTP_400_BAD_REQUEST,
):
message = f"Unsupported search type: {search_type}"
super().__init__(message, name, status_code)

View file

@ -3,9 +3,8 @@ import json
import asyncio import asyncio
from uuid import UUID from uuid import UUID
from typing import Callable, List, Optional, Type, Union from typing import Callable, List, Optional, Type, Union
from cognee.modules.search.exceptions import UnsupportedSearchTypeError
from cognee.context_global_variables import set_database_global_context_variables from cognee.context_global_variables import set_database_global_context_variables
from cognee.exceptions import InvalidValueError
from cognee.modules.retrieval.chunks_retriever import ChunksRetriever from cognee.modules.retrieval.chunks_retriever import ChunksRetriever
from cognee.modules.retrieval.insights_retriever import InsightsRetriever from cognee.modules.retrieval.insights_retriever import InsightsRetriever
from cognee.modules.retrieval.summaries_retriever import SummariesRetriever from cognee.modules.retrieval.summaries_retriever import SummariesRetriever
@ -136,7 +135,7 @@ async def specific_search(
search_task = search_tasks.get(query_type) search_task = search_tasks.get(query_type)
if search_task is None: if search_task is None:
raise InvalidValueError(message=f"Unsupported search type: {query_type}") raise UnsupportedSearchTypeError(str(query_type))
send_telemetry("cognee.search EXECUTION STARTED", user.id) send_telemetry("cognee.search EXECUTION STARTED", user.id)