Class KeywordRAGStrategy

java.lang.Object
com.tnsai.intelligence.rag.KeywordRAGStrategy
All Implemented Interfaces:
RAGStrategy

public final class KeywordRAGStrategy extends Object implements RAGStrategy
RAG strategy that uses BM25-style keyword matching.

Delegates to BM25Index from tnsai-core's advanced memory module. BM25 scoring favors documents with high term frequency relative to document length and inverse document frequency. Results must exactly match every RAGContext.metadataFilters() entry before the requested result limit is applied.

Since:
0.2.4
  • Constructor Details

    • KeywordRAGStrategy

      public KeywordRAGStrategy(com.tnsai.memory.advanced.BM25Index bm25Index)
      Creates a keyword RAG strategy backed by the given BM25 index.
      Parameters:
      bm25Index - the BM25 index to search
  • Method Details

    • name

      public String name()
      Description copied from interface: RAGStrategy
      Returns the unique name of this strategy (e.g., "vector", "keyword", "hybrid").

      Names are compared case-insensitively using Locale.ROOT.

      Specified by:
      name in interface RAGStrategy
      Returns:
      the strategy name, never null
    • retrieve

      public List<RetrievedDocument> retrieve(String query, RAGContext context)
      Description copied from interface: RAGStrategy
      Retrieves documents relevant to the given query.

      Every returned document must exactly match all metadata filters in the context. Implementations apply that constraint before limiting the result to RAGContext.maxResults().

      Specified by:
      retrieve in interface RAGStrategy
      Parameters:
      query - the search query (never null)
      context - retrieval parameters (max results, min score, exact metadata filters)
      Returns:
      an unmodifiable list of retrieved documents, sorted by descending relevance