Add namespace to pinecone hybrid search (#10677)

**Description:** 
  
Pinecone hybrid search is now limited to default namespace. There is no
option for the user to provide a namespace to partition an index, which
is one of the most important features of pinecone.
  
**Resource:** 
https://docs.pinecone.io/docs/namespaces

---------

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
pull/9894/head^2
Ahmad Bunni 1 year ago committed by GitHub
parent b338e492fc
commit 5272e42b0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,6 +28,7 @@ def create_index(
sparse_encoder: Any, sparse_encoder: Any,
ids: Optional[List[str]] = None, ids: Optional[List[str]] = None,
metadatas: Optional[List[dict]] = None, metadatas: Optional[List[dict]] = None,
namespace: Optional[str] = None,
) -> None: ) -> None:
"""Create an index from a list of contexts. """Create an index from a list of contexts.
@ -91,7 +92,7 @@ def create_index(
) )
# upload the documents to the new hybrid index # upload the documents to the new hybrid index
index.upsert(vectors) index.upsert(vectors, namespace=namespace)
class PineconeHybridSearchRetriever(BaseRetriever): class PineconeHybridSearchRetriever(BaseRetriever):
@ -108,6 +109,8 @@ class PineconeHybridSearchRetriever(BaseRetriever):
"""Number of documents to return.""" """Number of documents to return."""
alpha: float = 0.5 alpha: float = 0.5
"""Alpha value for hybrid search.""" """Alpha value for hybrid search."""
namespace: Optional[str] = None
"""Namespace value for index partition."""
class Config: class Config:
"""Configuration for this pydantic object.""" """Configuration for this pydantic object."""
@ -120,6 +123,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):
texts: List[str], texts: List[str],
ids: Optional[List[str]] = None, ids: Optional[List[str]] = None,
metadatas: Optional[List[dict]] = None, metadatas: Optional[List[dict]] = None,
namespace: Optional[str] = None,
) -> None: ) -> None:
create_index( create_index(
texts, texts,
@ -128,6 +132,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):
self.sparse_encoder, self.sparse_encoder,
ids=ids, ids=ids,
metadatas=metadatas, metadatas=metadatas,
namespace=namespace,
) )
@root_validator() @root_validator()
@ -162,6 +167,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):
sparse_vector=sparse_vec, sparse_vector=sparse_vec,
top_k=self.top_k, top_k=self.top_k,
include_metadata=True, include_metadata=True,
namespace=self.namespace,
) )
final_result = [] final_result = []
for res in result["matches"]: for res in result["matches"]:

Loading…
Cancel
Save