{"_id":"@cajuncodemonkey/naics-search","_rev":"6-c29b5b2ce74c70cfd9aef732f3f20f5d","name":"@cajuncodemonkey/naics-search","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@cajuncodemonkey/naics-search","version":"1.0.0","license":"MIT","_id":"@cajuncodemonkey/naics-search@1.0.0","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"homepage":"https://github.com/krcourville/naics-code-resolver#readme","dist":{"shasum":"7747bcf52c3169917b942d71d6a7e5cd03498c13","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-1.0.0.tgz","fileCount":7,"integrity":"sha512-MYdLwDsHaVMQY2SYdiA795d8FThcG9ptPuiHm94mCPFXyEXvpzNVqX3qyMIZeYK2tHfKaUpgu1xMD9DLOLkJXg==","signatures":[{"sig":"MEQCIFId/0IWFcK9f9IQSqr0iMCRo+shPDhRoZy601mkErC+AiAj/6Tp91EKkuhpXxlueHxqayASpaOX9KW+sLDbU7tzfw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48389408},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"scripts":{"build":"vp pack && cp -r src/data dist/data"},"_npmUser":{"name":"krcourville","email":"krcourville@gmail.com"},"repository":{"url":"https://github.com/krcourville/naics-code-resolver.git","type":"git","directory":"packages/naics-search"},"description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","directories":{},"_nodeVersion":"24.14.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/naics-search_1.0.0_1787194506288_0.5632022045942695","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@cajuncodemonkey/naics-search","version":"1.0.1","license":"MIT","_id":"@cajuncodemonkey/naics-search@1.0.1","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"homepage":"https://github.com/krcourville/naics-code-resolver#readme","bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"dist":{"shasum":"773d349243b573f3eb11770b1d6a648eb56bffe6","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-1.0.1.tgz","fileCount":6,"integrity":"sha512-FLF4gRjXNbeL7szDLaUBEK3BVQKyPZNDB/fr/e/QwKdNBu24ZA0ta8RGcARUSJuSSdrEKCo81eYUFNaKQnX9Ug==","signatures":[{"sig":"MEUCIQDntlI4cTwEf7AgufDALAdUZAB8bP1lBVoOop5ORU9IfwIgeuGw8L19lG91MyhADT5CCxTgUrQ8tqImpxpqmNnl3Vw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@cajuncodemonkey%2fnaics-search@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":34339771},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"gitHead":"721d90e010dfec835bd47fec494b51a90246aa3b","scripts":{"build":"vp pack && cp -r src/data dist/data"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f7329194-dc73-45fe-b971-be882cfb2e39"}},"repository":{"url":"git+https://github.com/krcourville/naics-code-resolver.git","type":"git","directory":"packages/naics-search"},"_npmVersion":"12.0.2","description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/naics-search_1.0.1_1787195941601_0.03886883903180416","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@cajuncodemonkey/naics-search","version":"1.0.2","license":"MIT","_id":"@cajuncodemonkey/naics-search@1.0.2","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"homepage":"https://github.com/krcourville/naics-code-resolver#readme","bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"dist":{"shasum":"61c9ac9b6432d70d02e98d39c3bf4712cab84b4f","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-1.0.2.tgz","fileCount":6,"integrity":"sha512-RoiKvLV/hG5tpjSFuTRMUqms2wsVcv++s59gt1qUyzn4eNezgg45NnfKJMh5bPwpzAY3WBv4xGjzmSH1TL3edg==","signatures":[{"sig":"MEYCIQCLknI+C4fjzAC8ZSsxmeM5qFKB2yOyGxThrTlgBOO29gIhALhOHJMctsNfZtBphZV4RS9wgJ1+oD8VEe8N6P6YK1tA","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@cajuncodemonkey%2fnaics-search@1.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":34340107},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"gitHead":"315189c39c8e8f75e40fc54c910a54dcaa7363d0","scripts":{"build":"vp pack && cp -r src/data data"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f7329194-dc73-45fe-b971-be882cfb2e39"}},"repository":{"url":"git+https://github.com/krcourville/naics-code-resolver.git","type":"git","directory":"packages/naics-search"},"_npmVersion":"12.0.2","description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/naics-search_1.0.2_1787196727312_0.04741898727625271","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@cajuncodemonkey/naics-search","version":"1.0.3","license":"MIT","_id":"@cajuncodemonkey/naics-search@1.0.3","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"homepage":"https://github.com/krcourville/naics-code-resolver#readme","bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"dist":{"shasum":"066d83ede57812b3c4e141f9f0df345272bd8a8a","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-1.0.3.tgz","fileCount":6,"integrity":"sha512-q1wKvqKfbidKuQutjCPEP95qGgJm02efYRKXBx1nJhIr3EVMhZeTjN+OevDaZ4LFJ8yS6drBlmTKjzJD5rW87g==","signatures":[{"sig":"MEQCIBy+5wfShPtsxVV9E35VRDTzrPpoOmCHyoqgBNgare1OAiBLM8A/yDY/Z8lQcZdUmi3TGHSNzSAlpwLK61mMUYFy8w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@cajuncodemonkey%2fnaics-search@1.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":34340434},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"gitHead":"44abfbde5bcc4565c98c40bebc14c7088276a00c","scripts":{"build":"vp pack && cp -r src/data data"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f7329194-dc73-45fe-b971-be882cfb2e39"}},"repository":{"url":"git+https://github.com/krcourville/naics-code-resolver.git","type":"git","directory":"packages/naics-search"},"_npmVersion":"12.0.2","description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/naics-search_1.0.3_1787197339301_0.23669604893280916","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@cajuncodemonkey/naics-search","version":"1.0.4","license":"MIT","_id":"@cajuncodemonkey/naics-search@1.0.4","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"homepage":"https://github.com/krcourville/naics-code-resolver#readme","bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"dist":{"shasum":"9aa07361521d26126a9324ca61e28f2f350ab725","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-1.0.4.tgz","fileCount":6,"integrity":"sha512-Ji9T90lLd5abTwDtCE2eACxxApDoTRRSr+M1Cq48dYYfFxRpDUgO9h+gUJGGxinpbJouh56NucgT/t24iOetjg==","signatures":[{"sig":"MEYCIQC1cQGAVEm4/Q3CYOkiSWKjFmlWwO62XcqOFYrjAaLXEwIhAKycQxRHFW4mP7C/fNbTpBdbPA1hh9Fu+nkQThdJo1gY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@cajuncodemonkey%2fnaics-search@1.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":34340330},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"gitHead":"3284801e3f71c08b1cb33780c003592511ed407e","scripts":{"build":"vp pack && rm -rf data && cp -r src/data data"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f7329194-dc73-45fe-b971-be882cfb2e39"}},"repository":{"url":"git+https://github.com/krcourville/naics-code-resolver.git","type":"git","directory":"packages/naics-search"},"_npmVersion":"12.0.2","description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/naics-search_1.0.4_1787198235439_0.20579665322605956","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@cajuncodemonkey/naics-search","version":"2.0.0","description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","homepage":"https://github.com/krcourville/naics-code-resolver#readme","license":"MIT","repository":{"type":"git","url":"git+https://github.com/krcourville/naics-code-resolver.git","directory":"packages/naics-search"},"type":"module","main":"./dist/index.mjs","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"},"./fs-provider":{"types":"./dist/naics/fs-provider.d.mts","import":"./dist/naics/fs-provider.mjs"}},"scripts":{"build":"vp pack"},"devDependencies":{"@arethetypeswrong/core":"^0.18.5","publint":"^0.3.24"},"gitHead":"1e9d443d4656b5aa6f7f8a9e48d87d7a1caf0d47","_id":"@cajuncodemonkey/naics-search@2.0.0","bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"_nodeVersion":"24.19.0","_npmVersion":"12.0.2","dist":{"integrity":"sha512-CaKKNgdkQQSmoirOEzbQBQRji2VP6kk2FYM6m4OTvAMszpm0whNJs0EsNjOjbDJ5QWl8XIg7frlxNU7iiqtVyw==","shasum":"a99ff3c6e08b4c945574d18ba27757049d86ddff","tarball":"https://registry.npmjs.org/@cajuncodemonkey/naics-search/-/naics-search-2.0.0.tgz","fileCount":7,"unpackedSize":39092,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@cajuncodemonkey%2fnaics-search@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIC77Al9FMLdRjIOrrkpOv77P3t6eC4r+CKYEXhJ89lwgAiAia17bMuwrpQbKaZ8EKpd+EhXJZXmYfZQNkA692+NX4w=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f7329194-dc73-45fe-b971-be882cfb2e39"}},"directories":{},"maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/naics-search_2.0.0_1787328003953_0.8640277696501846"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-20T02:55:06.098Z","modified":"2026-08-21T16:00:04.715Z","1.0.0":"2026-08-20T02:55:06.563Z","1.0.1":"2026-08-20T03:19:01.914Z","1.0.2":"2026-08-20T03:32:07.603Z","1.0.3":"2026-08-20T03:42:19.748Z","1.0.4":"2026-08-20T03:57:15.774Z","2.0.0":"2026-08-21T16:00:04.095Z"},"bugs":{"url":"https://github.com/krcourville/naics-code-resolver/issues"},"license":"MIT","homepage":"https://github.com/krcourville/naics-code-resolver#readme","repository":{"type":"git","url":"git+https://github.com/krcourville/naics-code-resolver.git","directory":"packages/naics-search"},"description":"Free-text business description -> NAICS code search + drilldown Q&A, ported from the BEACON model.","maintainers":[{"name":"krcourville","email":"krcourville@gmail.com"}],"readme":"# @cajuncodemonkey/naics-search\n\nFree-text business description → ranked [NAICS](https://www.census.gov/naics/) code\nmatches, plus the building blocks for a confidence-driven clarifying Q&A flow. Ported\nfrom the [BEACON](https://github.com/uscensusbureau/BEACON) model — inference itself\nruns entirely client-side, no server/backend. The ~34MB model+hierarchy data is **not**\nbundled in this package; it's fetched over the network the first time you call\n`search()`/`loadNaics()` (see [Data loading](#data-loading) below).\n\nBuilt for [naics-code-resolver](https://github.com/krcourville/naics-code-resolver),\na free-text NAICS code lookup tool. See that repo for the full resolver UI this\npackage powers and the \"how it works\" writeup, or try the\n[live app](https://krcourville.github.io/naics-code-resolver/) directly.\n\n## Install\n\n```sh\nnpm install @cajuncodemonkey/naics-search\n```\n\n## Usage\n\n```ts\nimport { search } from \"@cajuncodemonkey/naics-search\";\n\nconst results = await search(\"retail bakery\");\n// [{ naicsCode: \"311811\", title: \"Retail Bakeries\", description: \"...\",\n//    censusUrl: \"https://www.census.gov/naics/?input=311811&year=2022&details=311811\",\n//    score: 0.87 }, ...]\n```\n\n`search()` is async on every call, but only pays the model+hierarchy load cost once —\nthe first call kicks it off, every concurrent/later call awaits the same in-flight load.\n\n## API\n\n### `search(businessDescription: string, topN?: number): Promise<SearchResult[]>`\n\nRanked NAICS matches, highest score first. `topN` defaults to `10`.\n\n```ts\ninterface SearchResult {\n  naicsCode: string;\n  title: string;\n  description?: string; // official Census definition, when available\n  censusUrl: string;\n  score: number; // [0,1] model confidence\n}\n```\n\n### Full resolver flow (drilldown Q&A)\n\n`search()` alone is enough for a simple lookup. For a confidence-driven Q&A flow (offer\na drill-down when the top match is ambiguous, let the user narrow it down against the\nofficial NAICS hierarchy) use the lower-level pieces directly — this is exactly what\nthe [live app](https://github.com/krcourville/naics-code-resolver) does:\n\n```ts\nimport {\n  loadNaics,\n  drilldownOptions,\n  getAncestorPath,\n  getNode,\n  isResolved,\n} from \"@cajuncodemonkey/naics-search\";\n\nconst { model, hierarchy, titles } = await loadNaics();\nconst candidates = model.predictTopN(\"hvac\", 5); // [{ naics, score }, ...]\n\n// static hierarchy drill-down, not model/LLM-generated questions\nconst topLevelOptions = drilldownOptions(hierarchy, null); // sectors\nconst isLeaf = isResolved(hierarchy, \"238220\"); // true -> a confirmed 6-digit code\nconst path = getAncestorPath(hierarchy, \"238220\"); // breadcrumb from root\nconst node = getNode(hierarchy, \"238220\"); // { title, definition?, examples?, children }\n```\n\n- `loadNaics(): Promise<{ model: BeaconModel; hierarchy: HierarchyTree; titles: Map<string, string> }>`\n  — memoized; every caller awaits the same load, nothing is re-triggered.\n- `BeaconModel#predictTopN(text: string, n?: number): NaicsScore[]` — `{ naics, score }[]`,\n  descending by score, positive scores only.\n- `BeaconModel#predictProba(text: string): Record<string, number>` — full score\n  distribution over all 6-digit codes.\n- `drilldownOptions(tree, code)` — children of `code` (or top-level sectors if `code` is\n  `null`).\n- `isResolved(tree, code)` — `true` once a node has no children (a confirmed 6-digit code).\n- `getAncestorPath(tree, code)` — root-to-node `{code,title}[]` chain, for breadcrumbs.\n- `getNode(tree, code)` — full node (`title`, `definition?`, `examples?`, `children`).\n\nWant your own data (BEACON-refit params, or a different vintage), or to construct the\nmodel without going through `loadNaics()`/any provider at all? Construct `BeaconModel`\ndirectly — `new BeaconModel(customParams)`, where `customParams` matches the exported\n`BeaconParams` shape. This is the same data `scripts/build-model.py` in the main repo\nexports.\n\n## Data loading\n\n`search()`/`loadNaics()`/the drilldown fns all need the ~34MB model+hierarchy data, which\nis **not** in this package's install — it's fetched at runtime the first time you call\nany of them. By default that fetch goes to\n[unpkg](https://unpkg.com) (`@cajuncodemonkey/naics-search-data`, a tiny sibling package\nthat exists only to give unpkg a tarball to serve — you never install it directly),\nfalling back automatically to a raw GitHub Release download if unpkg fails for any\nreason. If both fail, the `loadNaics()`/`search()` promise rejects — handle that like\nany other failed fetch.\n\n### Overriding the data source\n\nCall `configureDataProvider()` once, before your first `search()`/`loadNaics()` call:\n\n```ts\nimport { configureDataProvider } from \"@cajuncodemonkey/naics-search\";\n\nconfigureDataProvider(async () => ({\n  params: /* your BeaconParams */,\n  hierarchy: /* your HierarchyTree */,\n}));\n```\n\nA `DataProvider` is just `() => Promise<{ params: BeaconParams; hierarchy: HierarchyTree }>`\n— fetch it from wherever you like. For Node consumers (scripts, tests, self-hosted/offline\nsetups) a ready-made filesystem provider ships as a separate entry point so `node:fs`\nnever lands in a browser bundle:\n\n```ts\nimport { configureDataProvider } from \"@cajuncodemonkey/naics-search\";\nimport { fsDataProvider } from \"@cajuncodemonkey/naics-search/fs-provider\";\n\nconfigureDataProvider(\n  fsDataProvider({ model: \"./naics-model.json\", hierarchy: \"./naics-hierarchy.json\" }),\n);\n```\n\n## Caveats\n\n- **Network required by default.** Unlike versions before 2.0, this package ships no\n  data — the first `search()`/`loadNaics()` call needs network access (unpkg, falling\n  back to a GitHub Release download) unless you supply your own provider. Offline/\n  air-gapped consumers should use `configureDataProvider()` with the fs provider (or\n  their own) pointed at a locally-obtained copy of the data.\n- **Sparse model, not exhaustive.** The underlying BeaconModel keeps only nonzero\n  n-gram → NAICS proportions (~98.8% of the dense form is zero); scores are a purity-\n  weighted heuristic over 2017/2022 Census training data, not a guarantee — always\n  treat `score` as a confidence signal, not ground truth.\n- **Main entry stays DOM-free.** The package itself (and its default data provider) only\n  uses `fetch` — no `document`/`window`/other browser-only globals — so it works in\n  Node 18+ and any bundler target alike. The Node-only `fs-provider` subpath is opt-in\n  and never pulled into a browser build unless you import it yourself.\n- **English business descriptions only.** No multi-language support.\n- **Static Q&A only.** Any drill-down UI you build on `drilldownOptions`/`getNode`\n  should stay a static hierarchy browse — there's no model/LLM-generated question\n  text here by design.\n\n## License\n\nMIT. BEACON (the model this package ports) is public domain (CC0 1.0) — see the\n[upstream license](https://github.com/uscensusbureau/BEACON/blob/main/LICENSE.md).\n\nSee [CONTRIBUTING.md](https://github.com/krcourville/naics-code-resolver/blob/main/CONTRIBUTING.md)\nin the main repo for release steps.\n","readmeFilename":"README.md"}