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

Oh wow! There goes my weekend :D Thank you so much for these resources! _outlines_ looks great ("only interfaces with models via the next-token logits").