Skip to content

Exceptions

All Medha exceptions inherit from MedhaError, making it easy to catch any library error with a single handler.

from medha.exceptions import MedhaError

try:
    async with Medha(...) as cache:
        await cache.store(...)
except MedhaError as exc:
    logger.error("Medha error: %s", exc)

Exception Hierarchy

Exception Raised When
MedhaError Base class for all Medha exceptions
ConfigurationError Invalid Settings values (e.g. threshold ordering violation)
EmbeddingError Embedder fails to produce a vector (API error, model load failure)
StorageError Vector backend read/write operation fails
StorageInitializationError Backend cannot connect or create the collection at startup
TemplateError A QueryTemplate is malformed or cannot be registered
ParameterExtractionError Named entity extraction fails during template matching

MedhaError

Bases: Exception

Base exception for all Medha errors.

Source code in src/medha/exceptions.py
class MedhaError(Exception):
    """Base exception for all Medha errors."""

ConfigurationError

Bases: MedhaError

Raised when configuration is invalid or required environment variables are missing.

Source code in src/medha/exceptions.py
class ConfigurationError(MedhaError):
    """Raised when configuration is invalid or required environment variables are missing."""

EmbeddingError

Bases: MedhaError

Raised when embedding generation fails.

Source code in src/medha/exceptions.py
class EmbeddingError(MedhaError):
    """Raised when embedding generation fails."""

StorageError

Bases: MedhaError

Raised when the vector storage backend encounters an error.

Source code in src/medha/exceptions.py
class StorageError(MedhaError):
    """Raised when the vector storage backend encounters an error."""

StorageInitializationError

Bases: StorageError

Raised when collection creation or storage initialization fails.

Source code in src/medha/exceptions.py
class StorageInitializationError(StorageError):
    """Raised when collection creation or storage initialization fails."""

TemplateError

Bases: MedhaError

Raised when template loading, matching, or rendering fails.

Source code in src/medha/exceptions.py
class TemplateError(MedhaError):
    """Raised when template loading, matching, or rendering fails."""

ParameterExtractionError

Bases: MedhaError

Raised when required parameters cannot be extracted from the input.

Source code in src/medha/exceptions.py
class ParameterExtractionError(MedhaError):
    """Raised when required parameters cannot be extracted from the input."""