Skip to content

Fix incremental indexing reprocessing and document state handling - #112

Open
huytg2610 wants to merge 2 commits into
HKUDS:mainfrom
huytg2610:codex/fix-incremental-indexing
Open

Fix incremental indexing reprocessing and document state handling#112
huytg2610 wants to merge 2 commits into
HKUDS:mainfrom
huytg2610:codex/fix-incremental-indexing

Conversation

@huytg2610

Copy link
Copy Markdown

Summary

  • Run entity extraction only for documents staged during the current insert.
  • Keep a document in PROCESSING until chunk/vector writes and entity extraction succeed; mark it FAILED with an error message if extraction fails.
  • Add regression tests for duplicate inserts and document status handling.

Why

The insertion pipeline rebuilt chunks from every PROCESSED document. Inserting an already-indexed document therefore reran entity extraction, and relationship weights could grow because edge merging accumulates weight. A duplicate insert now stages no document and makes no LLM extraction call.

Tests

  • pytest tests/test_incremental_indexing.py -q: 4 passed
  • py_compile for the changed source and test
  • git diff --check

Repository-wide test collection still needs optional PostgreSQL and Weaviate dependencies/services that are not present locally.

Accented scripts have more than one valid encoding of the same text: "ệ" is
either U+1EC7 or "e" + U+0323 + U+0302. Both render identically, so the
difference is invisible, but the strings compare unequal and hash differently.

That matters because these strings become identity keys:

  clean_text -> md5 -> doc_id      (minirag.py:446)
  clean_str  -> entity_name        -> graph node id
             -> md5 -> ent-<hash>  (vector id)

So the same document typed with a Vietnamese IME (NFC) and copied off the
macOS filesystem (NFD) produced two different doc_ids and was indexed twice,
and "PHÚ THỌ" written the two ways became two graph nodes that could never
merge — halving what a query could reach about one entity.

Pure-ASCII text has a single encoding, so NFC and NFD coincide and the bug
never fired for English. It is a no-op there, which is why it went unnoticed.

Normalise in clean_text and clean_str, the two funnels every such string
already passes through. Tests cover id stability across both forms, that
upper-casing before cleaning still converges (operate.py does this), and that
ASCII and the existing escape/control-character handling are unchanged.
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.

1 participant