Class MariaDbVectorStore

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

@Service public class MariaDbVectorStore extends Object implements VectorStore
MariaDB implementation of VectorStore using the native VECTOR type. Chunk metadata remains in rag_embedding_chunks; non-null vectors are stored separately so failed and pending chunks can remain vectorless.
  • Constructor Details

    • MariaDbVectorStore

      public MariaDbVectorStore()
  • 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 database-specific vector schema if needed.
      Specified by:
      initializeSchema in interface VectorStore
    • recreateIndex

      public boolean recreateIndex()
      Description copied from interface: VectorStore
      Recreate the database-specific vector index using the configured metric. Implementations without a native index-management capability may keep the default.
      Specified by:
      recreateIndex in interface VectorStore
      Returns:
      true when the index was recreated successfully
    • 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
    • getExistingEmbeddingsByHash

      public Map<String,float[]> getExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId)
      Description copied from interface: VectorStore
      Get existing embeddings for an entity and domain, keyed by content hash. Used 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
    • getConnection

      protected Connection getConnection(String dataSourceName) throws SQLException
      Obtains a pooled connection and rejects a missing connection explicitly.
      Parameters:
      dataSourceName - resolved RAG datasource name
      Returns:
      open connection that the caller must close
      Throws:
      SQLException - if a connection cannot be obtained