in experiments/legacy/backend/category.py [0:0]
def retrieve_and_rank(
desc: str,
image: Optional[str] = None,
base64: bool = False,
num_neighbors: int = config.NUM_NEIGHBORS,
filters: list[str] = []) -> list[list[str]]:
"""Wrapper function to sequence retrieve and rank functions.
Args:
desc: user provided description of product
image: can be local file path, GCS URI or base64 encoded image
base64: True indicates image is base64. False (default) will be
interpreted as image path (either local or GCS)
num_neigbhors: number of nearest neighbors to return for EACH embedding
filters: category prefix to restrict results to
Returns:
The candidates ranked by the LLM from most to least relevant. If there are
duplicate candidates the list is deduped prior to returning
"""
candidates = retrieve(desc, image, base64, num_neighbors, filters)
if filters and not candidates:
return [['ERROR: No existing products match that category']]
return rank(desc, [candidate['category'] for candidate in candidates])