Skip to content

Build1 publisher2 min readPublished

Cutting graph retrieval to 50 nodes stopped the model confusing entities

One developer's Graph RAG layer over a 50 million-row supply chain graph caps every retrieval at 50 nodes and three hops, and the ordering line in the Cypher decides which facts that cap throws away.

The Engineer · Build desk

Illustration accompanying Cutting graph retrieval to 50 nodes stopped the model confusing entities

What happened

  • The first version expanded four hops from the seed entity and reached 8,000 tokens of context on a basic query about a mid-size Korean manufacturer, at which point the model started confusing entities.
  • Expansion was cut to three hops after the fourth hop began returning nodes that were technically connected but irrelevant, typically conglomerates that own everything.
  • The seed lookup matches normalized names and aliases, ranks candidates by how many documents mention them, returns three, and the code keeps the first one.
  • Retrieval fetches up to 100 source-document excerpts ordered by assertion confidence, then trims them to 40 by TF-IDF overlap with the query terms before the model sees them.
  • Facts reached through entity-resolution merges below 0.80 confidence get a manually added [uncertain] label, put in after the model was found treating every fact as equally solid.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • constraint The budget is spent in hop order, so a wide first-hop fan-out consumes all of it and the longer chains the layer was built to surface are the first thing lost.
  • cost A team copying this design pays in entity-resolution weeks, not retrieval days: the query layer here is three days of Cypher sitting on roughly five times that much work underneath.
  • decision Inheriting 50 as a cap means inheriting one developer's read of one model's behaviour, so a team has to run its own accuracy comparison before it trusts the number.
  • exposure An unmerged raw-string supplier node stays reachable by retrieval, so the model can build an answer on facts attached to an entity the graph never resolved.

The ordering line in the expansion query decides what the 50-node cap removes. The Cypher walks SUPPLIES_TO, SOURCES_FROM, OWNS and CONTROLS to depth three, sorts by hop count ascending and then by the neighbor's document_count, and cuts at 50 [12]. Slots fill from the inside out. The post says Samsung Electronics has hundreds of subsidiaries, and that a query about their supply chain exposure hits the limit before returning a complete picture [6]. Direct neighbors take the slots first, so on a seed like that the second hop never gets a row [23]. The chain the design exists to find runs three hops: a steel tariff on a Korean parts supplier that feeds a construction equipment company [14].

The author is direct about the number. "I don't love that number," the post says [4]. "But 50 is where the model stops confusing things and starts giving useful answers, and I haven't found a smarter expansion strategy that changes that tradeoff," the author wrote [5].

Downstream, two rankings fight over the fact list. Assertion confidence picks the pool of 100 excerpts [15], and lexical overlap picks the 40 that ship [16], so a fact from a weak merge can survive on term overlap while a verified one is cut. Sixty of every hundred fetched excerpts never reach the model [20]. The prompt tells the model to treat flagged facts as preliminary, and facts arrive sorted by confidence with a source and a date attached [18].

The seed lookup carries the weaker guarantee. mention_count is the number of source documents an entity appears in, which the post calls a rough importance proxy, and it sometimes picks the wrong candidate for ambiguous mentions, especially smaller companies that share name fragments [10]. The query returns three candidates and the code keeps the first, so two are fetched and dropped [24]. "I haven't fixed that properly," the author wrote [11]. Every retrieval in the system starts from those seed entities [26].

Fifty is a node count standing in for a token budget. It transfers to another graph only if the excerpts are about the length of the filing sentences, news sentences and procurement sentences this one stores [27]. It also assumes a similar fan-out, because what exhausts the budget is the count of direct neighbors [23]. The post reports no comparison against other caps and no accuracy numbers behind the choice [25]. Fifty nodes over 50 million rows is one node per million rows [21].

What to watch

  • Whether the flat 50 is replaced by a per-hop quota, which would let hop 2 and hop 3 survive a wide first-hop fan-out.
  • Any published accuracy comparison at 50 versus 100 or 200 nodes, which would show whether the cap or the merge quality is the binding constraint.
  • A disambiguation step replacing candidates[0] for mentions that share name fragments with larger entities.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories