Promoted preference keys use the raw extracted type, so an alias splits one preference

Aperta
#359 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript
Ambito
backend, databases

Direzione di ricerca

Start with _assemble in src/selfgraph/extraction/extractor.py and its counterpart in typescript/src/extraction/extractor.ts; trace how extracted entity types are resolved against the schema and how the fallback type is checked. Reproduce the example with the Python snippet in the issue, then verify that alias and canonical type inputs yield one preference with key food and that fallback matching ignores case.

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

Descrizione

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

What happens

When an extracted relation such as Ann PREFERS Pizza points at a typed value, extraction turns it into a preference whose key is the value entity's type, lowercased, as the LLM wrote it. The type is not canonicalized first, so a schema alias gives a different key from its type name, and the same fact becomes two preferences with two ids. The entity itself is canonicalized correctly (food:pizza in both cases).

The fallback check is also case-sensitive: a value typed thing is treated as typed and promoted with key thing, while Thing is not promoted.

Reproduce

On main (5a277c9), embedded Kuzu:

import asyncio, tempfile
from selfgraph import KuzuStore, SelfGraph

class LLM:
    def __init__(self, food_type):
        self.food_type = food_type

    async def generate(self, *, system, user, output):
        kind = next(iter(output.model_fields))
        reply = {
            "entities": [{"type": "Person", "name": "Ann"}, {"type": self.food_type, "name": "Pizza"}],
            "relations": [{"from_name": "Ann", "type": "PREFERS", "to_name": "Pizza"}],
        }
        return {kind: reply.get(kind, [])}

SCHEMA = {"entities": [{"name": "Person"}, {"name": "Food", "aliases": ["dish"]}], "relations": []}

async def main():
    with tempfile.TemporaryDirectory() as tmp:
        llm = LLM("Food")
        async with SelfGraph(store=KuzuStore(f"{tmp}/g.kuzu"), llm=llm, schema=SCHEMA) as g:
            await g.insert.text("Ann prefers pizza.")
            llm.food_type = "dish"
            await g.insert.text("Ann prefers pizza.")
            print([(p.key, p.value_entity) for p in (await g.preferences.list()).items])

asyncio.run(main())

Prints [('food', 'food:pizza'), ('dish', 'food:pizza')]. Expected one preference with key food.

Cause

_assemble in src/selfgraph/extraction/extractor.py (key = value.type.lower(), value.type != _FALLBACK_TYPE) and the same lines in typescript/src/extraction/extractor.ts. Canonicalizing the type against the schema, and comparing the fallback type case-insensitively, would give one key.

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.