
    Xj 
                     4   d dl mZmZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ  ee          Z ee          Z e            Ze                    d           ee           e ed	                    fd
e
defd            ZdS )    )	APIRouterDepends)
Collectionconnectionsutility)
get_logger)Session)require_read)get_db)Userz/milvus/debugknowledge_basesdbcurrent_userc                     t                               d|j                    	 t          j        dd           t          j                    }t          |          g d}|s!d|d<   t                               d           |S |D ]}	 t          |          }|	                                 |j
        }||d |j        j        D             d	}|d
k    r)|                    dg dd          }d |D             |d<   |d                             |           # t          $ rU}	t                               d| d|	            |d                             |t#          |	          d           Y d }	~	d }	~	ww xY wt          j        d           t                               dt          |           d           |S # t          $ r9}	t                               d|	            t#          |	          ddcY d }	~	S d }	~	ww xY w)NzDebugging Milvus, user=debugz./data/milvus_data.db)aliasuri)total_collectionscollectionsz#No collections found in Milvus Litemessagec                     g | ]	}|j         
S  )name).0fields     J/lsinfo/ai/hellotax_ai/base_platform/app/api/v1/monitoring/milvus_debug.py
<listcomp>z debug_milvus.<locals>.<listcomp>'   s    PPPeuzPPP    )r   entitiesfieldsr    )document_idchunk_indexcontent   )exproutput_fieldslimitc                     g | ]J}|                     d           |                     d          |                     dd          dd         dKS )r"   r#   r$   r!   Nd   )r"   r#   content_preview)get)r   rs     r   r   z debug_milvus.<locals>.<listcomp>-   si     0 0 0 	 ,-55+?+?+,55+?+?/0uuY/C/CDSD/I 0 0 0r   sample_datar   zError processing collection z: )r   error)r   zMilvus debug completed: z collectionszMilvus debug failed: z Failed to connect to Milvus Lite)r/   r   )loggerinfoidr   connectr   list_collectionslenr   loadnum_entitiesschemar    queryappend	Exceptionwarningstr
disconnectr/   )
r   r   r   result	coll_name
collectionr7   	coll_infosample_resultses
             r   debug_milvusrE      s    KK;,/;;<<<'P'/FGGGG.00'*;'7'7KK 	 EF9KK=>>>M$ 	S 	SIS'	22
!!!)6% ,PPz7H7OPPP 	
  !##%/%5%5/X/X/X`a &6 & &N0 0 "00 0 0Im, }%,,Y7777 S S SNiNN1NNOOO}%,,i#a&&-Q-QRRRRRRRRS 	W----Ms;/?/?MMMNNN P P P0Q00111Q,NOOOOOOOOPsQ   AF: F: BDF: 
E5 AE0+F: 0E55AF: :
G=.G82G=8G=N)fastapir   r   pymilvusr   r   r   common_loggingr   sqlalchemy.ormr	   app.api.permissionsr
   app.db.sessionr   app.models.userr   __name__r0   routerr,   rE   r   r   r   <module>rO      sG   & & & & & & & & 5 5 5 5 5 5 5 5 5 5 % % % % % % " " " " " " , , , , , , ! ! ! ! ! !             % % % % % %	H			H			 O'&//M^@_@_8`8`+P +P+P15+P +P +P +P +P +Pr   