Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

community: Add configurable text key for indexing and the retriever in Pinecone Hybrid Search #29697

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create_index(
ids: Optional[List[str]] = None,
metadatas: Optional[List[dict]] = None,
namespace: Optional[str] = None,
text_key: str = "context",
) -> None:
"""Create an index from a list of contexts.

Expand Down Expand Up @@ -69,7 +70,7 @@ def create_index(
)
# add context passages as metadata
meta = [
{"context": context, **metadata}
{text_key: context, **metadata}
for context, metadata in zip(context_batch, metadata_batch)
]

Expand Down Expand Up @@ -114,7 +115,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):
"""Alpha value for hybrid search."""
namespace: Optional[str] = None
"""Namespace value for index partition."""

text_key: str = "context"
model_config = ConfigDict(
arbitrary_types_allowed=True,
extra="forbid",
Expand All @@ -135,6 +136,7 @@ def add_texts(
ids=ids,
metadatas=metadatas,
namespace=namespace,
text_key=self.text_key,
)

@pre_init
Expand Down Expand Up @@ -174,7 +176,7 @@ def _get_relevant_documents(
)
final_result = []
for res in result["matches"]:
context = res["metadata"].pop("context")
context = res["metadata"].pop(self.text_key)
metadata = res["metadata"]
if "score" not in metadata and "score" in res:
metadata["score"] = res["score"]
Expand Down
Loading