Skip to content
Snippets Groups Projects
Commit f3a52bd8 authored by James Briggs's avatar James Briggs
Browse files

fix: qdrant to handle empty index when getting utterances

parent 2c2de82a
No related branches found
No related tags found
No related merge requests found
...@@ -212,32 +212,36 @@ class QdrantIndex(BaseIndex): ...@@ -212,32 +212,36 @@ class QdrantIndex(BaseIndex):
results = [] results = []
next_offset = None next_offset = None
stop_scrolling = False stop_scrolling = False
while not stop_scrolling: try:
records, next_offset = self.client.scroll( while not stop_scrolling:
self.index_name, records, next_offset = self.client.scroll(
limit=SCROLL_SIZE, self.index_name,
offset=next_offset, limit=SCROLL_SIZE,
with_payload=True, offset=next_offset,
) with_payload=True,
stop_scrolling = next_offset is None or ( )
isinstance(next_offset, grpc.PointId) stop_scrolling = next_offset is None or (
and next_offset.num == 0 isinstance(next_offset, grpc.PointId)
and next_offset.uuid == "" and next_offset.num == 0
) and next_offset.uuid == ""
)
results.extend(records) results.extend(records)
route_tuples: List[ route_tuples: List[
Tuple[str, str, Optional[Dict[str, Any]], Dict[str, Any]] Tuple[str, str, Optional[Dict[str, Any]], Dict[str, Any]]
] = [ ] = [
( (
x.payload[SR_ROUTE_PAYLOAD_KEY], x.payload[SR_ROUTE_PAYLOAD_KEY],
x.payload[SR_UTTERANCE_PAYLOAD_KEY], x.payload[SR_UTTERANCE_PAYLOAD_KEY],
None, None,
{}, {},
) )
for x in results for x in results
] ]
except ValueError as e:
logger.warning(f"Index likely empty, error: {e}")
return []
return route_tuples return route_tuples
def delete(self, route_name: str): def delete(self, route_name: str):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment