Validator

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

Validator

PGVectorStoreValidator

Bases: BaseVectorStoreValidator

Validator for Postgres vector store configuration.

Validates the existence of a table (treated as a collection) in the Postgres vector store backend. This validator ensures we don't create duplicate tables in the database.

Source code in src/embedding/vector_stores/pgvector/validator.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class PGVectorStoreValidator(BaseVectorStoreValidator):
    """Validator for Postgres vector store configuration.

    Validates the existence of a table (treated as a collection) in the Postgres
    vector store backend. This validator ensures we don't create duplicate tables
    in the database.
    """

    def __init__(
        self,
        configuration: PGVectorStoreConfiguration,
        client: PGVectorClient,
    ):
        """Initialize the PGVector validator with configuration and client.

        Args:
            configuration: Configuration for the PGVector store
            client: PostgreSQL connection client
        """
        self.configuration = configuration
        self.client = client

    def validate(self) -> None:
        """Validate the PGVector configuration settings.

        Runs all validation checks to ensure the vector store can be properly initialized.

        Raises:
            CollectionExistsException: If the collection already exists in database
        """
        self.validate_collection()

    def validate_collection(self) -> None:
        """Validate that the PGVector collection (table) doesn't already exist.

        Checks if a table with the same name exists in the PostgreSQL database
        to prevent duplicate collections.

        Raises:
            CollectionExistsException: If the table (collection) already exists.
        """
        collection_name = self.configuration.collection_name
        with self.client.cursor() as cursor:
            query = f"SELECT to_regclass('data_{collection_name}');"
            cursor.execute(query)
            result = cursor.fetchone()[0]
            if result is not None:
                raise CollectionExistsException(collection_name)

__init__(configuration, client)

Initialize the PGVector validator with configuration and client.

Parameters:
  • configuration (PGVectorStoreConfiguration) –

    Configuration for the PGVector store

  • client (connection) –

    PostgreSQL connection client

Source code in src/embedding/vector_stores/pgvector/validator.py
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(
    self,
    configuration: PGVectorStoreConfiguration,
    client: PGVectorClient,
):
    """Initialize the PGVector validator with configuration and client.

    Args:
        configuration: Configuration for the PGVector store
        client: PostgreSQL connection client
    """
    self.configuration = configuration
    self.client = client

validate()

Validate the PGVector configuration settings.

Runs all validation checks to ensure the vector store can be properly initialized.

Raises:
  • CollectionExistsException

    If the collection already exists in database

Source code in src/embedding/vector_stores/pgvector/validator.py
36
37
38
39
40
41
42
43
44
def validate(self) -> None:
    """Validate the PGVector configuration settings.

    Runs all validation checks to ensure the vector store can be properly initialized.

    Raises:
        CollectionExistsException: If the collection already exists in database
    """
    self.validate_collection()

validate_collection()

Validate that the PGVector collection (table) doesn't already exist.

Checks if a table with the same name exists in the PostgreSQL database to prevent duplicate collections.

Raises:
  • CollectionExistsException

    If the table (collection) already exists.

Source code in src/embedding/vector_stores/pgvector/validator.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def validate_collection(self) -> None:
    """Validate that the PGVector collection (table) doesn't already exist.

    Checks if a table with the same name exists in the PostgreSQL database
    to prevent duplicate collections.

    Raises:
        CollectionExistsException: If the table (collection) already exists.
    """
    collection_name = self.configuration.collection_name
    with self.client.cursor() as cursor:
        query = f"SELECT to_regclass('data_{collection_name}');"
        cursor.execute(query)
        result = cursor.fetchone()[0]
        if result is not None:
            raise CollectionExistsException(collection_name)

PGVectorStoreValidatorFactory

Bases: SingletonFactory

Factory for creating configured PGVector store validators.

Creates and manages singleton instances of validators for PostgreSQL vector store backends.

Attributes:
  • _configuration_class (Type) –

    Type of the configuration class used for validation.

Source code in src/embedding/vector_stores/pgvector/validator.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class PGVectorStoreValidatorFactory(SingletonFactory):
    """Factory for creating configured PGVector store validators.

    Creates and manages singleton instances of validators for PostgreSQL
    vector store backends.

    Attributes:
        _configuration_class: Type of the configuration class used for validation.
    """

    _configuration_class: Type = PGVectorStoreConfiguration

    @classmethod
    def _create_instance(
        cls, configuration: PGVectorStoreConfiguration
    ) -> PGVectorStoreValidator:
        """Creates a PGVector validator based on provided configuration.

        Args:
            configuration: PostgreSQL vector store connection configuration.

        Returns:
            PGVectorStoreValidator: Configured validator instance.
        """
        client = PGVectorStoreClientFactory.create(configuration)
        return PGVectorStoreValidator(
            configuration=configuration, client=client
        )