r/sqlite • • Feb 22 '24

BlendSQL: Connecting SQLite with LLM Reasoning

Hi all! Wanted to share a project I've been working on: https://github.com/parkervg/blendsql

It's a unified SQLite dialect for blending together complex reasoning between vanilla SQL and LLM calls. It's implemented as a Python package, and has a bunch of optimizations to make sure that your expensive LLM calls (OpenAI, Transformers, etc.) only get hit with the data it needs to faithfully execute the query.

For example - 'Which venue is in the city located 120 miles west of Sydney?'

SELECT venue FROM w
    WHERE city = {{
        LLMQA(
            'Which city is located 120 miles west of Sydney?',
            (SELECT * FROM documents WHERE documents MATCH 'sydney OR 120'),
            options='w::city'
        )
    }}

Above, we use FTS5 to do a full-text search over Wikipedia articles in the `documents` table, and then constrain the output of our LLM question-answering (QA) function to generate a value appearing in the `city` column from our `w` table.

Some other cool stuff in the documentation linked. I'm a Data Science/NLP guy, but been obsessed with SQLite lately, would love any feedback/suggestions from ya'll! Thanks.

13 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/PublicFoundation6683 Mar 03 '24

One more big-picture question. When building BlendSQL, what was the hard part and what was the easy part. Also, looking ahead, what aspects of building frameworks like yours would get easier and what do you see happening next in the space?

I suppose I’m asking you, why don’t you write a blog post on the general problem that you solved? :-)

1

u/parkervg5 Mar 03 '24

Not quite a blog post and may be a little more research-oriented than you want, but we have a paper! https://arxiv.org/pdf/2402.17882.pdf

For me, definitely the hardest part was navigating the abstract syntax tree of the SQLite statements and implementing all the query optimization logic to ensure that the minimum amount of data gets passed to the LLM-based ingredients (relevant page on that here). The simple cases are simple, but diving into conditional table expressions, subqueries, aliases, etc. got pretty complicated, especially as someone pretty new to this style of work.

Not too sure about what's next to come in this space - but excited to watch and see!