Skip to content

fix(search): lower semantic-only trigram grounding floor to 0.3 - #165

Merged
LucasACH merged 1 commit into
mainfrom
fix/lower-semantic-trgm-grounding-threshold
Jun 22, 2026
Merged

LucasACH merged 1 commit into
mainfrom
fix/lower-semantic-trgm-grounding-threshold

Conversation

@LucasACH

Copy link
Copy Markdown
Owner

Why

The lexical-grounding anchor (SPEC §Ranking) requires a pure-semantic hit to share a trigram word_similarity ≥ threshold with the query. This vetoed genuinely relevant docs whose vocabulary differs from the query's surface words.

Concrete case (investigated live in prod): the query "identificar tipos de flores a partir de sus medidas" cleared the 0.84 semantic floor against "Estadística Bayesiana Aplicada - Penguins y Iris" (max cosine 0.8694) but was dropped because its peak trigram score was 0.322, just under the 0.40 floor — the document never uses the word "medidas" (it says masa/tamaño corporal). Meanwhile the project's own "BUSCASAM" doc, which quotes the example query verbatim, was the sole result via lexical match.

Change

Lower the prod-effective sources to 0.3:

  • infra/terraform/modules/app-vm/startup.sh (the line that writes the live .env)
  • infra/.env.example (doc)
  • infra/compose.yaml (default)

0.3 aligns with the existing fuzzy floor (FUZZY_WORD_SIMILARITY_THRESHOLD=0.3) and leaves margin over 0.322. A corpus check for that query at 0.3 admits only the target doc plus the pre-existing lexical hit — no flood.

Deploy status

  • Already applied live on buscasam-app via .env edit + api container recreate; verified GET /api/search now returns the Iris doc.
  • terraform apply run to persist the value into instance startup-script metadata (in-place metadata update, 0 to add, 1 to change, 0 to destroy — no VM reboot/recreate), so a future reboot won't revert to 0.4.
  • The code default in backend/src/buscasam/settings.py:61 is intentionally left at 0.4 (affects only dev/tests; changing it would shift the committed relevance-fixture sweep). Separate calibration if repo/prod defaults should align.

🤖 Generated with Claude Code

The lexical-grounding anchor (a pure-semantic hit must share a trigram
word_similarity >= threshold with the query) vetoed relevant docs whose
vocabulary differs from the query's surface words. Concretely, the query
"identificar tipos de flores a partir de sus medidas" cleared the 0.84
semantic floor against "Estadística Bayesiana Aplicada - Penguins y Iris"
(max cosine 0.8694) but was dropped because its peak trigram score was
0.322, just under the 0.40 floor — the doc never uses the word "medidas".

Lower the prod-effective sources (startup.sh-generated .env, plus the
.env.example doc and compose default) to 0.3, aligning with the existing
fuzzy floor and leaving margin. A corpus check for that query at 0.3
admits only the target doc plus the pre-existing lexical hit, no flood.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LucasACH
LucasACH requested a review from MarcosACH as a code owner June 18, 2026 17:18
@LucasACH
LucasACH merged commit 059d598 into main Jun 22, 2026
3 checks passed
@MarcosACH
MarcosACH deleted the fix/lower-semantic-trgm-grounding-threshold branch June 22, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants