Class RAGFlowConfig.Builder

java.lang.Object
io.agentscope.core.rag.integration.ragflow.RAGFlowConfig.Builder
Enclosing class:
RAGFlowConfig

public static class RAGFlowConfig.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • apiKey

      public RAGFlowConfig.Builder apiKey(String apiKey)
      Sets the RAGFlow API key.
      Parameters:
      apiKey - the API key (required)
      Returns:
      this builder
    • baseUrl

      public RAGFlowConfig.Builder baseUrl(String baseUrl)
      Sets the RAGFlow base URL.

      Default: http://localhost:9380

      Parameters:
      baseUrl - the base URL
      Returns:
      this builder
    • datasetIds

      public RAGFlowConfig.Builder datasetIds(List<String> datasetIds)
      Sets the dataset IDs (replaces existing list).

      These are the IDs of RAGFlow datasets to search in. You can find these IDs in the RAGFlow console.

      Parameters:
      datasetIds - the list of dataset IDs (required, at least one)
      Returns:
      this builder
    • addDatasetId

      public RAGFlowConfig.Builder addDatasetId(String datasetId)
      Adds a single dataset ID to the list.
      Parameters:
      datasetId - the dataset ID to add
      Returns:
      this builder
    • documentIds

      public RAGFlowConfig.Builder documentIds(List<String> documentIds)
      Sets the document IDs to filter retrieval (optional).

      If specified, only search within these documents.

      Parameters:
      documentIds - the list of document IDs
      Returns:
      this builder
    • addDocumentId

      public RAGFlowConfig.Builder addDocumentId(String documentId)
      Adds a single document ID to the filter list.
      Parameters:
      documentId - the document ID to add
      Returns:
      this builder
    • topK

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

      Default: 5

      Parameters:
      topK - the number of chunks to retrieve (must be > 0)
      Returns:
      this builder
    • similarityThreshold

      public RAGFlowConfig.Builder similarityThreshold(Double similarityThreshold)
      Sets the similarity threshold.

      Only chunks with similarity >= threshold will be returned.

      Default: 0.2

      Parameters:
      similarityThreshold - the similarity threshold (0.0-1.0)
      Returns:
      this builder
    • vectorSimilarityWeight

      public RAGFlowConfig.Builder vectorSimilarityWeight(Double vectorSimilarityWeight)
      Sets the vector similarity weight.

      The weight of vector cosine similarity. If x represents the weight, then (1 - x) is the term similarity weight.

      Default: 0.3

      Parameters:
      vectorSimilarityWeight - the weight (0.0-1.0)
      Returns:
      this builder
    • page

      public RAGFlowConfig.Builder page(Integer page)
      Sets the page number for pagination.

      Default: 1

      Parameters:
      page - the page number (>= 1)
      Returns:
      this builder
    • pageSize

      public RAGFlowConfig.Builder pageSize(Integer pageSize)
      Sets the page size for pagination.

      Default: 30

      Parameters:
      pageSize - the page size (>= 1)
      Returns:
      this builder
    • useKg

      public RAGFlowConfig.Builder useKg(Boolean useKg)
      Sets whether to use knowledge graph for multi-hop queries.

      Before enabling this, ensure you have successfully constructed a knowledge graph for the specified datasets.

      Default: false

      Parameters:
      useKg - true to enable knowledge graph
      Returns:
      this builder
    • tocEnhance

      public RAGFlowConfig.Builder tocEnhance(Boolean tocEnhance)
      Sets whether to use TOC (Table of Contents) enhancement.

      Before enabling this, ensure you have enabled TOC_Enhance and successfully extracted table of contents for the specified datasets.

      Default: false

      Parameters:
      tocEnhance - true to enable TOC enhancement
      Returns:
      this builder
    • rerankId

      public RAGFlowConfig.Builder rerankId(String rerankId)
      Sets the rerank model ID.

      RAGFlow's /api/v1/retrieval endpoint expects rerank_id to be the rerank model's name, e.g. "BAAI/bge-reranker-v2-m3@BAAI" or a hex UUID such as "b2a62730759d11ef987d0242ac120004".

      Parameters:
      rerankId - the rerank model ID
      Returns:
      this builder
    • rerankId

      @Deprecated(forRemoval=true) public RAGFlowConfig.Builder rerankId(Integer rerankId)
      Deprecated, for removal: This API element is subject to removal in a future version.
      RAGFlow identifies rerank models by name, not by a numeric id, so no Integer maps to a real model and the retrieval request is rejected. Use rerankId(String) instead. This overload only keeps existing call sites compiling and stringifies the value.
      Sets the rerank model ID from a numeric value.
      Parameters:
      rerankId - the rerank model ID
      Returns:
      this builder
    • keyword

      public RAGFlowConfig.Builder keyword(Boolean keyword)
      Sets whether to enable keyword-based matching.

      Default: false

      Parameters:
      keyword - true to enable keyword matching
      Returns:
      this builder
    • highlight

      public RAGFlowConfig.Builder highlight(Boolean highlight)
      Sets whether to enable highlighting of matched terms in results.

      Default: false

      Parameters:
      highlight - true to enable highlighting
      Returns:
      this builder
    • crossLanguages

      public RAGFlowConfig.Builder crossLanguages(List<String> crossLanguages)
      Sets the languages for cross-language retrieval.

      The languages that should be translated into, in order to achieve keywords retrievals in different languages.

      Parameters:
      crossLanguages - the list of target languages
      Returns:
      this builder
    • addCrossLanguage

      public RAGFlowConfig.Builder addCrossLanguage(String language)
      Adds a language for cross-language retrieval.
      Parameters:
      language - the target language to add
      Returns:
      this builder
    • metadataCondition

      public RAGFlowConfig.Builder metadataCondition(Map<String,Object> metadataCondition)
      Sets the metadata filtering condition.

      Use this to filter chunks based on their metadata. For example:

      
       builder.metadataCondition(Map.of(
           "author", "John",
           "category", "tech"
       ));
       
      Parameters:
      metadataCondition - the metadata condition map
      Returns:
      this builder
    • timeout

      public RAGFlowConfig.Builder timeout(Duration timeout)
      Sets the HTTP timeout.

      Default: 30 seconds

      Parameters:
      timeout - the timeout duration
      Returns:
      this builder
    • maxRetries

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

      Default: 3

      Parameters:
      maxRetries - the max retries (>= 0)
      Returns:
      this builder
    • customHeaders

      public RAGFlowConfig.Builder customHeaders(Map<String,String> customHeaders)
      Sets custom HTTP headers.
      Parameters:
      customHeaders - the custom headers map
      Returns:
      this builder
    • addCustomHeader

      public RAGFlowConfig.Builder addCustomHeader(String key, String value)
      Adds a custom HTTP header.
      Parameters:
      key - the header name
      value - the header value
      Returns:
      this builder
    • build

      public RAGFlowConfig build()
      Builds the RAGFlowConfig instance.

      Either dataset_ids or document_ids must be set (or both). If document_ids is set without dataset_ids, ensure all documents use the same embedding model.

      Returns:
      a new RAGFlowConfig instance
      Throws:
      IllegalArgumentException - if required parameters are missing