fix(serve): rank resolve_element ties by closeness, not the alphabet - #70
Merged
Merged
Conversation
A phrase prefixes hundreds of concepts in one score tier, and ties fell to fact count and then the alphabet. A filing's fact counts usually separate them; a taxonomy reports nothing, so US GAAP answered "revenue" with RevenueChangeInJudgment and ranked Revenues past 100. - Within a tier: reported concepts first, then an amount before a heading, a text item or an enumeration, then the shortest name, then the alphabet. - A phrase that is the name or label but for spacing, punctuation or a plural scores as exact: "operating lease liability" is "Operating Lease, Liability", "cash and cash equivalents" is "Cash and Cash Equivalent".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolve_elementscores matches in tiers (exact, prefix, token, label, qname), and a phrase like "revenue" prefixes hundreds of concepts in one tier. Ties fell to fact count and then the alphabet. A filing's fact counts usually separate them; a taxonomy loaded in 0.17.0 reports nothing, so on US GAAP "revenue" answeredRevenueChangeInJudgmentand "Revenue Commissioners, Ireland [Member]" first and rankedus-gaap:Revenuespast 100. This ranks ties by closeness instead, and scores a label that differs from the phrase only by punctuation or a plural as exact.Changes
serve/tools.py(surface)signored) equals the concept's name or preferred label scores 90, the exact tier. "operating lease liability" now matches the label "Operating Lease, Liability"; "cash and cash equivalents" matches US GAAP's singular standard label "Cash and Cash Equivalent".Output Impact
INTERNAL for serialization: holon, TAVI and model output are unchanged. The order of
resolve_elementresults changes wherever a tier ties on fact count. That is always the case on a taxonomy and occasionally on a filing. Scores, match counts and match fields are unchanged. Anything that measuresresolve_elementrankings, such as the financial analysis benchmark, can see different first matches when run against this version.Testing
just test-allvia the commit hook: ruff, format, basedpyright clean; 545 passed, 2 skipped. The new test (test_resolve_element_ranks_a_taxonomy_with_no_facts_to_lean_on) fails onmain(RevenueChangeInJudgmentfirst) and passes here.Rank of the expected concept, before → after, over 19 queries per source:
0001045810-26-000021RevenuesOperatingLeaseLiabilityCashAndCashEquivalentsAtCarryingValueShareBasedCompensationInventoryNetEarningsPerShareBasicStockholdersEquityResearchAndDevelopmentExpenseNetIncomeLossProfitLossfirst)AccountsReceivableNetCurrentAccountsReceivableNetfirst)The other queries (revenues, cash, assets, goodwill, long-term debt, income tax expense, depreciation, operating income) were 1 before and stay 1 on both sources, except that NVDA does not report
us-gaap:Cash. A qname query (us-gaap:Assets) ranks 1 on every source. After the change, every query on AAPL 10-Q0000320193-26-000020ranks the expected concept 1 wherever the filing reports it, and all six GASB 2026 exposure-taxonomy queries rank 1 (pension liability was 14 before).