fix(tokenize): drop Limit=1 in customer resolution scan
DynamoDB's `Limit` caps items scanned *before* the FilterExpression runs, so `scan(FilterExpression=name==X, Limit=1)` returns nothing when the first row scanned isn't the match. Worked with one seeded customer; adding a second (cust-0002) made 王小明 fail to resolve to a customer_id, so the RAG tool returned "token did not resolve" and the agent replied "no customer found". Remove the Limit; the small table is filtered in full. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -89,14 +89,17 @@ def _analyze(text, language="zh"):
|
|||||||
|
|
||||||
|
|
||||||
def _resolve_customer_id(name):
|
def _resolve_customer_id(name):
|
||||||
# Demo-grade name -> customer_id resolution (one seeded customer, so a scan is
|
# Demo-grade name -> customer_id resolution (small table, so a filtered scan is
|
||||||
# fine). Best effort: if it fails we still tokenize, just without a RAG link.
|
# fine). Best effort: if it fails we still tokenize, just without a RAG link.
|
||||||
|
# NOTE: no `Limit` -- in DynamoDB, Limit caps items *scanned* before the filter
|
||||||
|
# runs, so `Limit=1` returns nothing when the first row scanned isn't the match
|
||||||
|
# (broke once a 2nd customer existed). A GSI on `name` would be the prod fix.
|
||||||
if not CUSTOMERS:
|
if not CUSTOMERS:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
from boto3.dynamodb.conditions import Attr
|
from boto3.dynamodb.conditions import Attr
|
||||||
|
|
||||||
res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name), Limit=1)
|
res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name))
|
||||||
items = res.get("Items", [])
|
items = res.get("Items", [])
|
||||||
return items[0]["customer_id"] if items else None
|
return items[0]["customer_id"] if items else None
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user