feat: enhance OCR matching with fuzzy logic and refined AI prompt
AI Prompt Improvements: - Standardized Item name format: [size] type vendor connector part_number - Clear examples: '5m Patchcord LC-LC', '256GB SSD Samsung SAS', '128GB DDR4 Hynix' - OCR key format: uppercase, space-separated tokens, includes variations/abbreviations - Excludes diameter/mm measurements from Item field - Allows 'HP'/'HPE', 'DDR'/'DDR4', 'NVMe'/'NVME' variations in OCR keys OCR Matching Logic: - Implemented Levenshtein distance fuzzy matching (allows 1-2 char differences) - Priority 0: Exact OCR key match (1000pts) + fuzzy match fallback (800pts) - Priority 2: Part number exact (200pts) + fuzzy match (150pts) - Priority 3: Token-based with fuzzy tolerance (50pts exact, 30pts fuzzy) - Removes whitespace for comparison (e.g., 'LCLC' matches 'LC-LC') Resolves OCR identification failures from minor text variations.
This commit is contained in:
@@ -103,18 +103,27 @@ def startup_event():
|
||||
try:
|
||||
# Default AI Prompt from User Request
|
||||
default_prompt = (
|
||||
"identify and summarise the minimal necessary information for a quick description if item. "
|
||||
"I need the following output - <field name> : the result from you.\n"
|
||||
"For any field, do not add comments in parenthesis. \n\n"
|
||||
"Item: in three words type of this item\n"
|
||||
"Type: what type of item is, like \"spare parts\", \"consumables\", \"patch cords\" etc.\n"
|
||||
"Description: description (max 5 words)\n"
|
||||
"Category: category, if any\n"
|
||||
"Connector: connectors\n"
|
||||
"Size: size or length\n"
|
||||
"Color: color if useful\n"
|
||||
"PartNr: part number if any\n"
|
||||
"OCR: identification string for local OCR matching"
|
||||
"Extract hardware specifications with PRECISE formatting.\n"
|
||||
"For any field, do not add comments in parenthesis or measurement units in Item name.\n\n"
|
||||
"ITEM FIELD FORMAT (Critical):\n"
|
||||
"[<size_or_length>] <type> <vendor> <connector> <part_number>\n"
|
||||
" <size_or_length>: GB/TB for storage, meters for cables (e.g., '2m', '256GB', '2TB'). Omit diameter/mm measurements.\n"
|
||||
" <type>: DDR3/DDR4/DDR5/SSD/HDD/NVMe/SAS/SATA/Patchcord/Fiber/Cable/Transceiver etc.\n"
|
||||
" <vendor>: HP/HPE/Dell/Samsung/Cisco/Lenovo/Hynix etc.\n"
|
||||
" <connector>: RJ45/LC-LC/MPO/U.3/SATA/SAS/LC/ST etc. Omit if N/A.\n"
|
||||
" <part_number>: PN only if visible on label. Omit serial numbers.\n"
|
||||
"Examples: '5m Patchcord LC-LC' / '256GB SSD Samsung SAS' / '128GB DDR4 Hynix SK-234' / '2TB NVMe HP U.3'\n\n"
|
||||
"TYPE: Item asset class (DDR3/SSD/NVMe/Patchcord/SFP etc.)\n"
|
||||
"DESCRIPTION: Technical details max 5 words (e.g., 'High speed fiber optic cable'). Omit size/length here.\n"
|
||||
"CATEGORY: Broad ecosystem (Memory, Storage, Network, Cabling, etc.)\n"
|
||||
"CONNECTOR: Physical interface type (e.g., 'LC', 'RJ45', 'U.3')\n"
|
||||
"SIZE: Capacity or length ONLY (e.g., '256GB', '2m')\n"
|
||||
"COLOR: Physical color if distinguishing.\n"
|
||||
"PartNr: Part number only (no serial numbers)\n"
|
||||
"OCR: Robust matching key. Include: core type + vendor + key identifiers + common variations.\n"
|
||||
" Example for '5m Patchcord LC-LC': 'PATCHCORD 5M LC LC CAT6 FIBER'\n"
|
||||
" Include abbreviations: 'DDR4'/'DDR' or 'SSD'/'SSDS' or 'HP'/'HPE' or 'NVMe'/'NVME'\n"
|
||||
" Format: ALL UPPERCASE, space-separated tokens, NO special chars. Skip serial numbers."
|
||||
)
|
||||
|
||||
# Wrap in JSON instructions for reliable parsing
|
||||
|
||||
Reference in New Issue
Block a user