Interface EmbeddingChunkRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<EmbeddingChunkEntity,Long>, DomainIdRepository<EmbeddingChunkEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<EmbeddingChunkEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<EmbeddingChunkEntity>, org.springframework.data.repository.ListCrudRepository<EmbeddingChunkEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<EmbeddingChunkEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<EmbeddingChunkEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<EmbeddingChunkEntity>, org.springframework.data.repository.Repository<EmbeddingChunkEntity,Long>

@Repository public interface EmbeddingChunkRepository extends DomainIdRepository<EmbeddingChunkEntity,Long>
Spring Data repository for EmbeddingChunkEntity. Provides JPA query methods for managing embedding chunks in the rag_embedding_chunks table. Note: the actual embedding vector storage is managed via native SQL through VectorStore.
  • Method Details

    • findByEntityTypeAndDomainIdAndSourcePathStartingWith

      List<EmbeddingChunkEntity> findByEntityTypeAndDomainIdAndSourcePathStartingWith(RagEntityType entityType, Integer domainId, String sourcePath)
    • findByEntityTypeAndEntityIdAndDomainId

      List<EmbeddingChunkEntity> findByEntityTypeAndEntityIdAndDomainId(RagEntityType entityType, Long entityId, Integer domainId)
    • deleteByEntityTypeAndEntityIdAndDomainId

      @Transactional @Modifying @Query("DELETE FROM EmbeddingChunkEntity c WHERE c.entityType = :entityType AND c.entityId = :entityId AND c.domainId = :domainId") void deleteByEntityTypeAndEntityIdAndDomainId(@Param("entityType") RagEntityType entityType, @Param("entityId") Long entityId, @Param("domainId") Integer domainId)
      Deletes all chunks for a source in one storage domain, regardless of provider or model.
      Parameters:
      entityType - source entity type
      entityId - source identifier
      domainId - storage domain, including zero for shared Markdown
    • deleteByEntityTypeAndEntityIdAndEmbeddingProviderAndEmbeddingModelAndDomainId

      @Transactional @Modifying @Query("DELETE FROM EmbeddingChunkEntity c WHERE c.entityType = :entityType AND c.entityId = :entityId AND c.embeddingProvider = :embeddingProvider AND c.embeddingModel = :embeddingModel AND c.domainId = :domainId") void deleteByEntityTypeAndEntityIdAndEmbeddingProviderAndEmbeddingModelAndDomainId(@Param("entityType") RagEntityType entityType, @Param("entityId") Long entityId, @Param("embeddingProvider") String embeddingProvider, @Param("embeddingModel") String embeddingModel, @Param("domainId") Integer domainId)
      Deletes only the selected provider and model's chunks for a source in one storage domain.
      Parameters:
      entityType - source entity type
      entityId - source identifier
      embeddingProvider - provider that generated the chunks
      embeddingModel - model that generated the chunks
      domainId - storage domain, including zero for shared Markdown
    • findDistinctEntityTypes

      @Query("SELECT DISTINCT c.entityType FROM EmbeddingChunkEntity c WHERE c.domainId = :domainId") List<RagEntityType> findDistinctEntityTypes(@Param("domainId") Integer domainId)
      Lists source types with stored chunks in the specified storage domain.
      Parameters:
      domainId - storage domain, including zero for shared Markdown
      Returns:
      distinct stored entity types
    • findDistinctEntityIdsByEntityTypeAndDomainId

      @Query("SELECT DISTINCT c.entityId FROM EmbeddingChunkEntity c WHERE c.entityType = :entityType AND c.domainId = :domainId") List<Integer> findDistinctEntityIdsByEntityTypeAndDomainId(RagEntityType entityType, Integer domainId)
      Lists distinct source IDs for document queue operations in one storage domain. The integer return type is intended for document IDs, not Markdown long identifiers.
      Parameters:
      entityType - source entity type, normally DOCUMENT
      domainId - storage domain
      Returns:
      distinct source IDs represented as integers
    • findDistinctEntityIdsByEntityTypeAndEmbeddingProviderAndEmbeddingModelAndDomainId

      @Query("SELECT DISTINCT c.entityId FROM EmbeddingChunkEntity c WHERE c.entityType = :entityType AND c.embeddingProvider = :embeddingProvider AND c.embeddingModel = :embeddingModel AND c.domainId = :domainId") List<Integer> findDistinctEntityIdsByEntityTypeAndEmbeddingProviderAndEmbeddingModelAndDomainId(@Param("entityType") RagEntityType entityType, @Param("embeddingProvider") String embeddingProvider, @Param("embeddingModel") String embeddingModel, @Param("domainId") Integer domainId)
      Lists source IDs with stored chunks from the selected provider and model. The integer return type is intended for document IDs, not Markdown long identifiers.
      Parameters:
      entityType - source entity type, normally DOCUMENT
      embeddingProvider - provider that generated the chunks
      embeddingModel - model that generated the chunks
      domainId - storage domain
      Returns:
      distinct source IDs represented as integers
    • findDistinctDocumentEntityIdsWithIncompleteGroupData

      @Query("SELECT DISTINCT c.entityId FROM EmbeddingChunkEntity c WHERE c.entityType = sk.iway.iwcm.rag.service.RagEntityType.DOCUMENT AND (c.groupId IS NULL OR c.rootGroupL1 IS NULL OR c.rootGroupL2 IS NULL OR c.rootGroupL3 IS NULL)") List<Long> findDistinctDocumentEntityIdsWithIncompleteGroupData()
      Finds documents whose stored chunks lack one or more group-scope values across all domains.
      Returns:
      distinct document IDs requiring group metadata backfill
    • updateDocumentGroupData

      @Transactional @Modifying @Query("UPDATE EmbeddingChunkEntity c SET c.groupId = :groupId, c.rootGroupL1 = :rootGroupL1, c.rootGroupL2 = :rootGroupL2, c.rootGroupL3 = :rootGroupL3 WHERE c.entityType = sk.iway.iwcm.rag.service.RagEntityType.DOCUMENT AND c.entityId = :entityId") int updateDocumentGroupData(@Param("entityId") Long entityId, @Param("groupId") Integer groupId, @Param("rootGroupL1") Integer rootGroupL1, @Param("rootGroupL2") Integer rootGroupL2, @Param("rootGroupL3") Integer rootGroupL3)
      Updates group-scope metadata on all chunks of a document across providers, models, and domains.
      Parameters:
      entityId - document ID
      groupId - immediate document group ID
      rootGroupL1 - first-level root group ID
      rootGroupL2 - second-level root group ID
      rootGroupL3 - third-level root group ID
      Returns:
      number of chunk rows updated