xarray-sql - Neural network implementation in SQL
Show HN: I implemented a neural network in SQL
xarray-sql is an innovative library that enables developers to build and train neural networks entirely within SQL. By leveraging the power of xarray for multi-dimensional data handling, this tool transforms standard SQL queries into a functional deep learning environment. It demonstrates the feasibility of executing complex machine learning tasks like gradient descent on datasets such as Fashion-MNIST without relying on traditional Python frameworks. This approach offers a unique perspective on data processing, allowing for efficient streaming and chunked computation directly in the database layer.
Drop zero-valued pixels from the dominant layer-0 contraction, shrinking the join exactly while scaling speedup with the fraction of zeros.
- AlotOfReading
I don't want to rain on discovering a genuinely cool bit of theory, but it's not "new" per se.
The equivalence with Einstein summation was noted in this paper [0]. Sandia labs wrote an SQL database based around graphBLAS called TenSQL a few years back. And something similar to your idea of relational algebra as the basis for AI had a paper published earlier this year [1], naming it Tensor Logic.
Are all of these common operations secretly relational, just with the wrong data model?
Sadly not, but you can get a long way before you find the limits. Modern databases are very well optimized for their use cases, but there's many other possible points in the design space to explore. If you want to really make efficient use of hardware, there are fundamental scaling problems with natural joins because of the combinatorial explosion that gives us WCO though. If you accept an inability to express triangular queries, you can get something that's embarrassingly parallel and scales really flipping well.
If you want to stick to the full relational model, you might be interested in Differential Dataflow [2].
[0] https://arxiv.org/html/2510.12269v3
- sporkl
I've been working on something similar, implementing a relational language on top of a tensor library[0].
Mathematically, einsum and database joins are the same thing, just over different semirings (real numbers for einsum, booleans for databases). A lot of papers about datalog explore this sort of thing in more depth. In particular, Dyna[1] might be interesting.
[0]: https://arxiv.org/abs/2509.22614
[1]: https://dyna.org/
- HPsquared
Somewhat more reliable than implementing SQL in neural networks.