retrieve misses Greek words with ΐ or ΰ when case differs

Aperta Adatta ai principianti
#337 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript
Ambito
backend, search

Direzione di ricerca

Leggi _fold in src/selfgraph/retrieval.py e fold in typescript/src/retrieval.ts, poi controlla i test di retrieval e la descrizione della normalizzazione in docs/retrieval.md. Riproduci in entrambe le implementazioni la discrepanza greca tra maiuscole e minuscole e conferma che la correzione fa corrispondere la query e il testo memorizzato. Il lavoro è completato quando gli esempi greci indicati funzionano e le corrispondenze esistenti senza distinzione tra maiuscole e minuscole per i caratteri latini restano invariate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

approved-for-pr area: retrieval bug effort: S P3

retrieve is documented as matching without regard to case, but it misses Greek words that contain ΐ or ΰ (a letter with both dialytika and tonos) when the query and the entity differ in case. An entity named "Πρωτεΐνη" ("protein") is not seeded by "ΠΡΩΤΕΪ́ΝΗ", which is what "Πρωτεΐνη".upper() returns, and the reverse fails as well. Latin cases such as Paris/PARIS, Zoë/ZOË, and Straße/STRASSE work.

Tested at 5a277c9 (current main), Python 3.14, Kuzu 0.11.3, on macOS. The cause is in the token fold, not the store.

Reproduce
import asyncio, os, tempfile
from selfgraph import KuzuStore, SelfGraph

async def main():
    async with SelfGraph(store=KuzuStore(os.path.join(tempfile.mkdtemp(), "g.kuzu"))) as g:
        await g.entities.create("Πρωτεΐνη", "Concept", id="concept:protein")
        await g.entities.create("Paris", "Place", id="place:paris")
        for q in ["Πρωτεΐνη", "Πρωτεΐνη".upper(), "πρωτεΐνη", "PARIS"]:
            print(repr(q), [s.id for s in (await g.retrieve(q)).seeds])

asyncio.run(main())
'Πρωτεΐνη' ['concept:protein']
'ΠΡΩΤΕΪ́ΝΗ' []
'πρωτεΐνη' ['concept:protein']
'PARIS' ['place:paris']

Storing the entity as "ΠΡΩΤΕΪ́ΝΗ" and querying "πρωτεΐνη" also returns no seeds. The same happens with "Ταΐζω" and "ΤΑΪ́ΖΩ", and with any other word that has ΐ (U+0390) or ΰ (U+03B0).

Cause

_fold (src/selfgraph/retrieval.py:161) is normalize_text(text).casefold(): NFC first, then casefold. Casefolding does not keep text in NFC:

import unicodedata as u
lower, upper = "Πρωτεΐνη", "Πρωτεΐνη".upper()
fold = lambda t: u.normalize("NFC", t).casefold()
print(fold(lower) == fold(upper))                                     # False
print(u.normalize("NFC", fold(lower)) == u.normalize("NFC", fold(upper)))  # True

The lowercase ΐ (U+0390) folds to U+03B9 U+0308 U+0301. The uppercase form's NFC is Ϊ plus a combining tonos (U+03AA U+0301), which folds to U+03CA U+0301. The two are canonically equivalent but not byte-equal, so neither the BM25 terms nor the substring boost match.

docs/retrieval.md ("How it works", step 1) says the query is NFC-normalized and casefolded so that query and stored text compare in one form. Unicode's canonical caseless match needs one more normalization after the fold, NFC(casefold(NFC(x))) or the NFD equivalent.

The TypeScript fold (typescript/src/retrieval.ts:87-88) is casefold(normalizeText(text)), using the full case-folding table in typescript/src/internal/casefold.ts, so it gives the same tokens and misses the same matches.

Related: #312 has the same root (case mapping applied after normalization leaves non-NFC text), in entity_id.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.