Repository navigation
Conversation
VANDRANKI
left a comment
There was a problem hiding this comment.
Community review (does not clear the merge gate). I read the diff and the surrounding KeywordTable dataclass in data_structs.py. llama_index is not installed in my environment, so I did not run the new tests. I ran the underlying Python expression instead.
Verified: set.union(*{}.values()) raises TypeError: unbound method set.union() needs an argument, and set().union(*{}.values()) returns set(). So KeywordTable.node_ids raises on an empty table, and the one-line change fixes it. An empty table happens after the last node is deleted: _delete_node in indices/keyword_table/base.py removes keywords whose node set is empty, so the table can legitimately become {}, and the same applies to a freshly loaded persisted empty index. Both are in your parametrized test.
Notes:
set.union(a, b)andset().union(a, b)both return a new set, so callers still cannot mutate the table through the returned value. Your second test (node_ids.clear()leaves the table alone) locks that in, which is a nice guard against a future "optimization" that returns the stored set for a single-keyword table.- I searched the repo for other
set.union(*uses inllama-index-coreand found only this one, so there are no sibling instances of the bug. - Only
data_structs.pyand tests reference.node_idson this struct in core as far as my code search showed. I did not check the integration packages, so downstream callers that relied on theTypeError(unlikely) are unchecked. - Test imports
load_index_from_storageandStorageContextat module top. The persisted case writes intotmp_path, which is fine.
Looks correct and minimal to me. I would be comfortable with this merging once CI is green.
Description
Reading
KeywordTable.node_idsraises aTypeErrorwhen the table is empty. This happens with a new emptySimpleKeywordTableIndex, after deleting its last node, and after saving and reloading either state.Start the union from an empty set so these cases return
set(). Populated tables still return the distinct node IDs in a separate set. No new dependencies.Fixes #23359
New Package?
Version Bump?
llama-index-core, which is exempt.Type of Change
How Has This Been Tested?
The four empty-table cases fail with the original code and pass with the fix. They exercise creation, deletion, persistence, and reload through the index APIs. A fifth test checks populated IDs and that changing the returned set doesn't change the keyword table. The tests use real keyword extraction and the local
MockLLM.From
llama-index-core:env -u OPENAI_API_KEY CI=1 uv run --frozen -- pytest tests -q): 1,504 passed, 22 skipped, 6 xfailed.uv run --frozen -- mypy llama_index: 479 source files passed.uv run make formatanduv run make lint: passed. Root pre-commit checks and commit hooks also passed for both changed files.The first full-suite run used an invalid dummy OpenAI key and enabled three existing live-provider tests, which failed authentication. The CI-gated run above skips those tests. No provider credentials are needed for the new tests.
Suggested Checklist
uv run make format; uv run make lintAI assistance was used for the one-line change in
KeywordTable.node_idsand the new regression tests. Verification included fail-before/pass-after checks, the full core suite under its CI skip conditions, source type checking, and the repository's formatting and lint checks.