Class SemanticSearchService

java.lang.Object
sk.iway.iwcm.rag.search.SemanticSearchService

@Service public class SemanticSearchService extends Object
Provides shared semantic and hybrid retrieval for document and Markdown embeddings. Document searches can aggregate chunks and generate answers; source-specific callers can retrieve raw chunks for authorization and citation enrichment before generating answers.
  • Constructor Details

  • Method Details

    • search

      public List<SemanticSearchResult> search(String query, Integer domainId, String language, int maxResults, RagEntityType entityType, jakarta.servlet.http.HttpServletRequest request)
      Searches for documents similar to the query text. Returns unique document IDs ordered by their best local ranking score. Depending on component settings, vector results may be merged with full-text results. When answer generation is enabled, the sanitized answer is stored in the request attribute ragAnswer.
      Parameters:
      query - search query text
      domainId - domain to search in (null for all)
      language - language filter (null for all)
      maxResults - maximum number of unique documents to return
      entityType - entity type to filter by
      request - current request with component PageParams and rootGroup attributes
      Returns:
      document IDs with their best retrieval and rerank scores, ordered by ranking score
    • rerankChunks

      public List<VectorSearchResult> rerankChunks(String query, List<VectorSearchResult> chunks)
      Reranks authorized chunks before source aggregation and answer context selection.
      Parameters:
      query - user question
      chunks - authorized retrieval candidates
      Returns:
      all candidates ordered by retrieval score and local text matches
    • searchChunks

      public List<VectorSearchResult> searchChunks(String query, Integer domainId, String language, int maxResults, RagEntityType entityType, Map<String,Object> filters, jakarta.servlet.http.HttpServletRequest request)
      Retrieves ranked chunks using the shared embedding and optional hybrid-search pipeline. Source-specific callers supply filters before retrieval and enrich or authorize chunks before generating answers.
      Parameters:
      query - search query text
      domainId - requesting domain used for assistants and usage; Markdown storage is shared in domain zero
      language - language filter
      maxResults - desired document count used to calculate the chunk retrieval limit
      entityType - source entity type
      filters - additional vector-store filters applied before the result limit
      request - current request with optional component settings
      Returns:
      ranked chunks without answer generation or document aggregation
    • filterResultsBySimilarity

      public List<SemanticSearchResult> filterResultsBySimilarity(List<SemanticSearchResult> sortedResults, double minimumSimilarity, int minimumResultCount)
      Filters pre-sorted semantic results using absolute and adaptive similarity thresholds. Input order is preserved. Results with a similarity value are retained until the requested minimum count is reached; subsequent results must meet the effective threshold. Results without a similarity value are omitted. Local reranking changes order, while thresholds still use original retrieval similarities.
      Parameters:
      sortedResults - results ordered by descending ranking score
      minimumSimilarity - absolute similarity floor, clamped to the range 0.0–1.0
      minimumResultCount - requested minimum number of non-null-similarity results
      Returns:
      filtered results in their original order
    • isAvailable

      public boolean isAvailable()
      Checks search availability and upgrades the shared schema on first use when necessary. Migration uses global configuration and always restores the requesting domain's context.
      Returns:
      whether search can safely access the current vector schema