PostgreSQL-backed embedding cache for SentenceTransformers
Project description
Cached Sentence Transformer
PostgreSQL-backed embedding cache for SentenceTransformers.
This package provides a small wrapper that caches computed sentence embeddings in a Postgres
table keyed by a stable hash of (model, normalize flag, text), so repeated runs can reuse
stored vectors instead of recomputing them.
Installation
pip install cached-sentence-transformer
Quickstart
from cached_sentence_transformer import CachedSentenceTransformer
st = CachedSentenceTransformer(
model_name_or_path="sentence-transformers/all-MiniLM-L6-v2",
pg_dsn="host=localhost port=5432 dbname=mydb user=myuser password=mypassword",
)
emb = st.encode(["hello", "world"], normalize_embeddings=True)
st.close()
Environment-based DSN
If you do not pass pg_dsn, the wrapper will attempt to build it from environment variables
(auto loads environment variables in the .env file in the current working directory) and
will fail fast if any are missing:
PSQL_HOST_NAMEPSQL_PORTPSQL_DBNAMEPSQL_USERPSQL_PASSWORD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cached_sentence_transformer-0.1.0.tar.gz.
File metadata
- Download URL: cached_sentence_transformer-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd742fb1a4dc3d13df30c1267580d5f29b4ccb861ea018666fdc1eddff24962
|
|
| MD5 |
1cf3ecae504bfdf2a350a86d74ec7bca
|
|
| BLAKE2b-256 |
52e8d622bbe4eac5d126418036d45cadde60f59e253483cf4acf6f2dd59f91cf
|
File details
Details for the file cached_sentence_transformer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cached_sentence_transformer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aeb67dadc5aecd8432cb5903f7ff84bb26161ae6c20c97c7109807b48e9e80c
|
|
| MD5 |
c0ce904ee528a24041bb9f9306862966
|
|
| BLAKE2b-256 |
8dec9f88a46f551c2f56e3b22026bfab60304afd8bfeac6b981bea187f86eb40
|