Skip to main content

datasette-llm-embed

PyPI Changelog Tests License

Datasette plugin adding a llm_embed(model_id, text) SQL function.

Installation

datasette install datasette-llm-embed

Usage

Adds a SQL function that can be called like this:

select llm_embed('sentence-transformers/all-mpnet-base-v2', 'This is some text')

This embeds the provided text using the specified embedding model and returns a binary blob, suitable for use with plugins such as datasette-faiss.

The models need to be installed using LLM plugins such as llm-sentence-transformers.

Use llm_embed_cosine(a, b) to calculate cosine similarity between two vector blobs:

select llm_embed_cosine(
    llm_embed('sentence-transformers/all-mpnet-base-v2', 'This is some text'),
    llm_embed('sentence-transformers/all-mpnet-base-v2', 'This is some other text')
)

The llm_embed_decode() function can be used to decode a binary BLOB into a JSON array of floats:

select llm_embed_decode(
    llm_embed('sentence-transformers/all-mpnet-base-v2', 'This is some text')
)

Models that require API keys

If your embedding model needs an API key - for example the ada-002 model from OpenAI - you can configure that key in metadata.yml (or JSON) like this:

plugins:
  datasette-llm-embed:
    keys:
      ada-002:
        $env: OPENAI_API_KEY

The key here should be the full model ID of the model - not an alias.

You can then set the OPENAI_API_KEY environment variable to the key you want to use before starting Datasette:

export OPENAI_API_KEY=sk-1234567890

Once configured, calls like this will use the API key that has been provided:

select llm_embed('ada-002', 'This is some text')

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-llm-embed
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'
To run the tests:
```bash
pytest

Metadata

Release files for datasette-llm-embed 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-llm-embed 0.2
File Size Uploaded Provenance Actions
datasette-llm-embed-0.2.tar.gz 7.5 kB Without provenance Details for datasette-llm-embed-0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datasette-llm-embed 0.2
File Interpreter ABI Platform Actions
datasette_llm_embed-0.2-py3-none-any.whl Python 3 none any Details for datasette_llm_embed-0.2-py3-none-any.whl

Total release size: 15.0 kB

Release files / datasette-llm-embed-0.2.tar.gz

Download URL datasette-llm-embed-0.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6793b0403546188db13ebcd1d2009078bc88695418aeae4f734e45c3114e510c
BLAKE2b-256 checksum
How to use checksums
408b26e2d501ddd920eb6a0bfa0ac76499178f1eeaea7bad608fe835eaca2990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / datasette_llm_embed-0.2-py3-none-any.whl

Download URL datasette_llm_embed-0.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3474758a5d54af523c344dcf99a331ba33930e7de73d0815feee5cc352c47ff
BLAKE2b-256 checksum
How to use checksums
95eaa90fcaaa81310bf05b0d3eace0a752b6b15aa7238273a72b7c373899fea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for datasette-llm-embed 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page