Skip to content

Commit 3fad958

Browse files
author
Daniel Lorch
committed
chore: clarify distance
1 parent 3e6135a commit 3fad958

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

notebooks/examples/dynamic-few-shot-lambda/GENAIIDP-dynamic-few-shot.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

143146
def _s3vectors_find_similar_items_from_image(page_image):
144147
"""Search for similar items using image query"""

notebooks/examples/dynamic-few-shot-lambda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extraction:
117117
{
118118
"attributes_prompt": "Expected attributes are: invoice_number [Unique identifier], invoice_date [Invoice date], total_amount [Total amount]...",
119119
"class_prompt": "This is an example of the class 'invoice'",
120-
"distance": 0.892344521145,
120+
"distance": 0.122344521145, # lower is more similar
121121
"image_content": ["<base64_image_content_1>", "<base64_image_content_2>", ...]
122122
}
123123
]

0 commit comments

Comments
 (0)