5 ms·
Show HN: Vector-logic, a lightweight rules engine from first principles
- dmitry_stratyfy 11mo agoHi HN, I'm one of the creators. I've been tackling the problem of managing complex business rules for years (especially in fintech), and wanted a lightweight, Python-native tool that was built on a solid theoretical foundation. We built vector-logic (it's on PyPI) and wrote a hands-on guide for Towards Data Science: https://towardsdatascience.com/building-a-rules-engine-from-first-principles/ https://towardsdatascience.com/building-a-rules-engine-from-... The whole framework is based on a theory we call 'State Algebra,' which we co-authored for arXiv: https://arxiv.org/abs/2509.10326 https://arxiv.org/abs/2509.10326 Happy to answer any questions!
- Antibabelic 11mo agoHow does this compare to something like Prolog?
- dmitry_stratyfy 11mo agoProlog is heavy-weight 1st order logic machine. vector-logic is light-weight propositional logic inference engine. Optimised for simple queries like "what is the value of 'y' given all rules and evidences", and also allows you to iterate through the entire valid set (all valid assignments). We also bothered to make the interface very simple and intuitive - you'll have very shallow learning curve.
- nch1357 11mo agoHi Dmitry. This is really cool -- thanks for sharing! This is very clean and intuitive, and it definitely come in handy when I'm mapping out systems logic.
- dmitry_stratyfy 11mo agoGlad to hear that! Ping me if you have any questions
- d_blumberg 11mo agoIs it brute force or uses some sort of heuristics?
- dmitry_stratyfy 11mo agoGood point. Yes, it uses optimisation for various tasks. First of all, it uses compact representatin of rules - similar to DNF, but converted to a sparse matrix. Second, for the inference (which is a process of compiling the knowledge base) the order in which rules are compiled is crucial. We use two types of heuristic optimisations for this process, one is based on Jaccard similarity, another is so called predator-pray heuristics. Happy to give more details, let me know
- d_blumberg 11mo agoI checked your benchmarks. Runtime with 30 rules is 5x longer than with 45 rules. Am I missing something?
- dmitry_stratyfy 11mo agoThis is an expected behaviour. More rules impose more constraints on the feasible space. The space with more rules is hence much smaller. The only pitfall is that in the middle of calculation the feasible space may blow up before eventually shrinking. This is where the optimisation heuristics helps. Your previous question was spot on :)