Package sk.iway.iwcm.rag.vectorstore
Class PgVectorStore
java.lang.Object
sk.iway.iwcm.rag.vectorstore.PgVectorStore
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetExistingEmbeddingsByHash(String entityType, long entityId, String embeddingProvider, String embeddingModel) Deprecated.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.booleanInitialize the pgvector extension and create the table 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 HNSW index according to configured distance 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 pgvector extension and create the table if needed.- Specified by:
initializeSchemain interfaceVectorStore
-
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:
getExistingEmbeddingsByHashin interfaceVectorStore- Parameters:
entityType- entity type of the indexed objectentityId- ID of the indexed objectembeddingProvider- provider that generated the embeddingsembeddingModel- 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:
getExistingEmbeddingsByHashin interfaceVectorStore- 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
-
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
-