
    BTh}                       d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZ d dl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 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+ er	  ejX                  e-      Z. ede      Z/ G d de      Z0 eddd       G d de0             Zy# e&$ r d dl'm#Z#m%Z% d dl(m!Z! Y aw xY w)    )annotationsN)TYPE_CHECKINGAnyCallableIterableListOptionalTupleTypeVar)
deprecated)Document)
Embeddings)batch_iterate)VectorStore)Pinecone)PineconeAsyncio)ApplyResult)Index)_IndexAsyncio)_Indexr   )DistanceStrategymaximal_marginal_relevanceVST)boundc                  L   e Zd ZU dZdZded<   dZded<   ddddej                  fddd	 	 	 	 	 	 	 	 	 	 	 	 	 d%d	Z	e
d&d
       Ze
d'd       Ze
d(d       Z	 	 	 	 	 d)dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZ	 	 	 	 	 d)dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ	 	 	 d,	 	 	 	 	 	 	 	 	 d-dZ	 	 	 d,	 	 	 	 	 	 	 	 	 d.dZdddd	 	 	 	 	 	 	 	 	 d/dZdddd	 	 	 	 	 	 	 	 	 d/dZ	 	 	 d,	 	 	 	 	 	 	 	 	 	 	 d0dZ	 	 	 d,	 	 	 	 	 	 	 	 	 	 	 d1dZd2dZed3d       Z	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7dZe	 d8dd	 	 	 	 	 	 	 d9d       Ze	 	 	 	 	 	 	 	 	 d:dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d;d        Ze	 	 	 	 	 	 	 	 d<dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d!       Z e	 	 	 d>	 	 	 	 	 	 	 	 	 	 	 d?d"       Z!	 	 	 	 d@	 	 	 	 	 	 	 	 	 	 	 dAd#Z"	 	 	 	 d@	 	 	 	 	 	 	 	 	 	 	 dAd$Z#y)BPineconeVectorStoreuo  Pinecone vector store integration.

    Setup:
        Install ``langchain-pinecone`` and set the environment variable ``PINECONE_API_KEY``.

        .. code-block:: bash

            pip install -qU langchain-pinecone
            export PINECONE_API_KEY = "your-pinecone-api-key"

    Key init args — indexing params:
        embedding: Embeddings
            Embedding function to use.

    Key init args — client params:
        index: Optional[Index]
            Index to use.


    # TODO: Replace with relevant init params.
    Instantiate:
        .. code-block:: python

            import time
            import os
            from pinecone import Pinecone, ServerlessSpec
            from langchain_pinecone import PineconeVectorStore
            from langchain_openai import OpenAIEmbeddings

            pc = Pinecone(api_key=os.environ.get("PINECONE_API_KEY"))

            index_name = "langchain-test-index"  # change if desired

            existing_indexes = [index_info["name"] for index_info in pc.list_indexes()]

            if index_name not in existing_indexes:
                pc.create_index(
                    name=index_name,
                    dimension=1536,
                    metric="cosine",
                    spec=ServerlessSpec(cloud="aws", region="us-east-1"),
                    deletion_protection="enabled",  # Defaults to "disabled"
                )
                while not pc.describe_index(index_name).status["ready"]:
                    time.sleep(1)

            index = pc.Index(index_name)
            vector_store = PineconeVectorStore(index=index, embedding=OpenAIEmbeddings())

    Add Documents:
        .. code-block:: python

            from langchain_core.documents import Document

            document_1 = Document(page_content="foo", metadata={"baz": "bar"})
            document_2 = Document(page_content="thud", metadata={"bar": "baz"})
            document_3 = Document(page_content="i will be deleted :(")

            documents = [document_1, document_2, document_3]
            ids = ["1", "2", "3"]
            vector_store.add_documents(documents=documents, ids=ids)

    Delete Documents:
        .. code-block:: python

            vector_store.delete(ids=["3"])

    Search:
        .. code-block:: python

            results = vector_store.similarity_search(query="thud",k=1)
            for doc in results:
                print(f"* {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            * thud [{'bar': 'baz'}]

    Search with filter:
        .. code-block:: python

            results = vector_store.similarity_search(query="thud",k=1,filter={"bar": "baz"})
            for doc in results:
                print(f"* {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            * thud [{'bar': 'baz'}]

    Search with score:
        .. code-block:: python

            results = vector_store.similarity_search_with_score(query="qux",k=1)
            for doc, score in results:
                print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            * [SIM=0.832268] foo [{'baz': 'bar'}]

    Async:
        .. code-block:: python

            # add documents
            # await vector_store.aadd_documents(documents=documents, ids=ids)

            # delete documents
            # await vector_store.adelete(ids=["3"])

            # search
            # results = vector_store.asimilarity_search(query="thud",k=1)

            # search with score
            results = await vector_store.asimilarity_search_with_score(query="qux",k=1)
            for doc,score in results:
                print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")

        .. code-block:: python

            * [SIM=0.832268] foo [{'baz': 'bar'}]

    Use as Retriever:
        .. code-block:: python

            retriever = vector_store.as_retriever(
                search_type="mmr",
                search_kwargs={"k": 1, "fetch_k": 2, "lambda_mult": 0.5},
            )
            retriever.invoke("thud")

        .. code-block:: python

            [Document(metadata={'bar': 'baz'}, page_content='thud')]

    NzOptional[_Index]_indexzOptional[_IndexAsyncio]_async_indextext)pinecone_api_key
index_namec               T   |t        d      || _        |t        d      || _        || _        || _        |rVt        |t              r|| _        n|| _        |j                  j                  | _        |j                  j                  | _        y |xs# t        j                  j!                  d      xs d}|st        d      || _        |xs# t        j                  j!                  d      xs d}	|	st        d      || _        t#        |d	      }
|
j%                  |	
      | _        y )NzEmbedding must be providedzText key must be providedPINECONE_API_KEY ziPinecone API key must be provided in either `pinecone_api_key` or `PINECONE_API_KEY` environment variablePINECONE_INDEX_NAMEziPinecone index name must be provided in either `index_name` or `PINECONE_INDEX_NAME` environment variable	langchainapi_key
source_tag)name)
ValueError
_embedding	_text_key
_namespacedistance_strategy
isinstancer   r   r   confighost_index_hostr(   _pinecone_api_keyosenvirongetPineconeClientr   )selfindex	embeddingtext_key	namespacer/   r    r!   r4   _index_nameclients              q/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_pinecone/vectorstores.py__init__zPineconeVectorStore.__init__   s&    9::#899!#!2%/$)!#$||00D%*\\%9%9D" !LBJJNN3E$FL"  % A  &7D"$S

7L(MSQSK D  &7D"#,=+VF ,,K,8DK    c                    | j                   Jt        | d      st        d      t        | j                  d      }|j                  | j                        S | j                   S )zGet synchronous index instance.r4   zNo Pinecone API key availabler&   r'   r2   )r   hasattrr+   r8   r4   r   r3   r9   r?   s     r@   r:   zPineconeVectorStore.index   s]     ;;4!45 !@AA#..;F <<T%5%5<66{{rB   c                    | j                   Gt        | j                  d      }|j                  | j                  j
                  j                        S | j                   S )z Get asynchronous index instance.r&   r'   rD   )r   PineconeAsyncioClientr4   IndexAsyncior:   r1   r2   rF   s     r@   async_indexzPineconeVectorStore.async_index   sW     $*..;F &&DJJ,=,=,B,B&CC   rB   c                    | j                   S )z/Access the query embedding object if available.)r,   r9   s    r@   
embeddingszPineconeVectorStore.embeddings  s     rB   )	id_prefixc               h   || j                   }t        |      }|xs+ |D 	cg c]  }	t        t        j                               ! c}	}|r|D 
cg c]  }
|dz   |
vr|dz   |
z   n|
 }}
|xs |D 	cg c]  }	i  c}	}t        ||      D ]  \  }}||| j                  <    t        dt        |      |      D ]j  }||||z    }||||z    }||||z    }| j                  j                  |      }t        t        |||            } | j                  j                  d||d| l |S c c}	w c c}
w c c}	w )a  Run more texts through the embeddings and add to the vectorstore.

        Upsert optimization is done by chunking the embeddings and upserting them.
        This is done to avoid memory issues and optimize using HTTP based embeddings.
        For OpenAI embeddings, use pool_threads>4 when constructing the pinecone.Index,
        embedding_chunk_size>1000 and batch_size~64 for best performance.
        Args:
            texts: Iterable of strings to add to the vectorstore.
            metadatas: Optional list of metadatas associated with the texts.
            ids: Optional list of ids to associate with the texts.
            namespace: Optional pinecone namespace to add the texts to.
            batch_size: Batch size to use when adding the texts to the vectorstore.
            embedding_chunk_size: Chunk size to use when embedding the texts.
            id_prefix: Optional string to use as an ID prefix when upserting vectors.

        Returns:
            List of ids from adding the texts into the vectorstore.

        #r   vectorsr=    )r.   liststruuiduuid4zipr-   rangelenr,   embed_documentsr:   upsert)r9   texts	metadatasidsr=   
batch_sizeembedding_chunk_sizerN   kwargs_idmetadatar   ichunk_texts	chunk_idschunk_metadatasrM   vector_tupless                      r@   	add_textszPineconeVectorStore.add_texts  sl   > IU77Ac$**,'7TWNP	Cr(A	C"$rIC  4e!4"!4	!)U3 	,NHd'+HT^^$	,
 q#e*&:; 
	AA(<$<=KA$8 89I'A0D,DEO88EJ Y
O!LMMDJJ %# 
	 
/ 8 "5s   $D%D*1	D/c          	     Z  K   || j                   }t        |      }|xs+ |D 	cg c]  }	t        t        j                               ! c}	}|r|D 
cg c]  }
|dz   |
vr|dz   |
z   n|
 }}
|xs |D 	cg c]  }	i  c}	}t        ||      D ]  \  }}||| j                  <    t        dt        |      |      D ]  }||||z    }||||z    }||||z    }| j                  j                  |       d{   }t        |||      }| j                  4 d{   }g }t        ||      D ](  } |j                  d||d|}|j                  |       * t        j                   |  d{    ddd      d{     |S c c}	w c c}
w c c}	w 7 7 |7 +7 # 1 d{  7  sw Y   xY ww)a  Asynchronously run more texts through the embeddings and add to the vectorstore.

        Upsert optimization is done by chunking the embeddings and upserting them.
        This is done to avoid memory issues and optimize using HTTP based embeddings.
        For OpenAI embeddings, use pool_threads>4 when constructing the pinecone.Index,
        embedding_chunk_size>1000 and batch_size~64 for best performance.
        Args:
            texts: Iterable of strings to add to the vectorstore.
            metadatas: Optional list of metadatas associated with the texts.
            ids: Optional list of ids to associate with the texts.
            namespace: Optional pinecone namespace to add the texts to.
            batch_size: Batch size to use when adding the texts to the vectorstore.
            embedding_chunk_size: Chunk size to use when embedding the texts.
            id_prefix: Optional string to use as an ID prefix when upserting vectors.

        Returns:
            List of ids from adding the texts into the vectorstore.

        NrP   r   rQ   rS   )r.   rT   rU   rV   rW   rX   r-   rY   rZ   r,   aembed_documentsrJ   r   r\   appendasynciogather)r9   r]   r^   r_   r=   r`   ra   rN   rb   rc   rd   re   r   rf   rg   rh   ri   rM   rj   idxtasksbatch_vector_tuplestasks                          r@   
aadd_textszPineconeVectorStore.aadd_textsI  s    > IU77Ac$**,'7TWNP	Cr(A	C"$rIC  4e!4"!4	!)U3 	,NHd'+HT^^$	, q#e*&:; 	-AA(<$<=KA$8 89I'A0D,DEO#??LLJ	:GM'' - -3+8]+S ''%3::  3"+ !D
 LL&' nne,,,- - -	-* 
? 8 "5 M- -- - - -s   "F+$E?	F+F)
F+3	F	<A5F+1F2!F+FF+AF&F'F+F+6F7F+F+FF+F(	FF(	$F+   c                ^    | j                  | j                  j                  |      |||      S )a  Return pinecone documents most similar to query, along with scores.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents most similar to the query and score for each
        kfilterr=   )&similarity_search_by_vector_with_scorer,   embed_queryr9   queryry   rz   r=   s        r@   similarity_search_with_scorez0PineconeVectorStore.similarity_search_with_score  s4    $ ::OO''.!Fi ; 
 	
rB   c                   K   | j                  | j                  j                  |       d{   |||       d{   S 7 7 w)a  Asynchronously return pinecone documents most similar to query, along with scores.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents most similar to the query and score for each
        Nrx   )'asimilarity_search_by_vector_with_scorer,   aembed_queryr}   s        r@   asimilarity_search_with_scorez1PineconeVectorStore.asimilarity_search_with_score  sM     $ AA??//66	 B 
 
 	
6
s   *AAAAAArx   c                  || j                   }g }| j                  j                  ||d||      }t        |t              rt        d      |d   D ]  }|d   }|j                  d      }	| j                  |v r@|j                  | j                        }
|d   }|j                  t        |	|
|      |f       gt        j                  d	| j                   d
        |S )zGReturn pinecone documents most similar to embedding, along with scores.Tvectortop_kinclude_metadatar=   rz   3Received asynchronous result from synchronous call.matchesre   rd   scorerd   page_contentre   Found document with no `` key. Skipping.)r.   r:   r~   r0   r   r+   r7   r-   poprn   r   loggerwarning)r9   r;   ry   rz   r=   docsresultsresre   rd   r   r   s               r@   r{   z:PineconeVectorStore.similarity_search_by_vector_with_score  s     I**""! # 
 g{+RSS9% 	C:HB~~)||DNN3G$JER .t~~.>>NO	 rB   c                 K   || j                   }g }| j                  4 d{   }|j                  ||d||       d{   }ddd      d{    d   D ]  }|d   }	|j                  d      }
| j                  |	v r@|	j                  | j                        }|d   }|j                  t        |
||	      |f       gt        j                  d	| j                   d
        |S 7 7 7 # 1 d{  7  sw Y   xY ww)zVReturn pinecone documents most similar to embedding, along with scores asynchronously.NTr   r   re   rd   r   r   r   r   )
r.   rJ   r~   r7   r-   r   rn   r   r   r   )r9   r;   ry   rz   r=   r   rq   r   r   re   rd   r   r   s                r@   r   z;PineconeVectorStore.asimilarity_search_by_vector_with_score  s     I## 	 	sII !%# &  G	 	 9% 	C:HB~~)||DNN3G$JER .t~~.>>NO	 -		 	 	 	sW   !DC)DC/C+C/DC-BD+C/-D/D5C86D=Dc                f     | j                   |f|||d|}|D cg c]  \  }}|	 c}}S c c}}w )a  Return pinecone documents most similar to query.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents most similar to the query and score for each
        rx   )r   	r9   r~   ry   rz   r=   rb   docs_and_scoresdocrc   s	            r@   similarity_searchz%PineconeVectorStore.similarity_search  sG    & <$;;
v
>D
 #22Q222s   -c                   K    | j                   |f|||d| d {   }|D cg c]  \  }}|	 c}}S 7 c c}}w w)Nrx   )r   r   s	            r@   asimilarity_searchz&PineconeVectorStore.asimilarity_search  sX      !C B B!
v!
>D!
 
 #22Q22
 3s   ?7	?9??c                   | j                   t        j                  k(  r| j                  S | j                   t        j                  k(  r| j
                  S | j                   t        j                  k(  r| j                  S t        d      )a8  
        The 'correct' relevance function
        may differ depending on a few things, including:
        - the distance / similarity metric used by the VectorStore
        - the scale of your embeddings (OpenAI's are unit normed. Many others are not!)
        - embedding dimensionality
        - etc.
        zXUnknown distance strategy, must be cosine, max_inner_product (dot product), or euclidean)	r/   r   COSINE_cosine_relevance_score_fnMAX_INNER_PRODUCT%_max_inner_product_relevance_score_fnEUCLIDEAN_DISTANCE_euclidean_relevance_score_fnr+   rL   s    r@   _select_relevance_score_fnz.PineconeVectorStore._select_relevance_score_fn,  sy     !!%5%<%<<222##'7'I'II===##'7'J'JJ555. rB   c                    | dz   dz  S )z8Pinecone returns cosine similarity scores between [-1,1]      rS   )r   s    r@   r   z.PineconeVectorStore._cosine_relevance_score_fnB  s     	QrB   c                   || j                   }| j                  j                  ||dd||      }t        |t              rt        d      t        t        j                  |gt        j                        |d   D 	cg c]  }	|	d   	 c}	||      }
|
D cg c]  }|d   |   d    }}|D cg c](  }t        |j                  | j                        |	      * c}S c c}	w c c}w c c}w )
a  Return docs selected using the maximal marginal relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult: Number between 0 and 1 that determines the degree
                        of diversity among the results with 0 corresponding
                        to maximum diversity and 1 to minimum diversity.
                        Defaults to 0.5.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents selected by maximal marginal relevance.
        Tr   r   include_valuesr   r=   rz   r   dtyper   valuesry   lambda_multre   r   re   )r.   r:   r~   r0   r   r+   r   nparrayfloat32r   r   r-   )r9   r;   ry   fetch_kr   rz   r=   rb   r   itemmmr_selectedrf   selectedre   s                 r@   'max_marginal_relevance_search_by_vectorz;PineconeVectorStore.max_marginal_relevance_search_by_vectorG  s    : I**""! # 
 g{+RSS1HHi[

3(/	(:;T(^;#	
 @LL!GI&q)*5LL %
 (,,"@8T
 	
 < M
s   <C
C#.-C(c           	     (  K   || j                   }| j                  4 d{   }|j                  ||dd||       d{   }	ddd      d{    t        t	        j
                  |gt        j                        	d   D 
cg c]  }
|
d   	 c}
||      }|D cg c]  }|	d   |   d    }}|D cg c](  }t        |j                  | j                        |	      * c}S 7 7 7 # 1 d{  7  sw Y   xY wc c}
w c c}w c c}w w)
a  Return docs selected using the maximal marginal relevance asynchronously.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult: Number between 0 and 1 that determines the degree
                        of diversity among the results with 0 corresponding
                        to maximum diversity and 1 to minimum diversity.
                        Defaults to 0.5.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents selected by maximal marginal relevance.
        NTr   r   r   r   r   re   r   )
r.   rJ   r~   r   r   r   r   r   r   r-   )r9   r;   ry   r   r   rz   r=   rb   rq   r   r   r   rf   r   re   s                  r@   (amax_marginal_relevance_search_by_vectorz<PineconeVectorStore.amax_marginal_relevance_search_by_vector|  s%    : I## 	 	sII #!%# &  G	 	 2HHi[

3(/	(:;T(^;#	
 @LL!GI&q)*5LL %
 (,,t~~">R
 	
#		 	 	 	 < M
sz   DC(DC. C*C.DC,5DD
D D2D8-D%D*C.,D.D 4C75D <Dc                d    | j                   j                  |      }| j                  ||||||      S )a  Return docs selected using the maximal marginal relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult: Number between 0 and 1 that determines the degree
                        of diversity among the results with 0 corresponding
                        to maximum diversity and 1 to minimum diversity.
                        Defaults to 0.5.
            filter: Dictionary of argument(s) to filter on metadata
            namespace: Namespace to search in. Default will search in '' namespace.

        Returns:
            List of Documents selected by maximal marginal relevance.
        )r,   r|   r   	r9   r~   ry   r   r   rz   r=   rb   r;   s	            r@   max_marginal_relevance_searchz1PineconeVectorStore.max_marginal_relevance_search  s8    : OO//6	;;q';	
 	
rB   c                   K   | j                   j                  |       d {   }| j                  ||||||       d {   S 7 #7 w)N)ry   r   r   rz   r=   )r,   r   r   r   s	            r@   amax_marginal_relevance_searchz2PineconeVectorStore.amax_marginal_relevance_search  sZ      //66u==	BB# C 
 
 	
 >
s!   A	AA	 AA	A	)r    c                  |xs# t         j                  j                  d      xs d}t        ||d      }|j	                         }|j
                  d   D cg c]  }|j                   }}|r||v r|j                  |      }	|	S t        |      dk(  rt        d      t        d| d	d
j                  |             c c}w )a  Return a Pinecone Index instance.

        Args:
            index_name: Name of the index to use.
            pool_threads: Number of threads to use for index upsert.
            pinecone_api_key: The api_key of Pinecone.
        Returns:
            Pinecone Index instance.r#   r$   r&   )r(   pool_threadsr)   indexesr   zNo active indexes found in your Pinecone project, are you sure you're using the right Pinecone API key and Environment? Please double check your Pinecone dashboard.zIndex 'zQ' not found in your Pinecone project. Did you mean one of the following indexes: z, )r5   r6   r7   r8   list_indexes
index_listr*   r   rZ   r+   join)
clsr!   r   r    r4   r?   r   rf   index_namesr:   s
             r@   get_pinecone_indexz&PineconeVectorStore.get_pinecone_index  s      -X

?Q0RXVX%L[
 %%''.'9'9)'DE!qvvEE*3LL,E  "?  * &>>Bii>T=UW  Fs   B>c          
     ~    | j                  ||
      } | ||||fi |} |j                  |f||||||d|	xs i  |S )a  Construct Pinecone wrapper from raw documents.

        This is a user-friendly interface that:
            1. Embeds documents.
            2. Adds the documents to a provided Pinecone index

        This is intended to be a quick way to get started.

        The `pool_threads` affects the speed of the upsert operations.

        Setup: set the `PINECONE_API_KEY` environment variable to your Pinecone API key.

        Example:
            .. code-block:: python

                from langchain_pinecone import PineconeVectorStore, PineconeEmbeddings

                embeddings = PineconeEmbeddings(model="multilingual-e5-large")

                index_name = "my-index"
                vectorstore = PineconeVectorStore.from_texts(
                    texts,
                    index_name=index_name,
                    embedding=embedding,
                    namespace=namespace,
                )
        r^   r_   r=   r`   ra   rN   )r   rk   )r   r]   r;   r^   r_   r`   r<   r=   r!   upsert_kwargsr   embeddings_chunk_sizerN   rb   pinecone_indexpinecones                   r@   
from_textszPineconeVectorStore.from_texts  sl    Z //
LI~y(IPP		
!!6		
 "		
 rB   c          
     x   K    | d||||d|} |j                   |f|||||
|d|	xs i  d {    |S 7 w)N)r!   r;   r<   r=   r   rS   )ru   )r   r]   r;   r^   r_   r`   r<   r=   r!   r   r   rN   rb   r   s                 r@   afrom_textszPineconeVectorStore.afrom_textsJ  s~     "  
!	

 
 "h!!	
!!6	
 "	
 		
 		
 		
s   /:8:c                <    | j                  ||      } | ||||      S )z*Load pinecone vectorstore from index name.)r   )r   r!   r;   r<   r=   r   r   s          r@   from_existing_indexz'PineconeVectorStore.from_existing_indexp  s'     //
LI>9h	BBrB   c                J   || j                   }|r  | j                  j                  d	d|d| y|Ed}t        dt	        |      |      D ])  }||||z    } | j                  j                  d	||d| + y|  | j                  j                  d	||d| yt        d      )
a=  Delete by vector IDs or filter.
        Args:
            ids: List of ids to delete.
            delete_all: Whether delete all vectors in the index.
            filter: Dictionary of conditions to filter vectors to delete.
            namespace: Namespace to search in. Default will search in '' namespace.
        NT
delete_allr=     r   r_   r=   rz   r=   3Either ids, delete_all, or filter must be provided.rS   )r.   r:   deleterY   rZ   r+   )	r9   r_   r   r=   rz   rb   
chunk_sizerf   chunks	            r@   r   zPineconeVectorStore.delete}  s      IDJJMMfM  _J1c#h
3 LAJ/!

!!KeyKFKL  DJJKVyKFK  RSSrB   c           
       K   || j                   }|rC| j                  4 d {   } |j                  dd|d| d {    d d d       d {    y |d}| j                  4 d {   }g }t        dt	        |      |      D ].  }	||	|	|z    }
|j                   |j                  d|
|d|       0 t        j                  |  d {    d d d       d {    y |C| j                  4 d {   } |j                  d||d| d {    d d d       d {    y t        d      7 7 7 # 1 d {  7  sw Y   y xY w7 7 7 u# 1 d {  7  sw Y   y xY w7 t7 Y7 K# 1 d {  7  sw Y   y xY ww)	NTr   r   r   r   r   r   rS   )	r.   rJ   r   rY   rZ   rn   ro   rp   r+   )r9   r_   r   r=   rz   rb   rq   r   rr   rf   r   s              r@   adeletezPineconeVectorStore.adelete  s     I'' Q Q3 cjjPDIPPPPQ Q   _J'' - -3q#c(J7 WAA
N3ELL!U!Uf!UVW nne,,,- -  '' O O3 cjjN)NvNNNO O
  RSSQPQ Q Q Q  -
 -- - - - ONO O O O
 s   !FD3FD: D6D:FD8F*E+F.AEEEFEF5E*6F9E0E,E0F"E.#F6D:8F:E EEFEFE'EE'#F,E0.F0F6E97F>F)r:   zOptional[Any]r;   Optional[Embeddings]r<   Optional[str]r=   r   r/   zOptional[DistanceStrategy]r    r   r!   r   )returnr   )r   r   )r   r   )NNN    r   )r]   Iterable[str]r^   Optional[List[dict]]r_   Optional[List[str]]r=   r   r`   intra   r   rN   r   rb   r   r   	List[str])r]   r   r^   r   r_   r   r=   r   r`   r   ra   r   rN   r   rb   r   r   z	list[str])rv   NN)
r~   rU   ry   r   rz   Optional[dict]r=   r   r   List[Tuple[Document, float]])
r~   rU   ry   r   rz   r   r=   r   r   zlist[tuple[Document, float]])
r;   List[float]ry   r   rz   r   r=   r   r   r   )r~   rU   ry   r   rz   r   r=   r   rb   r   r   List[Document])r~   rU   ry   r   rz   r   r=   r   rb   r   r   list[Document])r   zCallable[[float], float])r   floatr   r   )rv      g      ?NN)r;   r   ry   r   r   r   r   r   rz   r   r=   r   rb   r   r   r   )r~   rU   ry   r   r   r   r   r   rz   r   r=   r   rb   r   r   r   )r~   rU   ry   r   r   r   r   r   rz   r   r=   r   rb   r   r   r   )rv   )r!   r   r   r   r    r   r   r   )	NNr   r   NNNrv   r   )r]   r   r;   r   r^   r   r_   r   r`   r   r<   rU   r=   r   r!   r   r   r   r   r   r   r   rN   r   rb   r   r   r   )NNr   r   NNNr   )r   ztype[PineconeVectorStore]r]   r   r;   r   r^   r   r_   r   r`   r   r<   rU   r=   r   r!   r   r   r   r   r   rN   r   rb   r   r   r   )r   Nrv   )r!   rU   r;   r   r<   rU   r=   r   r   r   r   r   )NNNN)r_   r   r   zOptional[bool]r=   r   rz   r   rb   r   r   None)$__name__
__module____qualname____doc__r   __annotations__r   r   r   rA   propertyr:   rJ   rM   rk   ru   r   r   r{   r   r   r   r   staticmethodr   r   r   r   r   classmethodr   r   r   r   r   r   rS   rB   r@   r   r   .   s   FP  $F#,0L)0  $*."(#'8H8O8O69 +/$(69 69 (69  69 !69 669 (69 "69p 	 	 ! !   +/#'#'$(: $(:: (: !	:
 !: : ": !: : 
:~ +/#'#'$(B $(BB (B !	B
 !B B "B !B B 
BN !%#'

 
 	

 !
 
&
2 !%#'

 
 	

 !
 
&
: !%#'$$ 	$
 $ !$ 
&$T !%#'## 	#
 # !# 
&#P !%#'33 3 	3
 !3 3 
36 !%#'33 3 	3
 !3 3 
3,    !%#'3
3
 3
 	3

 3
 3
 !3
 3
 
3
p  !%#'4
4
 4
 	4

 4
 4
 !4
 4
 
4
r  !%#' 
 
  
 	 

  
  
 ! 
  
 
 
J  !%#'

 
 	

 
 
 !
 
 

(  #
 +/#!# #
 (# 
# #J 
 +/#'#'$((,%)9 $(99 9 (	9
 !9 9 9 !9 "9 &9 9  #9 !9 9  
!9 9v 
 +/#'#'$((,%)# $(#&## # (	#
 !# # # !# "# &#  ## !# # 
# #J 
 #'
C
C 
C 	
C
 !
C 
C 

C 
C $(%)#'!%  # !	
   
F $(%)#'!%  # !	
   
rB   r   z0.0.3z1.0.0)sinceremovalalternativec                      e Zd ZdZy)r   z,Deprecated. Use PineconeVectorStore instead.N)r   r   r   r   rS   rB   r@   r   r     s    6rB   r   )1
__future__r   ro   loggingr5   rV   typingr   r   r   r   r   r	   r
   r   numpyr   langchain_core._api.deprecationr   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.utils.iterr   langchain_core.vectorstoresr   r   r   r8   r   rH   pinecone.db_data.indexr   r   r   pinecone.db_data.index_asyncior   ImportErrorpinecone.datapinecone.data.indexlangchain_pinecone._utilitiesr   r   	getLoggerr   r   r   r   rS   rB   r@   <module>r     s    "   	 	 	 	  6 - 0 3 3 / =026<
 W			8	$e;'L+ L^ '78MN	" 	 O	}  03/0s   B8 8CC