Skip to main content

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_NAME
  • PSQL_PORT
  • PSQL_DBNAME
  • PSQL_USER
  • PSQL_PASSWORD

Project details


Download files

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

Source Distribution

cached_sentence_transformer-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

cached_sentence_transformer-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file cached_sentence_transformer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for cached_sentence_transformer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbd742fb1a4dc3d13df30c1267580d5f29b4ccb861ea018666fdc1eddff24962
MD5 1cf3ecae504bfdf2a350a86d74ec7bca
BLAKE2b-256 52e8d622bbe4eac5d126418036d45cadde60f59e253483cf4acf6f2dd59f91cf

See more details on using hashes here.

File details

Details for the file cached_sentence_transformer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cached_sentence_transformer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aeb67dadc5aecd8432cb5903f7ff84bb26161ae6c20c97c7109807b48e9e80c
MD5 c0ce904ee528a24041bb9f9306862966
BLAKE2b-256 8dec9f88a46f551c2f56e3b22026bfab60304afd8bfeac6b981bea187f86eb40

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page