@ -54,6 +54,7 @@ class Pinecone(VectorStore):
self ,
self ,
texts : Iterable [ str ] ,
texts : Iterable [ str ] ,
metadatas : Optional [ List [ dict ] ] = None ,
metadatas : Optional [ List [ dict ] ] = None ,
ids : Optional [ List [ str ] ] = None ,
namespace : Optional [ str ] = None ,
namespace : Optional [ str ] = None ,
) - > List [ str ] :
) - > List [ str ] :
""" Run more texts through the embeddings and add to the vectorstore.
""" Run more texts through the embeddings and add to the vectorstore.
@ -61,6 +62,7 @@ class Pinecone(VectorStore):
Args :
Args :
texts : Iterable of strings to add to the vectorstore .
texts : Iterable of strings to add to the vectorstore .
metadatas : Optional list of metadatas associated with the texts .
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 .
namespace : Optional pinecone namespace to add the texts to .
Returns :
Returns :
@ -69,14 +71,12 @@ class Pinecone(VectorStore):
"""
"""
# Embed and create the documents
# Embed and create the documents
docs = [ ]
docs = [ ]
ids = [ ]
ids = ids or [ str ( uuid . uuid4 ( ) ) for _ in texts ]
for i , text in enumerate ( texts ) :
for i , text in enumerate ( texts ) :
id = str ( uuid . uuid4 ( ) )
embedding = self . _embedding_function ( text )
embedding = self . _embedding_function ( text )
metadata = metadatas [ i ] if metadatas else { }
metadata = metadatas [ i ] if metadatas else { }
metadata [ self . _text_key ] = text
metadata [ self . _text_key ] = text
docs . append ( ( id , embedding , metadata ) )
docs . append ( ( ids [ i ] , embedding , metadata ) )
ids . append ( id )
# upsert to Pinecone
# upsert to Pinecone
self . _index . upsert ( vectors = docs , namespace = namespace )
self . _index . upsert ( vectors = docs , namespace = namespace )
return ids
return ids
@ -153,6 +153,7 @@ class Pinecone(VectorStore):
texts : List [ str ] ,
texts : List [ str ] ,
embedding : Embeddings ,
embedding : Embeddings ,
metadatas : Optional [ List [ dict ] ] = None ,
metadatas : Optional [ List [ dict ] ] = None ,
ids : Optional [ List [ str ] ] = None ,
batch_size : int = 32 ,
batch_size : int = 32 ,
text_key : str = " text " ,
text_key : str = " text " ,
index_name : Optional [ str ] = None ,
index_name : Optional [ str ] = None ,
@ -197,7 +198,11 @@ class Pinecone(VectorStore):
i_end = min ( i + batch_size , len ( texts ) )
i_end = min ( i + batch_size , len ( texts ) )
# get batch of texts and ids
# get batch of texts and ids
lines_batch = texts [ i : i + batch_size ]
lines_batch = texts [ i : i + batch_size ]
ids_batch = [ str ( uuid . uuid4 ( ) ) for n in range ( i , i_end ) ]
# create ids if not provided
if ids :
ids_batch = ids [ i : i + batch_size ]
else :
ids_batch = [ str ( uuid . uuid4 ( ) ) for n in range ( i , i_end ) ]
# create embeddings
# create embeddings
embeds = embedding . embed_documents ( lines_batch )
embeds = embedding . embed_documents ( lines_batch )
# prep metadata and upsert batch
# prep metadata and upsert batch