Package sk.iway.iwcm.rag.search
Class SemanticSearchService
java.lang.Object
sk.iway.iwcm.rag.search.SemanticSearchService
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 Summary
ConstructorsConstructorDescriptionSemanticSearchService(EmbeddingService embeddingService, VectorStore vectorStore, RagEmbeddingStatService ragEmbeddingStatService, RagService ragService, RerankerService rerankerService) -
Method Summary
Modifier and TypeMethodDescriptionfilterResultsBySimilarity(List<SemanticSearchResult> sortedResults, double minimumSimilarity, int minimumResultCount) Filters pre-sorted semantic results using absolute and adaptive similarity thresholds.booleanChecks search availability and upgrades the shared schema on first use when necessary.rerankChunks(String query, List<VectorSearchResult> chunks) Reranks authorized chunks before source aggregation and answer context selection.search(String query, Integer domainId, String language, int maxResults, RagEntityType entityType, jakarta.servlet.http.HttpServletRequest request) Searches for documents similar to the query text.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.
-
Constructor Details
-
SemanticSearchService
@Autowired public SemanticSearchService(EmbeddingService embeddingService, VectorStore vectorStore, RagEmbeddingStatService ragEmbeddingStatService, RagService ragService, RerankerService rerankerService)
-
-
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 attributeragAnswer.- Parameters:
query- search query textdomainId- domain to search in (null for all)language- language filter (null for all)maxResults- maximum number of unique documents to returnentityType- entity type to filter byrequest- current request with component PageParams and rootGroup attributes- Returns:
- document IDs with their best retrieval and rerank scores, ordered by ranking score
-
rerankChunks
Reranks authorized chunks before source aggregation and answer context selection.- Parameters:
query- user questionchunks- 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 textdomainId- requesting domain used for assistants and usage; Markdown storage is shared in domain zerolanguage- language filtermaxResults- desired document count used to calculate the chunk retrieval limitentityType- source entity typefilters- additional vector-store filters applied before the result limitrequest- 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 scoreminimumSimilarity- absolute similarity floor, clamped to the range0.0–1.0minimumResultCount- 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
-