Coverage for src/dataknobs_data/vector/exceptions.py: 41%
32 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-13 11:23 -0700
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-13 11:23 -0700
1"""Vector-specific exceptions.
3This module defines exception types for vector operations,
4built on the common exception framework from dataknobs_common.
5"""
7from __future__ import annotations
9from dataknobs_common import (
10 DataknobsError,
11 OperationError,
12 ResourceError,
13 ValidationError,
14)
16# Create VectorError as alias to DataknobsError for backward compatibility
17VectorError = DataknobsError
20class VectorDimensionError(ValidationError):
21 """Raised when vector dimensions don't match expectations."""
23 def __init__(self, expected: int, actual: int, field_name: str | None = None):
24 """Initialize dimension error.
26 Args:
27 expected: Expected number of dimensions
28 actual: Actual number of dimensions
29 field_name: Optional field name for context
30 """
31 self.expected = expected
32 self.actual = actual
33 self.field_name = field_name
35 message = f"Vector dimension mismatch: expected {expected}, got {actual}"
36 if field_name:
37 message = f"{message} for field '{field_name}'"
39 context = {"expected": expected, "actual": actual}
40 if field_name:
41 context["field_name"] = field_name
43 super().__init__(message, context=context)
46class VectorBackendError(ResourceError):
47 """Raised when vector backend operations fail."""
49 pass
52class VectorIndexError(OperationError):
53 """Raised when vector index operations fail."""
55 pass
58class VectorNotSupportedError(OperationError):
59 """Raised when vector operations are not supported by backend."""
61 def __init__(self, backend: str, operation: str | None = None):
62 """Initialize not supported error.
64 Args:
65 backend: Name of the backend
66 operation: Optional specific operation that's not supported
67 """
68 self.backend = backend
69 self.operation = operation
71 message = f"Vector operations not supported by {backend} backend"
72 if operation:
73 message = f"{message}: {operation}"
75 context = {"backend": backend}
76 if operation:
77 context["operation"] = operation
79 super().__init__(message, context=context)
82class VectorValidationError(ValidationError):
83 """Raised when vector validation fails."""
85 pass