dd-embed
Shared embedding model abstraction layer for Digital Duck projects.
Extracted from semanscope and maniscope. Zero heavy deps in core (only numpy). Adapters lazy-import their SDKs only when used.
Install
pip install dd-embed # numpy only
pip install "dd-embed[sentence-transformers]" # + sentence-transformers
pip install "dd-embed[openai]" # + OpenAI SDK (also covers openrouter)
pip install "dd-embed[voyageai]" # + Voyage AI SDK
pip install "dd-embed[gemini]" # + Google GenAI SDK
pip install "dd-embed[all]" # all provider SDKs
Quick Start
from dd_embed import embed
# Using sentence-transformers (local, free)
embeddings = embed(["hello", "world"], provider="sentence_transformers",
model_name="all-MiniLM-L6-v2")
print(embeddings.shape) # (2, 384)
# Using OpenAI
embeddings = embed(["hello"], provider="openai", api_key="sk-...")
# Using Ollama (local)
embeddings = embed(["hello"], provider="ollama", model_name="bge-m3")
Built-in Adapters
| Name | Class | SDK | Notes |
|---|---|---|---|
sentence_transformers |
SentenceTransformerAdapter |
sentence-transformers |
Local, free, used by maniscope |
huggingface |
HuggingFaceAdapter |
transformers + torch |
AutoModel + mean pooling, E5/Qwen support |
ollama |
OllamaEmbedAdapter |
requests |
Local Ollama server |
openai |
OpenAIEmbedAdapter |
openai |
OpenAI embeddings API |
openrouter |
OpenAIEmbedAdapter (configured) |
openai |
OpenAI-compat endpoint |
gemini |
GeminiEmbedAdapter |
google-generativeai |
Google Gemini embeddings |
voyage |
VoyageEmbedAdapter |
voyageai |
Voyage AI embeddings |
Embedding Cache
Disk-persistent, per-word granular cache (ported from semanscope):
from dd_embed import EmbeddingCache, get_adapter
cache = EmbeddingCache() # default: ~/projects/embedding_cache/dd_embed/master.pkl
adapter = get_adapter("sentence_transformers", model_name="all-MiniLM-L6-v2")
embeddings, cached, computed = cache.get_embeddings(
texts=["apple", "banana", "cherry"],
model_name="all-MiniLM-L6-v2",
scope="en",
embed_fn=lambda texts: adapter.embed(texts).embeddings,
)
print(f"Cached: {cached}, Computed: {computed}")
cache.save()
Custom Adapters
from dd_embed import EmbeddingAdapter, EmbeddingResult, register_adapter, embed
import numpy as np
class MyAdapter(EmbeddingAdapter):
def embed(self, texts, **kwargs):
vecs = np.random.randn(len(texts), 128) # your logic here
return EmbeddingResult(
embeddings=vecs, success=True, provider="my_api",
model="v1", dimensions=128, num_texts=len(texts),
)
register_adapter("my_api", MyAdapter)
result = embed(["hello"], provider="my_api")
Environment Variables
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key | -- |
OPENROUTER_API_KEY |
OpenRouter API key | -- |
GEMINI_API_KEY |
Google Gemini API key | -- |
VOYAGE_API_KEY |
Voyage AI API key | -- |
OLLAMA_HOST |
Ollama server URL | http://localhost:11434 |
License
MIT
Metadata
Release files for dd-embed 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dd_embed-0.1.0.tar.gz | 14.7 kB | Without provenance | Details for dd_embed-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dd_embed-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dd_embed-0.1.0-py3-none-any.whl |
Total release size: 31.0 kB
Release files / dd_embed-0.1.0.tar.gz
| Download URL | dd_embed-0.1.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f39ef28fb5f3226c18746cdf608d9af4b319c669a1d1f117593851781148525
|
|
BLAKE2b-256 checksum How to use checksums |
265e3fa85b67e5b831c6eec1e340f2ac3741dcda21989547088cd181c6e3b4f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / dd_embed-0.1.0-py3-none-any.whl
| Download URL | dd_embed-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
002bce40cbc0bea2074e728d005a323586c391bf9d0042cb8b809552c41661d6
|
|
BLAKE2b-256 checksum How to use checksums |
4579aedf343e0f727fda4def760e15e1c84677699993d7340528c39f518df594
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for dd-embed 0.1.0
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.