Class HayStackConfig.Builder

java.lang.Object
io.agentscope.core.rag.integration.haystack.HayStackConfig.Builder
Enclosing class:
HayStackConfig

public static class HayStackConfig.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • baseUrl

      public HayStackConfig.Builder baseUrl(String baseUrl)
      Sets the HayStack base URL.
      Parameters:
      baseUrl - the base URL
      Returns:
      this builder
    • successCode

      public HayStackConfig.Builder successCode(Integer successCode)
      Sets the HayStack API success code.

      Default: 0

      Parameters:
      successCode - the success code
      Returns:
      this builder
    • topK

      public HayStackConfig.Builder topK(Integer topK)
      The maximum number of documents to return. If using `group_by` parameters, maximum number of groups to return.

      Default: 3

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

      public HayStackConfig.Builder scaleScore(Boolean scaleScore)
      Whether to scale the scores of the retrieved documents or not

      - When `true`, scales the score of retrieved documents to a range of 0 to 1, where 1 means extremely relevant.

      - When `false`, uses raw similarity scores.

      Parameters:
      scaleScore - whether to scale scores
      Returns:
      this builder
    • returnEmbedding

      public HayStackConfig.Builder returnEmbedding(Boolean returnEmbedding)
      Whether to return the embedding of the retrieved Documents.
      Parameters:
      returnEmbedding - whether to return embedding
      Returns:
      this builder
    • scoreThreshold

      public HayStackConfig.Builder scoreThreshold(Double scoreThreshold)
      A minimal score threshold for the result.

      Score of the returned result might be higher or smaller than the threshold depending on the Distance function used.

      E.g. for cosine similarity only higher scores will be returned.

      Parameters:
      scoreThreshold - the score threshold
      Returns:
      this builder
    • groupBy

      public HayStackConfig.Builder groupBy(String groupBy)
      Payload field to group by, must be a string or number field. If the field contains more than 1 value, all values will be used for grouping. One point can be in multiple groups.
      Parameters:
      groupBy - group name
      Returns:
      this builder
    • groupSize

      public HayStackConfig.Builder groupSize(Integer groupSize)
      Maximum amount of points to return per group.

      Default is 3.

      Parameters:
      groupSize - group size
      Returns:
      this builder
    • queryEmbedding

      public HayStackConfig.Builder queryEmbedding(List<Float> queryEmbedding)
      Use vector retrieval from the vector store.

      Normally you should not use it directly, instead use normal `query text` together with Haystack's `Embedders`.

      Parameters:
      queryEmbedding - queryEmbedding
      Returns:
      this builder
    • querySparseEmbedding

      public HayStackConfig.Builder querySparseEmbedding(SparseEmbedding querySparseEmbedding)
      Sparse Embedding of the query.
      Parameters:
      querySparseEmbedding - SparseEmbedding
      Returns:
      this builder
    • documents

      public HayStackConfig.Builder documents(List<HayStackDocument> documents)
    • retrievedDocuments

      public HayStackConfig.Builder retrievedDocuments(List<HayStackDocument> retrievedDocuments)
      The documents must include `metadata` indicating their origin and position:

      - `source_id` is used to group sentence chunks belonging to the same original document.

      - `split_id` represents the position/order of the chunk within the document.

      Parameters:
      retrievedDocuments - the documents
      Returns:
      this builder
    • windowSize

      public HayStackConfig.Builder windowSize(Integer windowSize)
      The number of adjacent documents to include on each side of the retrieved document can be configured using the `window_size` parameter.
      Parameters:
      windowSize - the window size
      Returns:
      this builder
    • filters

      public HayStackConfig.Builder filters(Map<String,Object> filters)
      A dictionary with filters to narrow down the retriever's search space in the document store.
      Parameters:
      filters - the filters
      Returns:
      this builder
    • filterPolicy

      public HayStackConfig.Builder filterPolicy(FilterPolicy filterPolicy)
      Policy to determine how filters are applied in retrievers interacting with document stores.
      Parameters:
      filterPolicy - FilterPolicy.REPLACE or FilterPolicy.MERGE
      Returns:
      this builder
    • timeout

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

      Default: 30 seconds

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

      public HayStackConfig.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 HayStackConfig.Builder customHeaders(Map<String,String> customHeaders)
      Sets custom HTTP headers.
      Parameters:
      customHeaders - the custom headers map
      Returns:
      this builder
    • addCustomHeader

      public HayStackConfig.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 HayStackConfig build()
      Builds the HayStackConfig instance.

      The baseUrl parameter is required and must not be null or blank.

      Returns:
      a new HayStackConfig instance
      Throws:
      IllegalArgumentException - if the required baseUrl parameter is missing or blank