Skip to content

Commit

Permalink
Fixed pinecone.py _get_all method unordered return for ids and metada…
Browse files Browse the repository at this point in the history
…ta and used the fixed version inside _get_routes_with_ids
  • Loading branch information
Vits-99 committed Jul 11, 2024
1 parent caefb77 commit 4ffe29c
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions semantic_router/index/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,15 @@ def _get_route_ids(self, route_name: str):

def _get_routes_with_ids(self, route_name: str):
clean_route = clean_route_name(route_name)
ids, _ = self._get_all(prefix=f"{clean_route}#")
ids, metadata = self._get_all(prefix=f"{clean_route}#", include_metadata=True)
route_tuples = []
for id in ids:
res_meta = (
self.index.fetch(ids=[id], namespace=self.namespace)
if self.index
else {}
)
route_tuples.extend(
[
{
"id": id,
"route": x["metadata"]["sr_route"],
"utterance": x["metadata"]["sr_utterance"],
}
for x in res_meta["vectors"].values()
]
for id, data in zip(ids, metadata):
route_tuples.append(

Check warning on line 338 in semantic_router/index/pinecone.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/index/pinecone.py#L334-L338

Added lines #L334 - L338 were not covered by tests
{
"id": id,
"route": data["sr_route"],
"utterance": data["sr_utterance"],
}
)
return route_tuples

Check warning on line 345 in semantic_router/index/pinecone.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/index/pinecone.py#L345

Added line #L345 was not covered by tests

Expand Down Expand Up @@ -391,9 +383,14 @@ def _get_all(self, prefix: Optional[str] = None, include_metadata: bool = False)

# if we need metadata, we fetch it
if include_metadata:
res_meta = self.index.fetch(ids=vector_ids, namespace=self.namespace)
for id in vector_ids:
res_meta = (

Check warning on line 387 in semantic_router/index/pinecone.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/index/pinecone.py#L386-L387

Added lines #L386 - L387 were not covered by tests
self.index.fetch(ids=[id], namespace=self.namespace)
if self.index
else {}
)
metadata.extend([x["metadata"] for x in res_meta["vectors"].values()])

Check warning on line 392 in semantic_router/index/pinecone.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/index/pinecone.py#L392

Added line #L392 was not covered by tests
# extract metadata only
metadata.extend([x["metadata"] for x in res_meta["vectors"].values()])

# Check if there's a next page token; if not, break the loop
next_page_token = response_data.get("pagination", {}).get("next")
Expand Down

0 comments on commit 4ffe29c

Please sign in to comment.