Class PgVectorStore

java.lang.Object
sk.iway.iwcm.rag.vectorstore.PgVectorStore
All Implemented Interfaces:
VectorStore

@Service public class PgVectorStore extends Object implements VectorStore
PgVector implementation of VectorStore. Handles ONLY the embedding (vector) column via native SQL using pgvector operators. Entity CRUD operations are handled by EmbeddingChunkRepository (JPA). Connects to the RAG datasource (primary PgSQL or secondary rag_jpa).
  • Constructor Details

    • PgVectorStore

      public PgVectorStore()
  • Method Details

    • updateEmbedding

      public void updateEmbedding(Long id, float[] embedding)
      Description copied from interface: VectorStore
      Update the embedding vector for an existing chunk entity. The entity must already be saved via EmbeddingChunkRepository.
      Specified by:
      updateEmbedding in interface VectorStore
      Parameters:
      id - the chunk entity ID
      embedding - the embedding vector
    • updateEmbeddingBatch

      public void updateEmbeddingBatch(List<Long> ids, List<float[]> embeddings)
      Description copied from interface: VectorStore
      Update embedding vectors for multiple existing chunk entities in a batch. All entities must already be saved via EmbeddingChunkRepository.
      Specified by:
      updateEmbeddingBatch in interface VectorStore
      Parameters:
      ids - the chunk entity IDs
      embeddings - the embedding vectors (must match ids in size and order)
    • search

      public List<VectorSearchResult> search(float[] queryEmbedding, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String,Object> bonusParams)
      Description copied from interface: VectorStore
      Find the most similar chunks to the query embedding.
      Specified by:
      search in interface VectorStore
      Parameters:
      queryEmbedding - the query vector
      embeddingProvider - provider used to generate/query embeddings
      embeddingModel - model used to generate/query embeddings
      entityType - entity type to filter by (null for all)
      domainId - domain ID to filter by (null for all)
      language - language to filter by (null for all)
      limit - max number of results
      bonusParams - optional store-specific filters, such as document root groups
      Returns:
      list of search results ordered by similarity (descending)
    • searchFulltext

      public List<VectorSearchResult> searchFulltext(String query, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String,Object> bonusParams)
      Description copied from interface: VectorStore
      Find relevant chunks by fulltext search in chunk text.
      Specified by:
      searchFulltext in interface VectorStore
      Parameters:
      query - textual query
      embeddingProvider - provider used to filter rows
      embeddingModel - model used to filter rows
      entityType - entity type to filter by (null for all)
      domainId - domain ID to filter by (null for all)
      language - language to filter by (null for all)
      limit - max number of results
      bonusParams - optional store-specific filters, such as document root groups and fallback flags
      Returns:
      list of search results ordered by fulltext rank (descending)
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: VectorStore
      Check if the vector store can be used in the current runtime configuration. This does not guarantee that required schema objects already exist.
      Specified by:
      isAvailable in interface VectorStore
    • isAvailableAndInitialized

      public boolean isAvailableAndInitialized()
      Description copied from interface: VectorStore
      Check if the vector store is available and schema is initialized. Implementations should return true only when operations can be executed safely.
      Specified by:
      isAvailableAndInitialized in interface VectorStore
    • initializeSchema

      public boolean initializeSchema()
      Description copied from interface: VectorStore
      Initialize the pgvector extension and create the table if needed.
      Specified by:
      initializeSchema in interface VectorStore
    • recreateHnswIndex

      public boolean recreateHnswIndex()
      Recreates HNSW index according to configured distance metric.
    • getExistingEmbeddingsByHash

      @Deprecated(forRemoval=false) public Map<String,float[]> getExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel)
      Deprecated.
      Get existing embeddings for an entity, keyed by content hash.
      Specified by:
      getExistingEmbeddingsByHash in interface VectorStore
      Parameters:
      entityType - entity type of the indexed object
      entityId - ID of the indexed object
      embeddingProvider - provider that generated the embeddings
      embeddingModel - model that generated the embeddings
      Returns:
      existing embeddings keyed by content hash
    • getExistingEmbeddingsByHash

      public Map<String,float[]> getExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId)
      Fetches existing content hashes and embedding vectors for an entity and domain, allowing the indexer to skip re-embedding unchanged chunks.
      Specified by:
      getExistingEmbeddingsByHash in interface VectorStore
      Parameters:
      entityType - entity type of the indexed object
      entityId - ID of the indexed object
      embeddingProvider - provider that generated the embeddings
      embeddingModel - model that generated the embeddings
      domainId - domain that owns the indexed object
      Returns:
      existing embeddings keyed by content hash
    • resetDimensions

      public boolean resetDimensions(int dimensions)
      Description copied from interface: VectorStore
      Delete all stored embeddings and resize the vector column.
      Specified by:
      resetDimensions in interface VectorStore
      Parameters:
      dimensions - new vector dimensions