DB utils

Classes

PGConnector

class PGConnector:
    db_user: str,
    db_password: str,
    db_host: str,
    db_port: int,
    db_name: str,
    db_schema: str,
    logger: Logger,
    embeddings_table_name: str = "embeddings",

Configures a connection to a postgresql database with pgvector

ParameterTypeDescription
db_userstrThe user for the postgres connection URL
db_passwordstrThe password for the postgres connection URL
db_hoststrThe host for the postgres connection URL
db_portintThe port for the postgres connection URL
db_namestrThe database name for the postgres connection URL
db_schemastrThe name of the database schema to use
loggerlogging.LoggerLogging for database interactions
embeddings_table_namestrThe name for the embeddings table in the specified schema
PropertyDescription
db_schemaThe name of the database schema used
embeddings_table_nameThe name of the embeddings table

Methods

check_extension
check_extension() -> None:

Check whether the connected database has the pgvector extension installed

reset_embedding_table
reset_embedding_table() -> None:

Drop any existing embedding table, then create a new one with the right vector dimension

ParameterTypeDescription
embedding_dimensionintThe table needs a specified dimension for the embeddings
get_connection
get_connection() -> psycopg.Connection

Return a configured connection