Class RAGPipeline

java.lang.Object
com.tnsai.intelligence.rag.RAGPipeline

public final class RAGPipeline extends Object
Orchestrates the full RAG flow: preprocess query, retrieve, rerank, format context.

The pipeline executes these phases in order:

  1. Preprocess — optional query transformation (e.g., expansion, reformulation)
  2. Retrieve — delegates to the configured RAGStrategy
  3. Rerank — optional reranking of retrieved documents
  4. Format — converts documents into a context string for LLM injection

Each phase is pluggable via builder methods. The default pipeline performs retrieval with identity preprocessing, no reranking, and simple numbered formatting.

Thread-safe if the underlying strategy and operators are thread-safe.

Since:
0.2.4
  • Method Details

    • execute

      public String execute(String query)
      Executes the full RAG pipeline and returns the formatted context string.
      Parameters:
      query - the user query
      Returns:
      the formatted context string ready for LLM injection
    • execute

      public String execute(String query, RAGContext context)
      Executes the full RAG pipeline with a custom context and returns the formatted context string.
      Parameters:
      query - the user query
      context - retrieval parameters
      Returns:
      the formatted context string ready for LLM injection
    • retrieveDocuments

      public List<RetrievedDocument> retrieveDocuments(String query, RAGContext context)
      Executes the pipeline and returns the raw retrieved documents (after reranking).
      Parameters:
      query - the user query
      context - retrieval parameters
      Returns:
      the retrieved and optionally reranked documents
    • strategy

      public RAGStrategy strategy()
      Returns the strategy used by this pipeline.
      Returns:
      the RAG strategy
    • defaultContext

      public RAGContext defaultContext()
      Returns the default context used when none is specified.
      Returns:
      the default RAG context
    • builder

      public static RAGPipeline.Builder builder(RAGStrategy strategy)
      Creates a new builder for constructing a pipeline.
      Parameters:
      strategy - the retrieval strategy to use
      Returns:
      a new builder