mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 06:14:37 +00:00
Harrison/namespace pinecone (#581)
Co-authored-by: mmorzywolek <89693033+mmorzywolek@users.noreply.github.com>
This commit is contained in:
parent
ffc7e04d44
commit
5ba46f6d0c
@ -91,6 +91,7 @@ class Pinecone(VectorStore):
|
||||
batch_size: int = 32,
|
||||
text_key: str = "text",
|
||||
index_name: Optional[str] = None,
|
||||
namespace: Optional[str] = None,
|
||||
**kwargs: Any,
|
||||
) -> Pinecone:
|
||||
"""Construct Pinecone wrapper from raw documents.
|
||||
@ -121,7 +122,11 @@ class Pinecone(VectorStore):
|
||||
"Please install it with `pip install pinecone-client`."
|
||||
)
|
||||
_index_name = index_name or str(uuid.uuid4())
|
||||
index = None
|
||||
indexes = pinecone.list_indexes() # checks if provided index exists
|
||||
if _index_name in indexes:
|
||||
index = pinecone.Index(_index_name)
|
||||
else:
|
||||
index = None
|
||||
for i in range(0, len(texts), batch_size):
|
||||
# set end position of batch
|
||||
i_end = min(i + batch_size, len(texts))
|
||||
@ -143,5 +148,5 @@ class Pinecone(VectorStore):
|
||||
pinecone.create_index(_index_name, dimension=len(embeds[0]))
|
||||
index = pinecone.Index(_index_name)
|
||||
# upsert to Pinecone
|
||||
index.upsert(vectors=list(to_upsert))
|
||||
index.upsert(vectors=list(to_upsert), namespace=namespace)
|
||||
return cls(index, embedding.embed_query, text_key)
|
||||
|
Loading…
Reference in New Issue
Block a user