Package sk.iway.iwcm.rag.vectorstore
Class PgVectorStore
java.lang.Object
sk.iway.iwcm.rag.vectorstore.PgVectorStore
- All Implemented Interfaces:
VectorStore
Stores and searches embeddings in PostgreSQL using pgvector and native full-text queries.
Manages vector updates and schema initialization while normal chunk persistence uses the JPA repository.
Connects to the resolved RAG datasource, either the primary PostgreSQL database or
rag_jpa.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId) Fetches completed embeddings for content reuse within one source, provider, model, and domain.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.booleanRecreates the PostgreSQL HNSW index according to configured distance metric.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.
-
Constructor Details
-
PgVectorStore
public PgVectorStore()
-
-
Method Details
-
updateEmbedding
Description copied from interface:VectorStoreUpdate the embedding vector for an existing chunk entity. The entity must already be saved via EmbeddingChunkRepository.- Specified by:
updateEmbeddingin interfaceVectorStore- Parameters:
id- the chunk entity IDembedding- the embedding vector
-
updateEmbeddingBatch
Description copied from interface:VectorStoreUpdate embedding vectors for multiple existing chunk entities in a batch. All entities must already be saved via EmbeddingChunkRepository.- Specified by:
updateEmbeddingBatchin interfaceVectorStore- Parameters:
ids- the chunk entity IDsembeddings- 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:VectorStoreFind the most similar chunks to the query embedding.- Specified by:
searchin interfaceVectorStore- 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
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:VectorStoreFind relevant chunks by fulltext search in chunk text.- Specified by:
searchFulltextin interfaceVectorStore- 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
public boolean isAvailable()Description copied from interface:VectorStoreCheck if the vector store can be used in the current runtime configuration. This does not guarantee that required schema objects already exist.- Specified by:
isAvailablein interfaceVectorStore
-
isAvailableAndInitialized
public boolean isAvailableAndInitialized()Description copied from interface:VectorStoreCheck if the vector store is available and schema is initialized. Implementations should return true only when operations can be executed safely.- Specified by:
isAvailableAndInitializedin interfaceVectorStore
-
initializeSchema
public boolean initializeSchema()Description copied from interface:VectorStoreInitialize the database-specific vector schema if needed.- Specified by:
initializeSchemain interfaceVectorStore
-
recreateIndex
public boolean recreateIndex()Recreate the database-specific vector index using the configured metric. Implementations without a native index-management capability may keep the default.- Specified by:
recreateIndexin interfaceVectorStore- Returns:
- true when the index was recreated successfully
-
recreateHnswIndex
public boolean recreateHnswIndex()Recreates the PostgreSQL HNSW index according to configured distance metric.- Returns:
- true when the index was recreated successfully
-
getExistingEmbeddingsByHash
public Map<String,float[]> getExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel, int domainId) Fetches completed embeddings for content reuse within one source, provider, model, and domain.- Specified by:
getExistingEmbeddingsByHashin interfaceVectorStore- Parameters:
entityType- stored source entity typeentityId- source identifierembeddingProvider- provider that generated the vectorsembeddingModel- model that generated the vectorsdomainId- storage domain, including zero for shared Markdown- Returns:
- vectors keyed by content hash, or an empty map when the datasource or query is unavailable
-
resetDimensions
public boolean resetDimensions(int dimensions) Description copied from interface:VectorStoreDelete all stored embeddings and resize the vector column.- Specified by:
resetDimensionsin interfaceVectorStore- Parameters:
dimensions- new vector dimensions
-