@ -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 " ] :