Skip to main content

dirsql-plugin-embeddings

A first-party dirsql plugin for semantic search over files.

Installing the plugin loads the sqlite-vec extension (for vec_distance_cosine() and friends) and declares an embed() SQL scalar function that turns TEXT or BLOB values into embedding vectors:

uvx --with dirsql-plugin-embeddings dirsql "
  SELECT path
  FROM (SELECT path, embed(content ->> 'abstract') AS emb
        FROM './arxiv-firehose/data/**/metadata.json')
  WHERE emb IS NOT NULL
  ORDER BY vec_distance_cosine(emb, embed('local private models'))
  LIMIT 10"

WHERE emb IS NOT NULL is not optional bookkeeping: a file that is unreadable or not valid UTF-8 has NULL content, so its distance is NULL, and SQLite sorts NULLs first ascending — without the guard those files take the top slots.

For the common case — one glob, one question, top-k paths — the package is also its own command, generating and running exactly that SQL:

uvx dirsql-plugin-embeddings '**/*.md' "local private models" -k 10
  • Corpus glob: required first positional. The plugin never picks a default corpus; you always say which files are in scope. A bare glob is fine here — the command normalizes it to the ./-relative form the SQL layer requires (**/*.md./**/*.md).
  • Query text: second positional. Query text, model id, and glob are SQL-escaped into the generated query.
  • -k / --limit (both spellings, default 10): the number of results. It is exactly the SQL LIMIT of the generated query — no other cutoff exists.
  • --model <id>: templates the model id as embed()'s second argument in the generated SQL (see Model).

Results print one path<TAB>distance line per match, closest first.

Top-k is LIMIT k. sqlite-vec's MATCH ... AND k = N idiom belongs to its vec0 virtual table, which dirsql does not use. For plain expressions, sqlite-vec's own documented pattern is the one above: ORDER BY vec_distance_cosine(...) LIMIT k.

Zero cost when unused

embed() is inert until a query calls it: no worker process is spawned and no model is loaded for queries that never use it. On the first call, dirsql spawns the plugin's worker process (dirsql-plugin-embeddings worker), which serves every call of the invocation over stdin/stdout. Only the values the query actually selects are embedded — the worker receives values, not paths, and never opens files itself.

Model

Embeddings come from model2vec (static embeddings — numpy + tokenizers, no torch), defaulting to minishlab/potion-retrieval-32M. The model downloads to the standard Hugging Face cache on the first ever run (on the order of a hundred megabytes — seconds to a few minutes depending on your connection), with progress on stderr when stderr is a TTY; every later run loads it from disk.

An optional second argument overrides the model per call — the id must be model2vec-loadable (sentence-transformers/torch models are out of scope):

SELECT embed('some text', 'minishlab/potion-base-8M')

The one-liner's --model flag templates the same second argument.

Vector cache

Computed vectors are cached at ~/.cache/dirsql/embeddings/ (or $XDG_CACHE_HOME/dirsql/embeddings/ when XDG_CACHE_HOME is set), keyed by the SHA-256 of the value bytes plus the model identifier — changing either recomputes; switching models never serves stale vectors. There is no eviction: the directory is safe to wipe at any time; the only cost is re-embedding. The cache never lives inside a queried tree — the worker receives values, not paths, and writes nothing anywhere else.

Docs

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dirsql_plugin_embeddings-0.1.18.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dirsql_plugin_embeddings-0.1.18-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file dirsql_plugin_embeddings-0.1.18.tar.gz.

File metadata

File hashes

Hashes for dirsql_plugin_embeddings-0.1.18.tar.gz
Algorithm Hash digest
SHA256 ed0dd199eaabc62bc261042b6d0bc190548e87fb9468971f7c3d5828a2ef90c6
MD5 fe5e359ed6e4ac83b9d9a72c07edb7f3
BLAKE2b-256 5718907fe3778783e81dca3015144f9808811cc1c48882c98bd2b5f3766347d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirsql_plugin_embeddings-0.1.18.tar.gz:

Publisher: release.yml on thekevinscott/dirsql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dirsql_plugin_embeddings-0.1.18-py3-none-any.whl.

File metadata

File hashes

Hashes for dirsql_plugin_embeddings-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 624a7baefeb5a8d5a97ef01e46ff1e4150bcfbf14be09879f5598615af3a44e5
MD5 de13f5ddafd8e349a7097a92f03f8a20
BLAKE2b-256 52340a59768447ca6b8f8eb2c36f3f6e11686ea9bcaf48905425071436293570

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirsql_plugin_embeddings-0.1.18-py3-none-any.whl:

Publisher: release.yml on thekevinscott/dirsql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.18 This release

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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