
    hhK                     \    d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
  G d de
e	          ZdS )0Simple in memory docstore in the form of a dict.    )DictListOptionalUnion)Document)AddableMixinDocstorec                       e Zd ZdZddeeeef                  fdZdeeef         ddfdZ	de
ddfd	Zd
edeeef         fdZdS )InMemoryDocstorer   N_dictc                     ||ni | _         dS )zInitialize with dict.Nr   )selfr   s     c/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_community/docstore/in_memory.py__init__zInMemoryDocstore.__init__   s    #/UUR


    textsreturnc                     t          |                              | j                  }|rt          d|           i | j        || _        dS )zAdd texts to in memory dictionary.

        Args:
            texts: dictionary of id -> document.

        Returns:
            None
        z%Tried to add ids that already exist: N)setintersectionr   
ValueError)r   r   overlappings      r   addzInMemoryDocstore.add   sV     %jj--dj99 	TR[RRSSS,
,e,


r   idsc                     t          |                              | j                  }|st          d|           |D ]}| j                            |           dS )z'Deleting IDs from in memory dictionary.z*Tried to delete ids that does not  exist: N)r   r   r   r   pop)r   r   r   _ids       r   deletezInMemoryDocstore.delete   sm    #hh++DJ77 	QO#OOPPP 	  	 CJNN3	  	 r   searchc                 :    || j         vrd| dS | j         |         S )zSearch via direct lookup.

        Args:
            search: id of a document to search for.

        Returns:
            Document if found, else error message.
        zID z not found.r   )r   r!   s     r   r!   zInMemoryDocstore.search'   s/     ##,,,,,:f%%r   )N)__name__
__module____qualname____doc__r   r   strr   r   r   r   r    r   r!    r   r   r   r   
   s        ::8 8htCM':; 8 8 8 8-c8m, - - - - - $  4        &S &U3=%9 & & & & & &r   r   N)r&   typingr   r   r   r   langchain_core.documentsr   !langchain_community.docstore.baser	   r
   r   r(   r   r   <module>r,      s    6 6 . . . . . . . . . . . . - - - - - - D D D D D D D D)& )& )& )& )&x )& )& )& )& )&r   