Package sk.iway.iwcm.rag.vectorstore
Interface VectorStore
- All Known Implementing Classes:
MariaDbVectorStore,PgVectorStore,VectorStoreRouter
public interface VectorStore
Abstraction for vector storage and similarity search.
Handles ONLY native vector storage and search operations.
Entity CRUD operations are handled by EmbeddingChunkRepository (JPA).
-
Method Summary
Modifier and TypeMethodDescriptiongetExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId) Get existing embeddings for an entity and domain, keyed by content hash.booleanInitialize the database-specific vector schema if needed.booleanCheck if the vector store can be used in the current runtime configuration.booleanCheck if the vector store is available and schema is initialized.default booleanRecreate the database-specific vector index using the configured metric.booleanresetDimensions(int dimensions) Delete all stored embeddings and resize the vector column.search(float[] queryEmbedding, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String, Object> bonusParams) Find the most similar chunks to the query embedding.searchFulltext(String query, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String, Object> bonusParams) Find relevant chunks by fulltext search in chunk text.voidupdateEmbedding(Long id, float[] embedding) Update the embedding vector for an existing chunk entity.voidupdateEmbeddingBatch(List<Long> ids, List<float[]> embeddings) Update embedding vectors for multiple existing chunk entities in a batch.
-
Method Details
-
updateEmbedding
Update the embedding vector for an existing chunk entity. The entity must already be saved via EmbeddingChunkRepository.- Parameters:
id- the chunk entity IDembedding- the embedding vector
-
updateEmbeddingBatch
Update embedding vectors for multiple existing chunk entities in a batch. All entities must already be saved via EmbeddingChunkRepository.- Parameters:
ids- the chunk entity IDsembeddings- the embedding vectors (must match ids in size and order)
-
search
List<VectorSearchResult> search(float[] queryEmbedding, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String, Object> bonusParams) Find the most similar chunks to the query embedding.- Parameters:
queryEmbedding- the query vectorembeddingProvider- provider used to generate/query embeddingsembeddingModel- model used to generate/query embeddingsentityType- 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 resultsbonusParams- optional store-specific filters, such as document root groups- Returns:
- list of search results ordered by similarity (descending)
-
searchFulltext
List<VectorSearchResult> searchFulltext(String query, String embeddingProvider, String embeddingModel, RagEntityType entityType, Integer domainId, String language, int limit, Map<String, Object> bonusParams) Find relevant chunks by fulltext search in chunk text.- Parameters:
query- textual queryembeddingProvider- provider used to filter rowsembeddingModel- model used to filter rowsentityType- 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 resultsbonusParams- optional store-specific filters, such as document root groups and fallback flags- Returns:
- list of search results ordered by fulltext rank (descending)
-
isAvailable
boolean isAvailable()Check if the vector store can be used in the current runtime configuration. This does not guarantee that required schema objects already exist. -
isAvailableAndInitialized
boolean isAvailableAndInitialized()Check if the vector store is available and schema is initialized. Implementations should return true only when operations can be executed safely. -
initializeSchema
boolean initializeSchema()Initialize the database-specific vector schema if needed. -
recreateIndex
default boolean recreateIndex()Recreate the database-specific vector index using the configured metric. Implementations without a native index-management capability may keep the default.- Returns:
- true when the index was recreated successfully
-
resetDimensions
boolean resetDimensions(int dimensions) Delete all stored embeddings and resize the vector column.- Parameters:
dimensions- new vector dimensions
-
getExistingEmbeddingsByHash
Map<String,float[]> getExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId) Get existing embeddings for an entity and domain, keyed by content hash. Used to skip re-embedding unchanged chunks.- Parameters:
entityType- entity type of the indexed objectentityId- ID of the indexed objectembeddingProvider- provider that generated the embeddingsembeddingModel- model that generated the embeddingsdomainId- domain that owns the indexed object- Returns:
- existing embeddings keyed by content hash
-