{"id":21202035,"url":"https://github.com/radiantone/inferencegraph","last_synced_at":"2025-08-18T05:49:38.184Z","repository":{"id":54871180,"uuid":"327288154","full_name":"radiantone/inferencegraph","owner":"radiantone","description":"A knowledge graph based forward chain inferencing engine in typescript/node.","archived":false,"fork":false,"pushed_at":"2021-01-23T15:45:52.000Z","size":83,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-04T07:07:48.214Z","etag":null,"topics":["artificial-intelligence","forward-chaining","framework","inference-engine","inferences","javascript","knowledge-graph","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radiantone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-06T11:16:25.000Z","updated_at":"2024-07-15T09:28:38.000Z","dependencies_parsed_at":"2022-08-14T05:20:19.226Z","dependency_job_id":null,"html_url":"https://github.com/radiantone/inferencegraph","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/radiantone/inferencegraph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radiantone%2Finferencegraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radiantone%2Finferencegraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radiantone%2Finferencegraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radiantone%2Finferencegraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radiantone","download_url":"https://codeload.github.com/radiantone/inferencegraph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radiantone%2Finferencegraph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270951283,"owners_count":24674007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","forward-chaining","framework","inference-engine","inferences","javascript","knowledge-graph","nodejs","typescript"],"created_at":"2024-11-20T20:12:31.548Z","updated_at":"2025-08-18T05:49:38.099Z","avatar_url":"https://github.com/radiantone.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inferencegraph\n\nA knowledge graph based forward chain inferencing engine in typescript/node.\n\n# Overview\n\n## Notes\n\nThis is 'in development' and is only a working draft at the moment, not a complete system. Updates will come regularly. I have some interesting plans for this package.\n\n## Install\n\n\\# From this cloned repo \u003cbr\u003e\n$ npm i\n\n\\# From your node project \u003cbr\u003e\n$ npm i inferencegraph\n\n## Lint\n\n\\# Within this cloned repo \u003cbr\u003e\n\n$ npm run lint \u003cbr\u003e\n\n## Build\n\n\\# Within this cloned repo \u003cbr\u003e\n\n$ npm run build \u003cbr\u003e\n\\# Clean build \u0026 test\u003cbr\u003e\n$ npm run clean \u0026\u0026 npm run build \u0026\u0026 npm run lint \u0026\u0026 npm run test\n\n## Run\n\n\\# Within this cloned repo \u003cbr\u003e\n\n$ npm run test\n\n# Design Goals\n\n- Primitive typed fact values (string, boolean, number, object)\n- Operator evaluation (=,!=,\u003e,\u003c,true,false)\n- Cycle detection\n- Composition based. Can create separate fact graphs and add them to a knowledge graph at different times\n- Clean. Simple. Easy to understand\n- Extensible\n- Uses Classes. Typescript\n- Powerful rules with conditions (when), assertions, retractions and functional side-effects (do's)\n- Automatic planning. Functional attributes of rules are built into a functional \"plan\" during inference chaining. Once the engine has completed its inferences, an executable (and ordered) plan is returned that executes asynchronously returning Promises.\n- Ability to solve inferencing logic problems. A more detailed logic problem example will be forthcoming.\n- Low memory consumption, simple data structures\n- Work in Node and in Browser\n\n# Importing\n\nFrom within your typescript module\n\n```\nimport { Graph, Fact, Factoid, KnowledgeBase, KnowledgeGraph, Brain, Rule } from 'inferencegraph'\n```\n\n# Classes\n\n## Factoids\n\nAn untyped data container\n\n```\nnew Factoid({\n        'name': 'barks',\n        'value': true\n    })\n```\n\n## Facts\n\nA typed data container used with Knowledge Bases\n\n```\nconst newFact = new Fact(new Factoid({\n    'name':'barks',\n    'value':true\n}))\n```\n\n## Rules\n\nRule is a container for conditions, assertions and functions associated with facts that are evaluated by the inference engine. Each rule evaluates to either true or false based on it's when conditions, which all must be true for the rule to fire.\n\n```\n    new Rule({\n        name: \"dog\",\n        when: [{\n            name:'hair',\n            value: true,\n            operator: '='\n        },{\n            name:'barks',\n            value: true,\n            operator: '='\n        }],\n        retract:[],\n        do:[(function(callbacks) {\n            return \"DO: It's a dog!\"+JSON.stringify(callbacks)\n        })],\n        assert: [{\n            name:'specie',\n            value: 'dog'\n        }]\n    })\n\n```\n\n## KnowledgeBase\n\nKnowledgeBase is a container for a collection of facts and operations on them\n\n```\nconst corgiFacts = [ new Fact(new Factoid({\n    'name':'hair',\n    'value':true\n})), new Fact(new Factoid({\n    'name':'barks',\n    'value':true\n})), new Fact(new Factoid({\n    'name':'fur',\n    'value':'tan'\n})), new Fact(new Factoid({\n    'name':'legs',\n    'value':'short'\n}))]\n\nconst kb = new KnowledgeBase()\nkb.assertFacts(corgiFacts, true);\n```\n\n## Graph\n\nGraph is a container for rules\n\n```\nconst graph = new Graph([\n    new Rule({\n        name: \"dog\",\n        when: [{\n            name:'hair',\n            value: true,\n            operator: '='\n        },{\n            name:'barks',\n            value: true,\n            operator: '='\n        }],\n        retract:[],\n        do:[(function(callbacks) { // Can receive callbacks object here, which might have other user data\n            return \"DO: It's a dog!\"+JSON.stringify(callbacks)\n        })],\n        assert: [{\n            name:'specie',\n            value: 'dog'\n        }]\n    }),\n    new Rule({\n        name: \"dalmation\",\n        when: [{\n            name:'specie',\n            value: 'dog',\n            operator: '='\n        },{\n            name:'fur',\n            value: 'spotted',\n            operator: '='\n        }],\n        retract:[],\n        do:[(function(callbacks) { // Can receive callbacks object here, which might have other user data\n            return \"DO: It's a dalmation!\"+JSON.stringify(callbacks)\n        })],\n        assert: [{\n            name:'breed',\n            value: 'dalmation'\n        }]\n    })\n]);\n```\n\n## KnowledgeGraph\n\nKnowledgeGraph is a container for graphs\n\n```\nconst kg = new KnowledgeGraph(kb)\nkg.addGraph(graph)\n```\n\n## Callbacks\n\nCallbacks are optional, but will be invoked during inferencing to trigger your business logic if using Plans is not the desired course.\u003cbr\u003e\n\nEvents\n\n```\nexport class Callbacks extends Object {\n\n    public onFactTrue: Function;\n    public onFactFalse: Function;\n    public onFactAsserted: Function;\n    public onFactResolved: Function;\n    public onFactRetracted: Function;\n\n}\n```\n\nUsage\n\n```\nvar callbacks = new Callbacks();\n\ncallbacks.onFactTrue = (fact, rule, when) =\u003e {\n    console.log(\"callback: onFactTrue: \",fact,rule,when)\n}\ncallbacks.onFactFalse = (fact, rule, when) =\u003e {\n    console.log(\"callback: onFactFalse: \",fact,rule,when)\n}\ncallbacks.onFactResolved = (fact) =\u003e {\n    console.log(\"callback: onFactResolved! \",fact)\n}\nbrain.assertFact(newFact, plan,callbacks);\n```\n\n## Brain\n\nBrain is a container for knowledge graphs and high-level API over them\n\n```\nconst brain = new Brain(kg, true);\n\nconst newFact = new Fact(new Factoid({\n    'name':'fur',\n    'value':'spotted'\n}))\n\nvar plan = [];\n\n// Infer a plan stemming from this fact assertion\nbrain.assertFact(newFact, plan, callbacks);\n\nconsole.log(\"PLAN:\",plan);\n\nplan.forEach( promise =\u003e {\n    promise.then( (result) =\u003e {\n        console.log(\"CALLBACK:\", result)\n    });  // Execute plan functions\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradiantone%2Finferencegraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradiantone%2Finferencegraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradiantone%2Finferencegraph/lists"}