Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Query with GRPC should return None when results are empty #261

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
69 changes: 34 additions & 35 deletions pinecone/grpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_sparse_values(sparse_values: dict):
return (
SparseValues(indices=sparse_values["indices"], values=sparse_values["values"])
if sparse_values
else SparseValues(indices=[], values=[])
else None
)


Expand All @@ -49,7 +49,7 @@ def parse_fetch_response(response: dict):
id=vec["id"],
values=vec["values"],
sparse_values=parse_sparse_values(vec.get("sparseValues")),
metadata=vec.get("metadata", None),
metadata=vec.get("metadata"),
_check_type=False,
)
vd[id] = v_obj
Expand All @@ -58,49 +58,48 @@ def parse_fetch_response(response: dict):


def parse_query_response(response: dict, unary_query: bool, _check_type: bool = False):
res = []

# TODO: consider deleting this deprecated case
for match in response.get("results", []):
namespace = match.get("namespace", "")
if unary_query:
m = []
if "matches" in match:
for item in match["matches"]:
sc = ScoredVector(
id=item["id"],
score=item.get("score", 0.0),
values=item.get("values", []),
sparse_values=parse_sparse_values(item.get("sparseValues")),
metadata=item.get("metadata", {}),
)
m.append(sc)
res.append(SingleQueryResults(matches=m, namespace=namespace))
for item in response.get("matches"):
sc = ScoredVector(
id=item["id"],
score=item.get("score"),
values=item.get("values"),
sparse_values=parse_sparse_values(item.get("sparseValues")),
metadata=item.get("metadata"),
_check_type=_check_type,
)
m.append(sc)

m = []
for item in response.get("matches", []):
sc = ScoredVector(
id=item["id"],
score=item.get("score", 0.0),
values=item.get("values", []),
sparse_values=parse_sparse_values(item.get("sparseValues")),
metadata=item.get("metadata", {}),
_check_type=_check_type,
)
m.append(sc)

if unary_query:
namespace = response.get("namespace", "")
matches = m
results = []
results = None
else:
namespace = ""
matches = []
# TODO: consider deleting this deprecated case
res = []
for match in response.get("results", []):
namespace = match.get("namespace", "")
m = []
if "matches" in match:
for item in match["matches"]:
sc = ScoredVector(
id=item["id"],
score=item.get("score"),
values=item.get("values"),
sparse_values=parse_sparse_values(item.get("sparseValues")),
metadata=item.get("metadata"),
_check_type=_check_type,
)
m.append(sc)
res.append(SingleQueryResults(matches=m, namespace=namespace))
namespace = None
matches = None
results = res

kw = QueryResponseKwargs(_check_type, namespace, matches, results)
kw_dict = kw._asdict()
kw_dict["_check_type"] = kw.check_type
return QueryResponse(**kw._asdict())
return QueryResponse(**kw_dict)


def parse_stats_response(response: dict):
Expand Down
Loading