NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Show HN: I implemented a neural network in SQL (github.com)
AlotOfReading 16 hours ago [-]
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

[1] https://arxiv.org/html/2601.17188v1

[2] https://github.com/TimelyDataflow/differential-dataflow

sporkl 22 hours ago [-]
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/

sixdimensional 21 hours ago [-]
In the past platforms have integrated ML algorithms into relational databases and SQL through extensions (both commercial and open source). A famous open source one was MADlib [1], which has an implementation of neural networks. Even the commercial ones were similar, I used ML algorithms in SQL Server many years ago around 2005 I think.

I am wondering about.. SQL as a declarative structured query language that can be optimized into essentially any kind of distributed, directed acyclic graph of processing - vs the special characteristics of relational databases (relational algebra, relvars, etc. etc.) is an important distinction as - of yet, I see the author linking both together so I'm trying to understand what it is about relational structures that specifically helped here (just not seeing it yet, not that it isn't there).

Also, wondering if ISO/IEC 9075-15:2023 SQL standard for multidimensional arrays (MDA) is of any use here? Paper describing SQL/MDA here [2].

[1] https://madlib.apache.org/documentation.html

[2] https://www.ifis.uni-luebeck.de/~moeller/Lectures/WS-19-20/N...

alxmrs 21 hours ago [-]
I need to better understand your first question before I can comment. In theory, we could work with MADlib too -- what we do is port scientific data, which typically is a "tensor" or Nd array, into a tabular view. I believe you know relational theory better than I do, I am still fairly new to the field.

WRT ISO/IEC 9075-15:2023: This is the standard established from rasdaman, IIUC. I reject this approach (which treats arrays as a column type), and instead adopt one inspired by Michael Stonebraker's SciDB (which treats arrays as tables themselves). For an in depth review of the topic, I recommend this NSF paper: https://par.nsf.gov/servlets/purl/10545560

HPsquared 24 hours ago [-]
Somewhat more reliable than implementing SQL in neural networks.
ReactiveJelly 17 hours ago [-]
I'll try it next time I've got Greece vacation money
harvey9 15 hours ago [-]
It did seem cross-posted from LinkedIn
23 hours ago [-]
tommica 24 hours ago [-]
I'm just going to go back to making my CRUD endpoints...

Jokes aside, sounds really impressive, though I only understood about 10% :D

goosethe 16 hours ago [-]
I have done similar as well: https://github.com/seanwevans/pg_gpt2
22 hours ago [-]
soupspaces 23 hours ago [-]
Neat! Feels analogous to "X runs Doom" demos (but NN).
simonw 22 hours ago [-]
Just today I saw this implementation of DOOM in SQLite using a recursive CTE for a simple ray tracer: https://github.com/petergpt/doomql
alxmrs 23 hours ago [-]
Totally. I can’t wait to take this to https://hytradboi.com
NuclearPM 6 hours ago [-]
Babymoon?
Sia123 13 hours ago [-]
Looks good, i will try today
0xnyn 24 hours ago [-]
initially rolled my eyes at "neural networks in SQL," but after reading the code I came away impressed

basically it comes down to using relational algebra as the IR, letting a database optimizer reason about tensor programs

alxmrs 23 hours ago [-]
I would have had the same gut reaction as you lol.

You’re spot on. I think that SQL, as a data oriented and logic PL, might be ideal for writing tensor programs.

handfuloflight 19 hours ago [-]
Fable is impressed.
slipperybeluga 1 days ago [-]
[dead]
throwaway613746 23 hours ago [-]
[dead]
iqbal1980 23 hours ago [-]
Why? lol
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 20:40:33 GMT+0000 (Coordinated Universal Time) with Vercel.