Skip to main content

omop-emb

Vector embedding layer for OMOP CDM concepts.

omop-emb generates, stores, and retrieves embeddings for OMOP concepts. It works out of the box with sqlite-vec (no external database required) and scales to PostgreSQL/pgvector for larger deployments. The database is the source of truth — FAISS is an optional read-acceleration sidecar, not a primary store.

Installation

pip install omop-emb                         # sqlite-vec backend (default, no extras needed)
pip install "omop-emb[pgvector]"             # adds PostgreSQL/pgvector support
pip install "omop-emb[faiss-cpu]"            # adds FAISS sidecar support
pip install "omop-emb[pgvector,faiss-cpu]"   # everything

Quick start

Ingest concepts (sqlite-vec, no external service):

export OMOP_EMB_BACKEND=sqlitevec
export OMOP_EMB_SQLITE_PATH=/data/omop_emb.db
export OMOP_CDM_DB_URL=postgresql+psycopg://user:pass@host:5432/omop_cdm

omop-emb embeddings add-embeddings --api-base http://localhost:11434/v1 --api-key ollama \
    --provider ollama --model nomic-embed-text:v1.5

Search:

omop-emb embeddings search --api-base http://localhost:11434/v1 --api-key ollama \
    --provider ollama --model nomic-embed-text:v1.5 \
    --query "hypertension" --query "type 2 diabetes" \
    --standard-only --domain Condition --k 5

Ingest concepts (OpenAI-hosted model):

Configure everything once via oa-configurator (see Configuration via oa-configurator below) rather than exporting connection details and passing an API key on the command line:

omop-config configure omop_alchemy
# CDM database connection

omop-config configure omop_emb
# backend: sqlitevec
# sqlite_path: /data/omop_emb.db
# provider_type: openai
# api_base: https://api.openai.com/v1
# api_key: <your OpenAI API key>
# embedding_model: text-embedding-3-large
omop-emb embeddings add-embeddings   # backend/CDM/provider/model/api_base/api_key all resolved from config

pgvector with HNSW index:

export OMOP_EMB_BACKEND=pgvector
export OMOP_EMB_DB_HOST=localhost
export OMOP_EMB_DB_USER=omop_emb
export OMOP_EMB_DB_PASSWORD=omop_emb
export OMOP_EMB_DB_NAME=omop_emb

omop-emb embeddings add-embeddings --api-base http://localhost:11434/v1 --api-key ollama \
    --provider ollama --model nomic-embed-text:v1.5
omop-emb maintenance rebuild-index --model nomic-embed-text:v1.5 --index-type hnsw --metric-type cosine

Environment variables

Variable Default Description
OMOP_EMB_BACKEND sqlitevec Backend: sqlitevec or pgvector.
OMOP_EMB_SQLITE_PATH sqlite-vec database file path (or :memory:).
OMOP_EMB_DB_HOST pgvector: PostgreSQL host.
OMOP_EMB_DB_PORT 5432 pgvector: PostgreSQL port.
OMOP_EMB_DB_USER pgvector: database user.
OMOP_EMB_DB_PASSWORD pgvector: database password.
OMOP_EMB_DB_NAME pgvector: database name.
OMOP_EMB_DB_URL pgvector: full SQLAlchemy URL (overrides individual vars).
OMOP_CDM_DB_URL OMOP CDM connection (required for ingestion commands only).
OMOP_EMB_FAISS_CACHE_DIR Default FAISS cache directory (alternative to --faiss-cache-dir).

See the Configuration Reference for the complete list including asymmetric embedding prefixes and driver overrides.

Documentation

Full documentation: https://AustralianCancerDataNetwork.github.io/omop-emb

Roadmap

  • sqlite-vec backend (default, zero-config)
  • pgvector backend (PostgreSQL)
  • HNSW index support for pgvector
  • FAISS sidecar (approximate nearest-neighbour read acceleration)
  • Embedding bundle export / import CLI (maintenance export, maintenance import, maintenance build-faiss-cache)
  • In-DB concept filtering (domain, vocabulary, standard status, active status)
  • Transparent FAISS fast path in EmbeddingReaderInterface
  • Extensive backend and registry testing
  • FAISS GPU support
  • pgvectorscale support
  • Vector quantisation for more efficient storage

Configuration via oa-configurator

The database connection can also be configured via oa-configurator, which stores settings in ~/.config/omop/config.toml and eliminates the need for environment variables at runtime:

omop-config init
omop-config configure omop_alchemy   # CDM database (required for ingestion)
omop-config configure omop_emb       # embedding database

omop-config configure omop_emb is required for local-dev setup before running the pgvector-backed test suite (CI provisions this automatically). Without it, those tests skip with "Resource 'test_emb_db' not configured" rather than failing.

See oa-configurator Setup for details.


Docker Compose

The included docker-compose.yaml provides both a CDM PostgreSQL database and a pgvector embedding database, plus a Python container with all optional backends pre-installed ([pgvector,faiss-cpu]). Default credentials work out of the box:

docker compose up

Include Ollama by adding the standalone profile:

docker compose --profile standalone up

The python-emb service runs omop-config configure at startup. To override credentials:

cp .env.example .env
docker compose up

Download files

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

Source Distribution

omop_emb-1.2.0.tar.gz (208.8 kB view details)

Uploaded Source

Built Distribution

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

omop_emb-1.2.0-py3-none-any.whl (92.2 kB view details)

Uploaded Python 3

File details

Details for the file omop_emb-1.2.0.tar.gz.

File metadata

  • Download URL: omop_emb-1.2.0.tar.gz
  • Upload date:
  • Size: 208.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for omop_emb-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a700d0caa2822cd34f82c4d2de51a4f00eea903c34d77dd60456cdd45c4aab15
MD5 efe1f3fc1fefdf69a5a970988985799c
BLAKE2b-256 974f9d80a633a94edb562158a6c68a6758798c47e73791cc9a342ff2a7a62fcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_emb-1.2.0.tar.gz:

Publisher: publish.yml on AustralianCancerDataNetwork/omop-emb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file omop_emb-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: omop_emb-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 92.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for omop_emb-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b99bb3c188112cbac26a30fb1c805082052b5a0c4ba0463e9b9f553df210b81
MD5 90e060d393de391acb994b8630da1b30
BLAKE2b-256 23ffd19aca8829dbad9de45e0950b57fdea8e77dbfc67f4b16e54de29c764a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_emb-1.2.0-py3-none-any.whl:

Publisher: publish.yml on AustralianCancerDataNetwork/omop-emb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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