
    rOi<                     t    d dl m Z  d dl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mZ  G d d	      Zy
)    )copy)Iterableget_args)	BaseModel)model_fields_set)INFERENCE_OBJECT_TYPES)ModelSchemaParser)convert_paths	FieldPathc                       e Zd ZdZddedz  ddfdZdee   ez  dee	   fdZ
	 dded	ee	   dz  d
edz  dee   fdZ	 ddededee	   d
edz  dee   f
dZy)InspectorEmbedzInspector which collects paths to objects requiring inference in the received models

    Attributes:
        parser: ModelSchemaParser instance
    Nparserreturnc                 6    |t               | _        y || _        y N)r	   r   )selfr   s     j/volume1/homes/robertsu/coba/app/.venv/lib/python3.12/site-packages/qdrant_client/embed/embed_inspector.py__init__zInspectorEmbed.__init__   s    -3^')    pointsc                 V   g }t        |t              rF| j                  j                  |j                         |j                  | j                  |             nt        |t              r6|j                         D ]"  }|j                  | j                  |             $ nmt        |t              r]|D ]X  }t        |t              s| j                  j                  |j                         |j                  | j                  |             Z t        t        |            }t        |      S )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   z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           	         |:| j                   j                  j                  |j                  j                  g       n|}g }|D ]G  }|j                  | j                  ||j                  |j                  r|j                  ng |             I |S )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   zInspectorEmbed._inspect_model1   s     KP-&&**3==+A+A2F]bD**DIItyy2u  r   original_modelcurrent_pathr-   c                      g }||}n|d| z  }dt         dt        dt        t           f fd}t        ||d      }|g S t	        |t        t                    r|gS t	        |t               rf|j                   |||             |D ]G  }|j                   j                  ||j                  |j                  r|j                  ng |             I |S t	        |t              r|D ]U  }	t	        |	t               st	        |	t        t                    r|j                  |       |j                   ||	|             W |D ]N  }|D ]G  }	|j                   j                  |	|j                  |j                  r|j                  ng |             I P |S t	        |t              rg }|j                         D ]  \  }
}t	        |t              s|gn|}|D ]U  }	t	        |	t               st	        |	t        t                    r|j                  |       |j                   ||	|             W |D ]N  }|D ]G  }	|j                   j                  |	|j                  |j                  r|j                  ng |             I P  |S )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                    g }t        |       D ]\  }|j                  j                  v sj                  j                  |   }|j                  j                  j                  |          ^ j                  | t        |      |      S )aU  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   )r4   r5   recursive_pathsfieldmapped_fieldr   s        r   inspect_recursivez?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,   r-   appendr   items)r   r0   r1   r-   r&   r.   r;   model	next_pathcurrent_modelkeyr   s   `           r   r+   z$InspectorEmbed._inspect_inner_modelsI   sh   $ = Eq''E	Si 	Sc 	Sd3i 	S d;=IeX&<=>7NeY'0>?!	""..y00INN)..XZ\a " t$!&!-;mX6L-MN&&u-""#4]E#JK "' "	%*M&&22)%--.7nnINN"!	 &+ " t$K${{}V)3FD)A&v%+M%mY? !-:P1QR#**51&&'8'NO &, "&I)/#** 66 - ) 1 12;..	b %	 *0 "&  -* r   r   )NN)r*   
__module____qualname____doc__r	   r   r   r   r=   r   r   r<   r   r+    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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   rH   r   r   <module>rO      s&     %  ; = ? >c cr   