Class RagExecutor

java.lang.Object
ai.nervemind.app.executor.RagExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class RagExecutor extends Object implements NodeExecutor
Executor for the "rag" node type - implements Retrieval-Augmented Generation.

Combines document retrieval with Large Language Models to answer questions based on specific context. This node orchestrates the full RAG pipeline: embedding generation for the query, vector similarity search against documents, and LLM generation with retrieved context.

Node Parameters

RAG node configuration parameters
Parameter Type Default Description
provider String "openai" LLM provider ("openai", "anthropic", "ollama")
chatModel String auto Model for answer generation (e.g., "gpt-4o")
embeddingModel String auto Model for embedding generation
apiKey String from settings API key for the provider
baseUrl String provider default Custom base URL for API
query String - User's question/query (supports interpolation)
documents List [] Documents to search (content + metadata)
topK Integer 3 Number of documents to retrieve
includeContext Boolean true Include retrieved text in output

Pipeline Steps

  1. Embedding: Generates vector for the user query
  2. Indexing: Generates embeddings for documents (if missing)
  3. Retrieval: Finds top K documents using cosine similarity
  4. Generation: Sends query + retrieved context to LLM

Output Data

Output keys added by this executor
Key Type Description
response String The LLM's generated answer
context List Retrieved documents (if includeContext=true)
sources List Metadata from retrieved documents
documentsRetrieved Integer Number of documents found
See Also:
  • Constructor Details

    • RagExecutor

      public RagExecutor()
      Creates a new RAG executor with default HTTP client configuration.
  • Method Details

    • execute

      public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String,Object> input, ExecutionService.ExecutionContext context)
      Description copied from interface: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.parameters() to access user settings.
      input - Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.
      context - Verification context providing access to workflow-scoped services, logger, and execution metadata.
      Returns:
      A Map containing the results of this node's execution. Keys in this map become available variables for downstream nodes.
      Note: Returning null is treated as an empty map.
    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      Returns:
      The unique type string (e.g., "httpRequest", "llmChat").