[BUG] LocalKGStore.nodes() omits nodes without outgoing edges, so entity linking cannot match them
Package version
3.19.1 (current main)
Package
byokg-rag
Python version
3.11
Operating System
Linux
Description
LocalKGStore.nodes() is documented as returning "all node_ids in the graph", but it returns list(self._graph.keys()) (graphstore/graphstore.py:168-174). The graph dict only has a top-level key for a node with outgoing edges, so a node that only appears as a triplet's destination is never returned. NeptuneAnalyticsGraphStore.nodes() runs MATCH (n) and returns every node, so the two stores disagree.
nodes() is the vocabulary for entity linking. ByoKGQueryEngine builds its default FuzzyStringIndex from graph_store.nodes() (byokg_query_engine.py:60), and the examples and docs do the same. Destination-only nodes can therefore never be linked: a mention of one resolves to whatever source node scores highest. This also affects linked draft answers, which are usually such nodes and which the path retriever uses as targets.
With examples/byokg-rag/data/freebase_tiny_kg.csv, the dataset the local-graph demo notebook loads, nodes() returns 1,691 of the graph's 16,412 nodes. The other 14,721 can't be linked, and the notebook prints the wrong node count.
Steps to reproduce
from graphrag_toolkit.byokg_rag.graphstore import LocalKGStore
from graphrag_toolkit.byokg_rag.indexing import FuzzyStringIndex
from graphrag_toolkit.byokg_rag.graph_retrievers import EntityLinker
store = LocalKGStore(graph={
'Organization': {
'LOCATED_IN': {'triplets': [('Organization', 'LOCATED_IN', 'Portland')]}
}
})
print(store.nodes())
# ['Organization'] -- 'Portland' is missing
# With the demo notebook's dataset:
store = LocalKGStore()
store.read_from_csv('examples/byokg-rag/data/freebase_tiny_kg.csv')
print(len(store.nodes())) # 1691; the CSV has 16412 distinct nodes
index = FuzzyStringIndex()
index.add(store.nodes())
print(EntityLinker(index.as_entity_matcher()).link(
['3rd New York Volunteer Infantry Regiment'], return_dict=False))
# ["Countdown of 10 Amazing Moments from the Year 2011: No. 9 Belafonte's New Song"]
Suggested fix
Return the source nodes and the destinations of every triplet, without duplicates.