@@ -45,8 +45,8 @@ def lambda_handler(event, context):
4545
4646 Input event:
4747 {
48- "class_label": "<class_label>",
49- "document_text": "<document_text>",
48+ "class_label": "<class_label e.g. invoice >",
49+ "document_text": "<document_text e.g. plain text or markdown from section 1 (pages 1-3)... >",
5050 "image_content": ["<base64_image_content_1>", "<base64_image_content_2>", ...]
5151 }
5252
@@ -55,7 +55,7 @@ def lambda_handler(event, context):
5555 {
5656 "attributes_prompt": "expected attributes are: ...",
5757 "class_prompt": "This is an example of the class 'invoice'",
58- "distance": 0.892344521145 ,
58+ "distance": 0.122344521145 ,
5959 "image_content": ["<base64_image_content_1>", "<base64_image_content_2>", ...]
6060 }
6161 ]
@@ -138,7 +138,10 @@ def _s3vectors_find_similar_items(image_data):
138138 attributes = _extract_metadata (metadata , distance )
139139 result .append (attributes )
140140
141- return result
141+ # sort results by distance score (lowest to highest - lower is more similar)
142+ sorted_result = sorted (result , key = lambda example : example ['distance' ], reverse = False )
143+
144+ return sorted_result
142145
143146def _s3vectors_find_similar_items_from_image (page_image ):
144147 """Search for similar items using image query"""
0 commit comments