Class DifyRAGConfig.Builder

java.lang.Object
io.agentscope.core.rag.integration.dify.DifyRAGConfig.Builder
Enclosing class:
DifyRAGConfig

public static class DifyRAGConfig.Builder extends Object
Builder for DifyRAGConfig.
  • Method Details

    • apiKey

      public DifyRAGConfig.Builder apiKey(String apiKey)
      Sets the Dify API key.

      Get your dataset API key from Dify console

      Parameters:
      apiKey - the API key (format: dataset-xxxxxxxxxxxxxxxx)
      Returns:
      this builder for method chaining
    • apiBaseUrl

      public DifyRAGConfig.Builder apiBaseUrl(String apiBaseUrl)
      Sets the Dify API base URL.

      For Dify Cloud, use the default: https://api.dify.ai/v1

      For self-hosted Dify, set your instance URL, e.g.: https://your-dify.com/v1

      If not set, defaults to https://api.dify.ai/v1

      Parameters:
      apiBaseUrl - the API base URL (must include /v1 suffix)
      Returns:
      this builder for method chaining
    • datasetId

      public DifyRAGConfig.Builder datasetId(String datasetId)
      Sets the dataset (knowledge base) ID.

      Get your dataset ID from Dify console: can got by url Format: UUID

      Parameters:
      datasetId - the dataset ID
      Returns:
      this builder for method chaining
    • retrievalMode

      public DifyRAGConfig.Builder retrievalMode(RetrievalMode retrievalMode)
      Sets the retrieval mode.

      Available modes:

      • KEYWORD: Traditional keyword search
      • SEMANTIC: Vector similarity search
      • HYBRID: Combined keyword + semantic (recommended)
      • FULLTEXT: Full-text search

      Default: HYBRID

      Parameters:
      retrievalMode - the retrieval mode
      Returns:
      this builder for method chaining
    • topK

      public DifyRAGConfig.Builder topK(Integer topK)
      Sets the top K value for retrieval.

      Number of documents to retrieve from the knowledge base. Range: [1-100], default: 10

      Parameters:
      topK - the top K value
      Returns:
      this builder for method chaining
      Throws:
      IllegalArgumentException - if topK is not in valid range
    • scoreThreshold

      public DifyRAGConfig.Builder scoreThreshold(Double scoreThreshold)
      Sets the score threshold for filtering results.

      Only documents with similarity score >= threshold will be returned. Range: [0.0-1.0], default: 0.0 (no filtering)

      Parameters:
      scoreThreshold - the score threshold
      Returns:
      this builder for method chaining
      Throws:
      IllegalArgumentException - if scoreThreshold is not in valid range
    • enableRerank

      public DifyRAGConfig.Builder enableRerank(Boolean enableRerank)
      Sets whether to enable reranking.

      Reranking uses a specialized model to re-score and reorder retrieved documents, improving relevance at the cost of slightly slower response.

      Default: false

      Parameters:
      enableRerank - true to enable reranking
      Returns:
      this builder for method chaining
    • rerankConfig

      public DifyRAGConfig.Builder rerankConfig(RerankConfig rerankConfig)
      Sets the rerank configuration.

      Only takes effect when enableRerank is true.

      Parameters:
      rerankConfig - the rerank configuration
      Returns:
      this builder for method chaining
    • weights

      public DifyRAGConfig.Builder weights(Double weights)
      Sets the hybrid search weights.

      This parameter is used when retrieval mode is HYBRID_SEARCH. It controls the balance between keyword and semantic search. A value closer to 1 emphasizes semantic search, closer to 0 emphasizes keyword search.

      Range: [0.0-1.0]

      Parameters:
      weights - the weights value
      Returns:
      this builder for method chaining
      Throws:
      IllegalArgumentException - if weights is not in valid range
    • metadataFilter

      public DifyRAGConfig.Builder metadataFilter(MetadataFilter metadataFilter)
      Sets the metadata filter configuration.

      Use this to filter documents based on their metadata fields.

      Parameters:
      metadataFilter - the metadata filter configuration
      Returns:
      this builder for method chaining
    • connectTimeout

      public DifyRAGConfig.Builder connectTimeout(Duration connectTimeout)
      Sets the HTTP connection timeout.

      Default: 30 seconds

      Parameters:
      connectTimeout - the connection timeout
      Returns:
      this builder for method chaining
    • readTimeout

      public DifyRAGConfig.Builder readTimeout(Duration readTimeout)
      Sets the HTTP read timeout.

      Default: 60 seconds

      Parameters:
      readTimeout - the read timeout
      Returns:
      this builder for method chaining
    • maxRetries

      public DifyRAGConfig.Builder maxRetries(Integer maxRetries)
      Sets the maximum number of retries for failed requests.

      Default: 3

      Parameters:
      maxRetries - the max retries (0 = no retry)
      Returns:
      this builder for method chaining
      Throws:
      IllegalArgumentException - if maxRetries is negative
    • customHeaders

      public DifyRAGConfig.Builder customHeaders(Map<String,String> customHeaders)
      Sets custom HTTP headers to include in all requests.

      Useful for adding custom authentication, tracing headers, etc.

      Parameters:
      customHeaders - map of header name to value
      Returns:
      this builder for method chaining
    • addCustomHeader

      public DifyRAGConfig.Builder addCustomHeader(String name, String value)
      Adds a single custom HTTP header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this builder for method chaining
    • build

      public DifyRAGConfig build()
      Builds a new DifyRAGConfig instance.
      Returns:
      a new DifyRAGConfig instance
      Throws:
      IllegalArgumentException - if required parameters are missing or invalid