One invalid extracted entity turns every entity in its chunk into Thing

Aperta Adatta ai principianti
#333 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
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

Inizia da src/selfgraph/extraction/extractor.py, in particolare da run() e dalla gestione di admit per entità in _assemble. Leggi il passaggio di estrazione e il flusso di convalida, quindi riproduci il problema con lo script fornito usando un’entità non valida. Il lavoro è completato quando le entità valide mantengono i tipi estratti, l’entità non valida viene eliminata con un avviso e la modalità schema rigorosa mantiene le entità e le relazioni ammissibili.

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

Descrizione

approved-for-pr area: extraction bug effort: S P2

What happens

insert.text with an LLM builds every EntityInput of the entities pass in one list comprehension. If one item fails validation (an empty or blank name or type, or an alias with a control, NUL, or surrogate character), the whole pass for that chunk becomes a single extraction_partial_failure warning. The relations pass then re-creates every name as the Thing fallback, so typed entities are stored under the wrong id.

With schema_mode="strict", the same chunk stores nothing: every thing:* entity and every relation on it is dropped as off-schema.

A later clean extraction of the same text writes person:ann next to the stray thing:ann.

Reproduce

On main (5a277c9), embedded Kuzu:

import asyncio, tempfile
from selfgraph import KuzuStore, SelfGraph

class LLM:
    def __init__(self, **replies):
        self.replies = replies

    async def generate(self, *, system, user, output):
        kind = next(iter(output.model_fields))
        return {kind: self.replies.get(kind, [])}

llm = LLM(
    entities=[
        {"type": "Person", "name": "Ann"},
        {"type": "Company", "name": "Acme"},
        {"type": "Person", "name": ""},
    ],
    relations=[{"from_name": "Ann", "type": "WORKS_AT", "to_name": "Acme"}],
)

async def main():
    with tempfile.TemporaryDirectory() as tmp:
        async with SelfGraph(store=KuzuStore(f"{tmp}/g.kuzu"), llm=llm) as g:
            r = await g.insert.text("Ann works at Acme.")
            print([e.id for e in r.entities])
            print([w.message for w in r.warnings])

asyncio.run(main())

Prints ['thing:ann', 'thing:acme']. Expected person:ann and company:acme, with one warning for the dropped empty-name entity. Replacing the empty name with "aliases": ["Acme\u0007Inc"] on the Acme item, or "type": " " on a third item, gives the same result.

Cause

src/selfgraph/extraction/extractor.py, in run(): return [EntityInput(type=e.type, name=e.name, aliases=e.aliases or []) for e in items] sits inside the per-pass try, so one item's ValidationError is caught as a failure of the whole call. _assemble already drops invalid entities one at a time through admit, but never gets the list.

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.