The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Add namespace to pinecone hybrid search (#10677)
Ahmad Bunni5272e42b0de2
diff --git a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.pyindex 068a5a53c1..7b41616fef 100644--- a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py+++ b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py@@ -28,6 +28,7 @@ def create_index(sparse_encoder: Any,ids: Optional[List[str]] = None,metadatas: Optional[List[dict]] = None,+ namespace: Optional[str] = None,) -> None:"""Create an index from a list of contexts.@@ -91,7 +92,7 @@ def create_index()# upload the documents to the new hybrid index- index.upsert(vectors)+ index.upsert(vectors, namespace=namespace)class PineconeHybridSearchRetriever(BaseRetriever):@@ -108,6 +109,8 @@ class PineconeHybridSearchRetriever(BaseRetriever):"""Number of documents to return."""alpha: float = 0.5"""Alpha value for hybrid search."""+ namespace: Optional[str] = None+ """Namespace value for index partition."""class Config:"""Configuration for this pydantic object."""@@ -120,6 +123,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):texts: List[str],ids: Optional[List[str]] = None,metadatas: Optional[List[dict]] = None,+ namespace: Optional[str] = None,) -> None:create_index(texts,@@ -128,6 +132,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):self.sparse_encoder,ids=ids,metadatas=metadatas,+ namespace=namespace,)@root_validator()@@ -162,6 +167,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):sparse_vector=sparse_vec,top_k=self.top_k,include_metadata=True,+ namespace=self.namespace,)final_result = []for res in result["matches"]: