Skip to content

Commit

Permalink
update print_milvus_search_results to have more paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Janes committed Aug 20, 2024
1 parent 05e906c commit 9c2d8dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions genai_4_dps_helper/milvus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
Expand Down

0 comments on commit 9c2d8dd

Please sign in to comment.