Skip to content

fix: match inflected Polish in the fallback full-text search - #60

Merged
Irahan2 merged 3 commits into
mainfrom
fix/59-inflected-polish-fallback-recall
Sep 1, 2026
Merged

fix: match inflected Polish in the fallback full-text search#60
Irahan2 merged 3 commits into
mainfrom
fix/59-inflected-polish-fallback-recall

Conversation

@Irahan2

@Irahan2 Irahan2 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #59.

The entity_search index doesn't stem, so an oblique-case question never reached a nominative
title. build_lucene_query now also emits prefix and edit-distance clauses for tokens of 5
characters or more. For "Co się dzieje w semestrze zimowym?":

"semestrze zimowym"^2     exact phrase, unchanged
semestr*^0.5              prefix, catches "Semestr"
zimow*^0.5                prefix, catches "zimowy"
semestrze~1^0.3           edit distance, for endings the prefix trim misses
zimowym~1^0.3

The prefix trims 2 characters with a floor of 4, since Polish endings are mostly 1-3 chars. Short
tokens stay exact, a 3-char prefix matches half the graph. Both expansion boosts are below 1 so an
exact hit still outranks them.

Measured on a 33-node graph

  • all 5 oblique-case questions recover their node at rank 1
  • all 5 unrelated questions still return 0 rows, no precision regression
  • "Kiedy zaczyna się semestr letni?" returns Semestr letni, not Semestr zimowy
  • nominative query scores 10.306, the oblique form of the same question 1.384, so boost ordering
    holds

Also re-ran the #57 abstention checks against Neo4j 5.18 and they still pass.

One thing from the issue notes I'd push back on

The notes suggest tuning fallback_min_score up, since real hits were around 10 against a floor
of 0.5. After the expansion that isn't safe any more. A legitimate oblique-case hit scores about
1.4, because inflected matches are low-scoring by construction. A floor picked from nominative
scores would drop exactly the matches this change exists to recover.

So I left it at 0.5 and wrote the reason into graph_config.yaml and CLAUDE.md, so it doesn't get
raised later on the strength of the original note.

If a Polish analyzer ever ships in the deployed Neo4j build, configuring it at index creation is
the better fix and this expansion can go. That's noted in CLAUDE.md too.

Notes

  • Two existing tests compared the whole Lucene string, so they now assert the quoted clauses
    instead. Same coverage, just not brittle to the extra clauses.
  • Only the fallback path changes. Model-generated primary queries are untouched.

Closes #59. The entity_search index uses a non-stemming analyzer, so a question
in an oblique case never reached a title in the nominative: "semestrze zimowym"
did not find "Semestr zimowy". Polish inflects heavily, so this was a common
miss rather than an edge case.

build_lucene_query now also emits prefix and edit-distance clauses for tokens of
5 characters or more, at boosts of 0.5 and 0.3. "semestrze" becomes semestr*,
"zimowym" becomes zimow*. Short tokens stay exact, since a 3-character prefix
matches half the graph. Exact phrase clauses keep their length boost, so a true
nominative hit still outranks an inflected one.

Measured on a 33-node graph, all five oblique-case questions now recover their
node at rank 1, all five unrelated questions still return zero rows, and a
question about one of a similar pair ("semestr letni" against "semestr zimowy")
still ranks the right one first. Nominative scores 10.3 against 1.4 for the
oblique form of the same question, so the boost ordering holds.
…e string

Two tests compared build_lucene_query's full output, so the inflection
expansion broke them even though the phrase clauses they cared about were
unchanged. They now pull out the quoted clauses and assert on those.
The issue suggested tuning fallback_min_score upward, since observed real hits
scored around 10 against a floor of 0.5. Measuring after the inflection
expansion says the opposite: an oblique-case hit legitimately scores about 1.4
where the nominative form of the same question scores 10. A floor picked from
nominative scores would drop exactly the matches the expansion recovers, so it
stays at 0.5 and both the config and CLAUDE.md now say why.

Also replaces the "no Polish analyzer, inflected forms do not match" note with
what the expansion actually does, and keeps the pointer that configuring a
Polish analyzer at index creation would be the better fix if one ever ships.

@Dominik-Galus Dominik-Galus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Irahan2
Irahan2 added this pull request to the merge queue Sep 1, 2026
Merged via the queue into main with commit 22c9599 Sep 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallback full-text search doesn't match inflected Polish (no stemming)

2 participants