mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-10 15:06:18 +00:00
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>
This commit is contained in:
parent
b338e492fc
commit
5272e42b0d
@ -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"]:
|
||||
|
Loading…
Reference in New Issue
Block a user