Documentation for PgvectorObjectsOptimization and PgvectorObjectPartsOptimization¶
PgvectorObjectsOptimization¶
Functionality¶
PgvectorObjectsOptimization is a base class that sets a framework for applying optimization strategies on PostgreSQL vector database object tables within pgvector collections. It encapsulates various SQL optimization statements tailored for object tables.
Motivation¶
This class is introduced to centralize and standardize SQL-based optimizations. It improves maintainability by abstracting the optimization logic for PostgreSQL tables in a pgvector context.
Inheritance¶
PgvectorObjectsOptimization inherits from the Optimization class, ensuring a common interface and extending shared optimization capabilities.
Method: _get_statement¶
This is an abstract method that must be implemented by subclasses. It takes the name of the table and should return a SQL statement for optimizing that table.
Parameters¶
tablename
: A string representing the name of the table to optimize.
Returns¶
- A SQL statement (typically wrapped as a SQLAlchemy text) that performs the optimization on the specified table.
Raises¶
NotImplementedError
: If the method is not implemented in the subclass.
Usage¶
Subclass PgvectorObjectsOptimization and implement the _get_statement method to return the SQL command for table optimization. Invoke the instance with a Collection object to apply optimization.
Example¶
class MyOptimization(PgvectorObjectsOptimization):
def _get_statement(self, tablename):
return sqlalchemy.text(f"VACUUM ANALYZE {tablename}")
PgvectorObjectPartsOptimization¶
Functionality¶
The PgvectorObjectPartsOptimization class provides an abstract framework for implementing optimization strategies for object parts tables in PostgreSQL vector databases. It allows developers to define custom SQL optimization statements that can help maintain and improve database performance by addressing issues like table fragmentation.
Motivation¶
Optimizing database tables is crucial for maintaining performance and ensuring efficient data retrieval. This class serves as a blueprint that motivates the development of concrete optimization strategies tailored to the unique requirements of object parts tables in pgvector collections.
Inheritance¶
This class inherits from the Optimization base class, leveraging its core functionality while specializing in object parts table optimization.
Method: _get_statement¶
This method is designed to generate an SQL statement for optimizing the object parts table in a PostgreSQL vector database. Subclasses should implement this method to return a specific SQL command for optimization.
Parameters¶
tablename
: str - The name of the table to optimize.
Usage¶
- Purpose: Generate and return the SQL command to optimize an object parts table.
Example¶
Below is an example implementation that overrides the abstract _get_statement method:
class CustomPartsOptimization(PgvectorObjectPartsOptimization):
def _get_statement(self, tablename):
return sqlalchemy.text(f"REINDEX TABLE {tablename}")