Back to Feast

PostgreSQL online store

docs/reference/online-stores/postgres.md

0.63.04.2 KB
Original Source

PostgreSQL online store

Description

The PostgreSQL online store provides support for materializing feature values into a PostgreSQL database for serving online features.

  • Only the latest feature values are persisted

  • sslmode defaults to require, which encrypts the connection without certificate verification. To disable SSL (e.g. for local development), set sslmode: disable. For certificate verification, set sslmode to verify-ca or verify-full and provide the corresponding sslrootcert_path (and optionally sslcert_path and sslkey_path for mutual TLS)

Getting started

In order to use this online store, you'll need to run pip install 'feast[postgres]'. You can get started by then running feast init -t postgres.

Example

{% code title="feature_store.yaml" %}

yaml
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
    type: postgres
    host: DB_HOST
    port: DB_PORT
    database: DB_NAME
    db_schema: DB_SCHEMA
    user: DB_USERNAME
    password: DB_PASSWORD
    sslmode: verify-ca
    sslkey_path: /path/to/client-key.pem
    sslcert_path: /path/to/client-cert.pem
    sslrootcert_path: /path/to/server-ca.pem
    vector_enabled: false

{% endcode %}

The full set of configuration options is available in PostgreSQLOnlineStoreConfig.

Functionality Matrix

The set of functionality supported by online stores is described in detail here. Below is a matrix indicating which functionality is supported by the Postgres online store.

Postgres
write feature values to the online storeyes
read feature values from the online storeyes
update infrastructure (e.g. tables) in the online storeyes
teardown infrastructure (e.g. tables) in the online storeyes
generate a plan of infrastructure changesno
support for on-demand transformsyes
readable by Python SDKyes
readable by Javano
readable by Gono
support for entityless feature viewsyes
support for concurrent writing to the same keyno
support for ttl (time to live) at retrievalno
support for deleting expired datano
collocated by feature viewyes
collocated by feature serviceno
collocated by entity keyno

To compare this set of functionality against other online stores, please see the full functionality matrix.

PGVector

The Postgres online store supports the use of PGVector for storing feature values. To enable PGVector, set vector_enabled: true in the online store configuration.

The vector_length parameter can be used to specify the length of the vector in the Field.

Please make sure to follow the instructions in the repository, which, as the time of this writing, requires you to run CREATE EXTENSION vector; in the database.

Then you can use retrieve_online_documents to retrieve the top k closest vectors to a query vector. For the Retrieval Augmented Generation (RAG) use-case, you have to embed the query prior to passing the query vector.

{% code title="python" %}

python
from feast import FeatureStore
from feast.infra.online_stores.postgres_online_store import retrieve_online_documents

feature_store = FeatureStore(repo_path=".")

query_vector = [0.1, 0.2, 0.3, 0.4, 0.5]
top_k = 5

feature_values = retrieve_online_documents(
    feature_store=feature_store,
    feature_view_name="document_fv:embedding_float",
    query_vector=query_vector,
    top_k=top_k,
)

{% endcode %}