Class DifyRAGConfig.Builder
- Enclosing class:
- DifyRAGConfig
-
Method Summary
Modifier and TypeMethodDescriptionaddCustomHeader(String name, String value) Adds a single custom HTTP header.apiBaseUrl(String apiBaseUrl) Sets the Dify API base URL.Sets the Dify API key.build()Builds a new DifyRAGConfig instance.connectTimeout(Duration connectTimeout) Sets the HTTP connection timeout.customHeaders(Map<String, String> customHeaders) Sets custom HTTP headers to include in all requests.Sets the dataset (knowledge base) ID.enableRerank(Boolean enableRerank) Sets whether to enable reranking.maxRetries(Integer maxRetries) Sets the maximum number of retries for failed requests.metadataFilter(MetadataFilter metadataFilter) Sets the metadata filter configuration.readTimeout(Duration readTimeout) Sets the HTTP read timeout.rerankConfig(RerankConfig rerankConfig) Sets the rerank configuration.retrievalMode(RetrievalMode retrievalMode) Sets the retrieval mode.scoreThreshold(Double scoreThreshold) Sets the score threshold for filtering results.Sets the top K value for retrieval.Sets the hybrid search weights.
-
Method Details
-
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
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
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
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
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
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
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
Sets the rerank configuration.Only takes effect when enableRerank is true.
- Parameters:
rerankConfig- the rerank configuration- Returns:
- this builder for method chaining
-
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
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
Sets the HTTP connection timeout.Default: 30 seconds
- Parameters:
connectTimeout- the connection timeout- Returns:
- this builder for method chaining
-
readTimeout
Sets the HTTP read timeout.Default: 60 seconds
- Parameters:
readTimeout- the read timeout- Returns:
- this builder for method chaining
-
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
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
Adds a single custom HTTP header.- Parameters:
name- the header namevalue- the header value- Returns:
- this builder for method chaining
-
build
Builds a new DifyRAGConfig instance.- Returns:
- a new DifyRAGConfig instance
- Throws:
IllegalArgumentException- if required parameters are missing or invalid
-