{"id":15290845,"url":"https://github.com/florents-tselai/tsellm","last_synced_at":"2025-04-12T05:12:49.979Z","repository":{"id":245479279,"uuid":"818600254","full_name":"Florents-Tselai/tsellm","owner":"Florents-Tselai","description":"tsellm: LLMs in SQLite and DuckDB","archived":false,"fork":false,"pushed_at":"2024-08-16T08:02:39.000Z","size":1131,"stargazers_count":22,"open_issues_count":21,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T05:12:37.527Z","etag":null,"topics":["duckdb","llm","sql","sqlite"],"latest_commit_sha":null,"homepage":"https://tsellm.tselai.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Florents-Tselai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Florents-Tselai"]}},"created_at":"2024-06-22T09:46:28.000Z","updated_at":"2025-02-03T15:16:40.000Z","dependencies_parsed_at":"2024-08-15T09:54:17.848Z","dependency_job_id":null,"html_url":"https://github.com/Florents-Tselai/tsellm","commit_stats":null,"previous_names":["florents-tselai/tsellm"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Ftsellm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Ftsellm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Ftsellm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Ftsellm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Florents-Tselai","download_url":"https://codeload.github.com/Florents-Tselai/tsellm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248519556,"owners_count":21117761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["duckdb","llm","sql","sqlite"],"created_at":"2024-09-30T16:09:44.025Z","updated_at":"2025-04-12T05:12:49.945Z","avatar_url":"https://github.com/Florents-Tselai.png","language":"Python","funding_links":["https://github.com/sponsors/Florents-Tselai","https://github.com/sponsors/Florents-Tselai/"],"categories":[],"sub_categories":[],"readme":"# tsellm: Use LLMs in SQLite and DuckDB\n\n[![Github](https://img.shields.io/static/v1?label=GitHub\u0026message=Repo\u0026logo=GitHub\u0026color=green)](https://github.com/Florents-Tselai/tsellm)\n[![PyPI](https://img.shields.io/pypi/v/tsellm.svg)](https://pypi.org/project/tsellm/)\n[![Documentation Status](https://readthedocs.org/projects/tsellm/badge/?version=stable)](http://tsellm.tselai.com/en/latest/?badge=stable)\n[![Linkedin](https://img.shields.io/badge/LinkedIn-0077B5?logo=linkedin\u0026logoColor=white)](https://www.linkedin.com/in/florentstselai/)\n[![Github Sponsors](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=pink)](https://github.com/sponsors/Florents-Tselai/)\n[![pip installs](https://img.shields.io/pypi/dm/tsellm?label=pip%20installs)](https://pypi.org/project/tsellm/)\n[![Tests](https://github.com/Florents-Tselai/tsellm/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/Florents-Tselai/tsellm/actions?query=workflow%3ATest)\n[![codecov](https://codecov.io/gh/Florents-Tselai/tsellm/branch/main/graph/badge.svg)](https://codecov.io/gh/Florents-Tselai/tsellm)\n[![License](https://img.shields.io/badge/BSD%20license-blue.svg)](https://github.com/Florents-Tselai/tsellm/blob/main/LICENSE)\n\n**tsellm** is the easiest way to access LLMs from SQLite or DuckDB.\n\n```shell\npip install tsellm\n```\n\n## Prompts\n\n```bash\ncat \u003c\u003cEOF | tee \u003e(sqlite3 prompts.sqlite3) | duckdb prompts.duckdb\nCREATE TABLE prompts ( p TEXT);\nINSERT INTO prompts VALUES('how are you?');\nINSERT INTO prompts VALUES('is this real life?');\nEOF\n```\n\n```shell\nllm install llm-gpt4all\n```\n\n```sql\ntsellm prompts.duckdb \"select prompt(p, 'orca-mini-3b-gguf2-q4_0') from prompts\"\ntsellm prompts.sqlite3 \"select prompt(p, 'orca-2-7b') from prompts\"\n```\n\nBehind the scenes, **tsellm** is based on the beautiful [llm](https://llm.datasette.io) library,\nso you can use any of its plugins:\n\n### Multiple Prompts\n\nWith a single query, you can easily access get prompt \nresponses from different LLMs:\n\n```sql\ntsellm prompts.sqlite3 \"\n        select p,\n        prompt(p, 'orca-2-7b'),\n        prompt(p, 'orca-mini-3b-gguf2-q4_0'),\n        embed(p, 'sentence-transformers/all-MiniLM-L12-v2') \n        from prompts\"\n```\n\n## Embeddings\n\n```shell\nllm install llm-sentence-transformers\nllm sentence-transformers register all-MiniLM-L12-v2\nllm install llm-embed-hazo # dummy embedding model for demonstration purposes\n```\n\n```sql\ntsellm prompts.sqlite3 \"select embed(p, 'sentence-transformers/all-MiniLM-L12-v2')\"\n```\n\n### `JSON` Embeddings Recursively\n\nIf you have `JSON` columns, you can embed these object recursively.\nThat is, an embedding vector of floats will replace each text occurrence in the object.\n\n```bash\ncat \u003c\u003cEOF | tee \u003e(sqlite3 prompts.sqlite3) | duckdb prompts.duckdb\nCREATE TABLE people(d JSON);\nINSERT INTO people (d) VALUES \n('{\"name\": \"John Doe\", \"age\": 30, \"hobbies\": [\"reading\", \"biking\"]}'),\n('{\"name\": \"Jane Smith\", \"age\": 25, \"hobbies\": [\"painting\", \"traveling\"]}')\nEOF\n```\n\n#### SQLite\n\n```sql\ntsellm prompts.sqlite3 \"select json_embed(d, 'hazo') from people\"\n```\n\n*Output*\n        \n```\n('{\"name\": [4.0, 3.0,..., 0.0], \"age\": 30, \"hobbies\": [[7.0, 0.0,..., 0.0], [6.0, 0.0, ..., 0.0]]}',)\n('{\"name\": [4.0, 5.0, ,..., 0.0], \"age\": 25, \"hobbies\": [[8.0, 0.0,..., 0.0], [9.0, 0.0,..., 0.0]]}',)\n```\n\n#### DuckDB\n\n```sql\ntsellm prompts.duckdb \"select json_embed(d, 'hazo') from people\"\n```\n\n*Output*\n        \n```\n('{\"name\": [4.0, 3.0,..., 0.0], \"age\": 30, \"hobbies\": [[7.0, 0.0,..., 0.0], [6.0, 0.0, ..., 0.0]]}',)\n('{\"name\": [4.0, 5.0, ,..., 0.0], \"age\": 25, \"hobbies\": [[8.0, 0.0,..., 0.0], [9.0, 0.0,..., 0.0]]}',)\n```\n\n### Binary (`BLOB`) Embeddings\n\n```shell\nwget https://tselai.com/img/flo.jpg\nsqlite3 images.sqlite3 \u003c\u003cEOF\nCREATE TABLE images(name TEXT, type TEXT, img BLOB);\nINSERT INTO images(name,type,img) VALUES('flo','jpg',readfile('flo.jpg'));\nEOF\n```\n\n```shell\nllm install llm-clip\n```\n\n```sql\ntsellm images.sqlite3 \"select embed(img, 'clip') from images\"\n```\n\n## Interactive Shell\n\nIf you don't provide an SQL query,\nyou'll enter an interactive shell instead.\n\n```shell\ntsellm prompts.db\n```\n\n![til](./tsellm-demo.gif)\n\n## Installation\n\n```bash\npip install tsellm\n```\n\n## How\n\n**tsellm** relies on the following facts:\n\n* SQLite is bundled with the standard Python library (`import sqlite3`)\n* Python 3.12 ships with a [SQLite interactive shell](https://docs.python.org/3/library/sqlite3.html#command-line-interface)\n* one can create Python-written user-defined functions to be used in SQLite \n  queries (see [create_function](https://github.com/simonw/llm))\n* [Simon Willison](https://github.com/simonw/) has gone through the process of \n  creating the beautiful [llm](https://github.com/simonw/llm) Python \n  library and CLI\n\n## Development\n\n```bash\npip install -e '.[test]'\npytest\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorents-tselai%2Ftsellm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorents-tselai%2Ftsellm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorents-tselai%2Ftsellm/lists"}