
    i                        d Z ddlmZmZ  G d de      Z G d de      Z G d de      Z G d	 d
e      Z G d de      Z	 G d de      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e	      Z G d! d"e	      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Zy+),z
Custom exceptions for the RAG system.

This module defines all custom exceptions used throughout the RAG system
to provide better error handling and debugging capabilities.
    )AnyOptionalc                   4     e Zd ZdZddedee   f fdZ xZS )RAGSystemErrorz)Base exception for all RAG system errors.messagedetailsc                 H    t         |   |       || _        |xs i | _        y N)super__init__r   r   )selfr   r   	__class__s      //var/www/html/backtest/airagagent/exceptions.pyr   zRAGSystemError.__init__   s"    !}"    r
   	__name__
__module____qualname____doc__strr   dictr   __classcell__r   s   @r   r   r      s"    3% %htn % %r   r   c                       e Zd ZdZy)ConfigurationErrorz2Raised when there's a configuration-related error.Nr   r   r   r    r   r   r   r          <r   r   c                       e Zd ZdZy)
ModelErrorz<Raised when there's an error with language model operations.Nr   r   r   r   r    r       s    Fr   r    c                       e Zd ZdZy)VectorStoreErrorz:Raised when there's an error with vector store operations.Nr   r   r   r   r"   r"      s    Dr   r"   c                       e Zd ZdZy)DocumentProcessingErrorz2Raised when there's an error processing documents.Nr   r   r   r   r$   r$   "   r   r   r$   c                       e Zd ZdZy)SearchErrorz6Raised when there's an error during search operations.Nr   r   r   r   r&   r&   '   s    @r   r&   c                       e Zd ZdZy)ValidationErrorz#Raised when input validation fails.Nr   r   r   r   r(   r(   ,   s    -r   r(   c                       e Zd ZdZy)ResourceErrorzIRaised when there are resource-related errors (memory, disk space, etc.).Nr   r   r   r   r*   r*   1   s    Sr   r*   c                       e Zd ZdZy)SecurityErrorz.Raised when there are security-related errors.Nr   r   r   r   r,   r,   6   s    8r   r,   c                       e Zd ZdZy)APILimitErrorz)Raised when API rate limits are exceeded.Nr   r   r   r   r.   r.   ;   s    3r   r.   c                   4     e Zd ZdZddedee   f fdZ xZS )ModelLoadErrorz Raised when model loading fails.
model_namer   c                 0    d| }t         |   ||       y )NzFailed to load model: r   r   )r   r1   r   r   r   s       r   r   zModelLoadError.__init__D   s    *:,7'*r   r
   r   r   s   @r   r0   r0   B   s"    *+3 +$ + +r   r0   c                   4     e Zd ZdZddedee   f fdZ xZS )EmbeddingErrorz'Raised when embedding generation fails.text_previewr   c                 8    d|d d  d}t         |   ||       y )Nz(Failed to generate embeddings for text: d   z...r3   )r   r6   r   r   r   s       r   r   zEmbeddingError.__init__K   s)    <\$3=O<PPST'*r   r
   r   r   s   @r   r5   r5   I   s"    1+S +8D> + +r   r5   c                   4     e Zd ZdZddedee   f fdZ xZS )IndexLoadErrorz&Raised when loading FAISS index fails.
index_pathr   c                 0    d| }t         |   ||       y )Nz!Failed to load FAISS index from: r3   r   r;   r   r   r   s       r   r   zIndexLoadError.__init__R   s    5j\B'*r   r
   r   r   s   @r   r:   r:   P   s"    0+3 +$ + +r   r:   c                   4     e Zd ZdZddedee   f fdZ xZS )IndexSaveErrorz%Raised when saving FAISS index fails.r;   r   c                 0    d| }t         |   ||       y )NzFailed to save FAISS index to: r3   r=   s       r   r   zIndexSaveError.__init__Y   s    3J<@'*r   r
   r   r   s   @r   r?   r?   W   s"    /+3 +$ + +r   r?   c                   4     e Zd ZdZddedee   f fdZ xZS )PDFParseErrorzRaised when PDF parsing fails.	file_pathr   c                 0    d| }t         |   ||       y )NzFailed to parse PDF file: r3   )r   rC   r   r   r   s       r   r   zPDFParseError.__init__`   s    .yk:'*r   r
   r   r   s   @r   rB   rB   ^   s"    (+# + + +r   rB   c                   0     e Zd ZdZddee   f fdZ xZS )ChunkingErrorz$Raised when document chunking fails.r   c                 *    d}t         |   ||       y )NzFailed to chunk documentr3   )r   r   r   r   s      r   r   zChunkingError.__init__g   s    ,'*r   r
   )r   r   r   r   r   r   r   r   r   s   @r   rF   rF   e   s    .+ + +r   rF   c                   8     e Zd ZdZddededee   f fdZ xZS )InvalidQueryErrorz#Raised when query validation fails.queryreasonr   c                 <    d|d d  d| }t         |   ||       y )NzInvalid query '2   z...': r3   )r   rJ   rK   r   r   r   s        r   r   zInvalidQueryError.__init__n   s*    #E#2J<vfX>'*r   r
   r   r   s   @r   rI   rI   l   s)    -+c +3 +$ + +r   rI   c                   8     e Zd ZdZddededee   f fdZ xZS )FileUploadErrorz)Raised when file upload validation fails.filenamerK   r   c                 6    d| d| }t         |   ||       y )NzFile upload failed for 'z': r3   )r   rP   rK   r   r   r   s        r   r   zFileUploadError.__init__u   s$    ,XJc&B'*r   r
   r   r   s   @r   rO   rO   s   s)    3+ +c +HTN + +r   rO   c                   8     e Zd ZdZddededee   f fdZ xZS )MemoryLimitErrorz'Raised when memory limits are exceeded.current_usagelimitr   c                 8    d| d| d}t         |   ||       y )NzMemory limit exceeded: z	MB used, zMB limitr3   )r   rT   rU   r   r   r   s        r   r   zMemoryLimitError.__init__|   s&    +M?)E7(S'*r   r
   	r   r   r   r   intr   r   r   r   r   s   @r   rS   rS   z   s)    1+c +# + + +r   rS   c                   8     e Zd ZdZddededee   f fdZ xZS )DiskSpaceErrorz'Raised when disk space is insufficient.required_spaceavailable_spacer   c                 8    d| d| d}t         |   ||       y )NzInsufficient disk space: zMB required, zMB availabler3   )r   r[   r\   r   r   r   s        r   r   zDiskSpaceError.__init__   s)    -n-=]?J[[gh'*r   r
   rW   r   s   @r   rZ   rZ      s*    1+s +S +8TX> + +r   rZ   N)r   typingr   r   	Exceptionr   r   r    r"   r$   r&   r(   r*   r,   r.   r0   r5   r:   r?   rB   rF   rI   rO   rS   rZ   r   r   r   <module>r`      s   !%Y %	 	
	 	
	~ 	
	n 	
	. 	
	n 	
	N 	
	N 	
	N 	+Z ++Z ++% ++% +++ +++ ++ ++o ++} ++] +r   