Client

This module contains functionality related to the the client module for embedding.vector_stores.pgvector.

Client

PGVectorStoreClientFactory

Bases: SingletonFactory

Factory class for creating and managing a singleton instance of the PGVector database client.

This factory ensures that only one connection to the PGVector database is maintained throughout the application lifecycle, following the Singleton pattern.

Source code in src/embedding/vector_stores/pgvector/client.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class PGVectorStoreClientFactory(SingletonFactory):
    """
    Factory class for creating and managing a singleton instance of the PGVector database client.

    This factory ensures that only one connection to the PGVector database is maintained
    throughout the application lifecycle, following the Singleton pattern.
    """

    _configuration_class: Type = PGVectorStoreConfiguration

    @classmethod
    def _create_instance(
        cls, configuration: PGVectorStoreConfiguration
    ) -> PGVectorClient:
        """
        Creates a new connection to the PGVector database using the provided configuration.

        Args:
            configuration: Configuration object containing connection details and credentials
                           for the PGVector database.

        Returns:
            A connection object to the PGVector database that can be used for database operations.
        """
        return connect(
            host=configuration.host,
            port=configuration.port,
            database=configuration.database_name,
            user=configuration.secrets.username.get_secret_value(),
            password=configuration.secrets.password.get_secret_value(),
        )