diff --git a/genai_4_dps_helper/milvus.py b/genai_4_dps_helper/milvus.py index 9d19106..c789355 100644 --- a/genai_4_dps_helper/milvus.py +++ b/genai_4_dps_helper/milvus.py @@ -41,19 +41,29 @@ def get_milvus_connection( ) -def print_milvus_search_results(search_results: List, entity_keys_to_show: List[str]): +def print_milvus_search_results( + search_results: List, + title_key: str, + entity_keys_to_show: List[str], + key_to_return: str = None, +) -> List[str]: """Prints the results of Milvus searches in a readable fashion Args: search_results (List): A List [] object returned from a mlivus collection search method + title_key (str): The attribute key you want to appear first in the printed string before a colon entity_keys_to_show (List[str]): Keys of attributes in the list object, this keys will be returned in the printed list + key_to_return (str): If not None then returns a list. The list contains all the values which correspond to this key. Defaults to None """ + ret_list: List[str] = [] for hits in search_results: print(hits.ids) print(hits.distances) for entity in hits: - entity_str = f"{entity.name}: " + entity_str = f"{getattr(entity,title_key)}: " entity_str += " ".join( [f"{getattr(entity, key)}" for key in entity_keys_to_show] ) + if key_to_return: + ret_list.append(getattr(entity, key_to_return)) print(entity_str) diff --git a/pyproject.toml b/pyproject.toml index 361cdf8..8c00dda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=73.0","ibm_watsonx_ai==1.1.6","pandas==2.1.4","pymilvus build-backend = "setuptools.build_meta" [project] name = "genai_4_dps_helper" -version = "0.0.9" +version = "0.0.10" authors = [ { name="Benjamin A. Janes", email="benjamin.janes@se.ibm.com" }, ]