Text embeddings for Clojure, using local sentence-transformers ONNX exports or hosted OpenAI, Cohere, and Voyage models.
deps.edn:
net.clojars.savya/embeddings-clj {:mvn/version "0.4.0"}
Leiningen:
[net.clojars.savya/embeddings-clj "0.4.0"]
Local and hosted models implement embeddings.core/EmbeddingProvider, with
embed, embed-batch, and dimension operations.
(require '[embeddings.core :as emb]
'[embeddings.providers :as providers])
(def openai
(providers/openai {:api-key (System/getenv "OPENAI_API_KEY")
:model "text-embedding-3-small"
:dimensions 512}))
(emb/embed openai "A sentence to embed")
(def cohere
(providers/cohere {:api-key (System/getenv "COHERE_API_KEY")
:model "embed-v4.0"
:input-type "search_document"}))
(def voyage
(providers/voyage {:api-key (System/getenv "VOYAGE_API_KEY")
:model "voyage-3-large"
:input-type "query"}))
Hosted provider options include :api-key, :model, :dimensions,
:batch-size (default 128), :url for an endpoint override, and
:transport for an injectable request function. Cohere and Voyage also accept
:input-type. The transport receives {:url :method :headers :body} and must
return {:status :body}.
embeddings.core/load-model accepts the existing pooling, normalization,
maximum-length, and execution-provider options, plus:
:output-name: select a named ONNX graph output.:input-schema: map custom ONNX input names to an encoded source keyword or
{:source keyword :pad-value number}. Built-in inputs include input_ids,
attention_mask, token_type_ids, and position_ids.:output-dimensions: truncate Matryoshka embeddings to a positive dimension
no larger than the model output. Truncation happens before normalization.clojure -M:test
The unit suite runs against tiny deterministic ONNX fixtures generated by
python3 dev/gen_fixture.py (requires pip install onnx; tests skip cleanly
when fixtures are absent, so the suite is green either way).
The opt-in integration suite exercises a real all-MiniLM-L6-v2 model:
./dev/fetch-model.sh # ~90MB download from HuggingFace
clojure -M:test --focus-meta :integration
Copyright © 2026 Savyasachi.
Distributed under the Eclipse Public License 2.0.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |