Class PostgresVectorStore

java.lang.Object
com.google.genkit.plugins.postgresql.PostgresVectorStore

public class PostgresVectorStore extends Object
PostgreSQL vector store implementation using pgvector extension.

This class provides indexing and retrieval of documents using PostgreSQL with the pgvector extension for vector similarity search.

  • Constructor Details

    • PostgresVectorStore

      public PostgresVectorStore(DataSource dataSource, PostgresTableConfig config, Embedder embedder)
      Creates a new PostgresVectorStore.
      Parameters:
      dataSource - the PostgreSQL data source
      config - the table configuration
      embedder - the embedder for generating vectors
  • Method Details

    • initialize

      public void initialize() throws SQLException
      Initializes the vector store by creating the table and index if needed.
      Throws:
      SQLException
    • retrieve

      public RetrieverResponse retrieve(ActionContext context, RetrieverRequest request)
      Retrieves documents similar to the query.
      Parameters:
      context - the action context
      request - the retriever request
      Returns:
      the retriever response with matching documents
    • index

      public IndexerResponse index(ActionContext context, IndexerRequest request)
      Indexes documents into the vector store.
      Parameters:
      context - the action context
      request - the indexer request
      Returns:
      the indexer response
    • deleteByIds

      public int deleteByIds(List<String> ids) throws SQLException
      Deletes documents by their IDs.
      Parameters:
      ids - the document IDs to delete
      Returns:
      the number of documents deleted
      Throws:
      SQLException
    • clearAll

      public int clearAll() throws SQLException
      Clears all documents from the table.
      Returns:
      the number of documents deleted
      Throws:
      SQLException
    • getConfig

      public PostgresTableConfig getConfig()
      Gets the table configuration.
    • getDataSource

      public DataSource getDataSource()
      Gets the data source.