
    <i<                     t    S SK J r   S SKJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJr   " S S	5      rg
)    )copy)Iterableget_args)	BaseModel)model_fields_set)INFERENCE_OBJECT_TYPES)ModelSchemaParser)convert_paths	FieldPathc                       \ rS rSrSrSS\S-  SS4S jjrS\\   \-  S\	\
   4S jr SS	\S
\	\
   S-  S\S-  S\	\   4S jjr SS\S\S\	\
   S\S-  S\	\   4
S jjrSrg)InspectorEmbed   zInspector which collects paths to objects requiring inference in the received models

Attributes:
    parser: ModelSchemaParser instance
Nparserreturnc                 8    Uc  [        5       U l        g UU l        g N)r	   r   )selfr   s     ]/home/james-whalen/.local/lib/python3.13/site-packages/qdrant_client/embed/embed_inspector.py__init__InspectorEmbed.__init__   s    -3^')    pointsc                    / n[        U[        5      (       aF  U R                  R                  UR                  5        UR                  U R                  U5      5        O[        U[        5      (       a8  UR                  5        H#  nUR                  U R                  U5      5        M%     Oz[        U[        5      (       ae  U H_  n[        U[        5      (       d  M  U R                  R                  UR                  5        UR                  U R                  U5      5        Ma     [        [        U5      5      n[        U5      $ )zLooks for all the paths to objects requiring inference in the received models

Args:
    points: models to inspect

Returns:
    list of FieldPath objects
)
isinstancer   r   parse_model	__class__extend_inspect_modeldictvaluesinspectr   sortedsetr
   )r   r   pathsvaluepoints        r   r!   InspectorEmbed.inspect   s     fi((KK##F$4$45LL,,V45%%T\\%01 )))eY//KK++EOO<LL!4!4U!;<  
 s5z"U##r   modr$   accumc           	      ,   Uc:  U R                   R                  R                  UR                  R                  / 5      OUn/ nU HL  nUR                  U R                  XR                  UR                  (       a  UR                  O/ U5      5        MN     U$ )a  Looks for all the paths to objects requiring inference in the received model

Args:
    mod: model to inspect
    paths: list of paths to the fields possibly containing objects for inference
    accum: accumulator for the path. Path is a dot separated string of field names which we assemble recursively

Returns:
    list of paths to the model fields containing objects for inference
)	r   
path_cachegetr   __name__r   _inspect_inner_modelscurrenttail)r   r(   r$   r)   found_pathspaths         r   r   InspectorEmbed._inspect_model1   s}     KP-&&**3==+A+A2F]bD**DIItyy2u  r   original_modelcurrent_pathr0   c                   ^  / nUc  UnOUSU 3-  nS[         S[        S[        [           4U 4S jjn[        XS5      nUc  / $ [	        U[        [        5      5      (       a  U/$ [	        U[         5      (       ak  UR                  U" Xt5      5        U HL  nUR                  T R                  XxR                  UR                  (       a  UR                  O/ U5      5        MN     U$ [	        U[        5      (       a  U H`  n	[	        U	[         5      (       d  M  [	        U	[        [        5      5      (       a  UR                  U5        UR                  U" X5      5        Mb     U HV  nU HM  n	UR                  T R                  U	UR                  UR                  (       a  UR                  O/ U5      5        MO     MX     U$ [	        U[        5      (       a  / nUR                  5        H  u  p[	        U[        5      (       d  U/OUnU H`  n	[	        U	[         5      (       d  M  [	        U	[        [        5      5      (       a  UR                  U5        UR                  U" X5      5        Mb     U HV  nU HM  n	UR                  T R                  U	UR                  UR                  (       a  UR                  O/ U5      5        MO     MX     M     U$ )a  Looks for all the paths to objects requiring inference in the received model

Args:
    original_model: model to inspect
    current_path: the field to inspect on the current iteration
    tail: list of FieldPath objects to the fields possibly containing objects for inference
    accum: accumulator for the path. Path is a dot separated string of field names which we assemble recursively

Returns:
    list of paths to the model fields containing objects for inference
N.memberaccumulatorr   c                   > / n[        U 5       H`  nUTR                  R                  ;   d  M  TR                  R                  U   nUR                  TR                  R                  U   5        Mb     TR                  U [        U5      U5      $ )a%  Iterates over the set model fields, expand recursive ones and find paths to objects requiring inference

Args:
    member: currently inspected model, which may or may not contain recursive fields
    accumulator: accumulator for the path, which is a dot separated string assembled recursively
)r   r   name_recursive_ref_mappingr   r+   r   r   )r8   r9   recursive_pathsfieldmapped_fieldr   s        r   inspect_recursive?InspectorEmbed._inspect_inner_models.<locals>.inspect_recursivea   sx     !O)&1DKKBBB#';;#I#I%#PL#**4;;+A+A,+OP 2
 &&vtO/DkRRr   )r   strlistgetattrr   r   r   r   r.   r/   r0   appendr   items)r   r4   r5   r0   r)   r1   r?   model	next_pathcurrent_modelkeyr    s   `           r   r.   $InspectorEmbed._inspect_inner_modelsI   sw   $ = Eq''E	Si 	Sc 	Sd3i 	S d;=IeX&<=>>7NeY''0>?!	""..00INN)..XZ\a " t$$!&!-;;mX6L-MNN&&u-""#4]#JK "' "	%*M&&22)%--.7nnINN"!	 &+ " t$$K${{})3FD)A)A&v%+M%mY?? !-:P1QRR#**51&&'8'NO &, "&I)/#** 66 - ) 1 12;..	b %	 *0 "&  -* r   )r   r   )NN)r-   
__module____qualname____firstlineno____doc__r	   r   r   r   rB   r   r!   rA   r   r.   __static_attributes__ r   r   r   r      s    H047 H4 H$hy1I= $$y/ $6 Y]%))_t%;KNQU:	c: !g!g g 9o	g
 Tzg 
cg gr   r   N)r   typingr   r   pydanticr   qdrant_client._pydantic_compatr   qdrant_client.embed.commonr   !qdrant_client.embed.schema_parserr	   qdrant_client.embed.utilsr
   r   r   rP   r   r   <module>rW      s&     %  ; = ? >c cr   