PgVectorStorage is an implementation of BaseVectorStorage for PostgreSQL with pgvector extension.
This class provides methods to add, delete, query, and manage vector records in a PostgreSQL database using the pgvector extension. It supports different distance metrics for similarity search.
Parameters:
None
)VectorDistance.COSINE
)Initialize PgVectorStorage.
Parameters:
None
)VectorDistance.COSINE
)Ensure the vector table exists in the database. Creates the table if it does not exist.
Ensure vector similarity search index exists for better performance.
Add or update vector records in the database.
Parameters:
Delete vector records from the database by their IDs.
Parameters:
Query the database for the most similar vectors to the given query vector.
Parameters:
Returns:
List[VectorDBQueryResult]: List of query results sorted by similarity.
Get the status of the vector database, including vector dimension and count.
Returns:
VectorDBStatus: Status object with vector dimension and count.
Remove all vectors from the storage by truncating the table.
Load the collection hosted on cloud service (no-op for pgvector). This method is provided for interface compatibility.
Close the database connection.
Ensure connection is closed when object is destroyed.
Returns:
Any: The underlying psycopg connection object.