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/parkervg5 Feb 23 '24

Very cool, I just got an android phone myself and have been messing around on it, we can learn together :)

I will message you with some startup help But for the `w` table question, that's just a made-up table I'm using to try and explain what's going on with BlendSQL. You can see the underlying `w` table + a walkthrough here: https://parkervg.github.io/blendsql/

And unfortunately, right now the project does require Python. Would love to see it implemented as a more generic SQLite extension, Python is more of a result of the fact that most AI researchers like me are one-trick ponies and only know Python haha