EmbedPrefix
A lightweight Python utility for managing embedding prefixes across different embedding models.
Many embedding models require specific prefixes (e.g. query:, passage:, search_document:) depending on the task being performed. EmbedPrefix provides a simple interface for registering those prefixes and applying them consistently.
Features
- Simple API
- Multiple prefix strategies per model
- Configurable prefix position (
startorend) - Optional separators
- Built-in loaders for common embedding models
- Easy to extend for custom models
Installation
Clone the repository:
pip install embedsavior
No external dependencies are required.
Quick Start
IntFloat E5
from embedprefix import EmbedPrefixLoaders
emb = EmbedPrefixLoaders.load_intfloat_e5()
query = emb.capsule(
"What is artificial intelligence?",
strategy="query"
)
document = emb.capsule(
"Artificial intelligence is a branch of computer science.",
strategy="input"
)
print(query)
# query: What is artificial intelligence?
print(document)
# passage: Artificial intelligence is a branch of computer science.
Nomic Embed
from embedprefix import EmbedPrefixLoaders
emb = EmbedPrefixLoaders.load_nomic()
query = emb.capsule(
"What is machine learning?",
strategy="query"
)
document = emb.capsule(
"Machine learning is a field of AI.",
strategy="input"
)
print(query)
# search_query: What is machine learning?
print(document)
# search_document: Machine learning is a field of AI.
Creating Your Own Configuration
from embedprefix import EmbedPrefix
emb = EmbedPrefix("my-model")
emb.add_prefix(
prefix="[QUERY]",
name="query",
position="start",
sep=" "
)
emb.add_prefix(
prefix="[DOC]",
name="document",
position="start",
sep=" "
)
text = emb.capsule(
"Hello world",
strategy="query"
)
print(text)
# [QUERY] Hello world
API
EmbedPrefix
Represents a collection of prefix strategies for a single embedding model.
Constructor
EmbedPrefix(model_name: str)
add_prefix(...)
Registers a new prefix strategy.
add_prefix(
prefix: str,
name: str,
position: Literal["start", "end"],
sep: str = "",
set_default: bool = False,
force: bool = False
)
Parameters
| Parameter | Description |
|---|---|
prefix |
Prefix string. |
name |
Strategy name. |
position |
Prefix placement (start or end). |
sep |
Separator between prefix and text. |
set_default |
Marks this strategy as the default. |
force |
Overwrites an existing strategy with the same name. |
capsule(...)
Applies a prefix strategy to a text.
capsule(
text: str,
strategy: str | None = None
)
Returns a prefixed string.
list_strategies()
Returns all registered strategy names.
strategies = emb.list_strategies()
Example
['query', 'input']
Built-in Loaders
IntFloat E5
EmbedPrefixLoaders.load_intfloat_e5()
Registered strategies
| Strategy | Prefix |
|---|---|
query |
query: |
input |
passage: |
Nomic Embed
EmbedPrefixLoaders.load_nomic()
Registered strategies
| Strategy | Prefix |
|---|---|
query |
search_query: |
input |
search_document: |
cluster |
clustering: |
clf |
classification: |
Supported Models
Currently included:
- IntFloat E5
- Nomic Embed
Additional loaders can easily be implemented for other embedding models.
License
This project is released under the Apache License.
Metadata
Release files for embedsavior 1.0.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 |
|---|---|---|---|---|
| embedsavior-1.0.0.tar.gz | 4.9 kB | Without provenance | Details for embedsavior-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| embedsavior-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for embedsavior-1.0.0-py3-none-any.whl |
Total release size: 10.1 kB
Release files / embedsavior-1.0.0.tar.gz
| Download URL | embedsavior-1.0.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c57cd4b2a6ff47cbce70f576d795258ec394bec49065fb88a454c6bc9ad48ab8
|
|
BLAKE2b-256 checksum How to use checksums |
e345810138785b4ad133bc3301e7445bb450fe92cd08b40b5f31aa831cab303d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / embedsavior-1.0.0-py3-none-any.whl
| Download URL | embedsavior-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aadae0efe3502d9406ace73d51cb651ffcba1a8dc7f6d9bab0365b705127fc9c
|
|
BLAKE2b-256 checksum How to use checksums |
1b2614508ea883f77c21b661233bf67e2cee115798cd22275473cf731b91ec15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for embedsavior 1.0.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.