Class: Telnyx::Resources::AI::Clusters

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/ai/clusters.rb

Overview

Identify common themes and patterns in your embedded documents

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Clusters

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Clusters.

Parameters:



143
144
145
# File 'lib/telnyx/resources/ai/clusters.rb', line 143

def initialize(client:)
  @client = client
end

Instance Method Details

#compute(bucket:, files: nil, min_cluster_size: nil, min_subcluster_size: nil, prefix: nil, request_options: {}) ⇒ Telnyx::Models::AI::ClusterComputeResponse

Some parameter documentations has been truncated, see Models::AI::ClusterComputeParams for more details.

Starts a background task to compute how the data in an [embedded storage bucket](developers.telnyx.com/api-reference/embeddings/embed-documents) is clustered. This helps identify common themes and patterns in the data.

Parameters:

  • bucket (String)

    The embedded storage bucket to compute the clusters from. The bucket must alread

  • files (Array<String>)

    Array of files to filter which are included.

  • min_cluster_size (Integer)

    Smallest number of related text chunks to qualify as a cluster. Top-level cluste

  • min_subcluster_size (Integer)

    Smallest number of related text chunks to qualify as a sub-cluster. Sub-clusters

  • prefix (String)

    Prefix to filter whcih files in the buckets are included.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



105
106
107
108
109
110
111
112
113
114
# File 'lib/telnyx/resources/ai/clusters.rb', line 105

def compute(params)
  parsed, options = Telnyx::AI::ClusterComputeParams.dump_request(params)
  @client.request(
    method: :post,
    path: "ai/clusters",
    body: parsed,
    model: Telnyx::Models::AI::ClusterComputeResponse,
    options: options
  )
end

#delete(task_id, request_options: {}) ⇒ nil

Delete a cluster

Parameters:

Returns:

  • (nil)

See Also:



72
73
74
75
76
77
78
79
# File 'lib/telnyx/resources/ai/clusters.rb', line 72

def delete(task_id, params = {})
  @client.request(
    method: :delete,
    path: ["ai/clusters/%1$s", task_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#fetch_graph(task_id, cluster_id: nil, request_options: {}) ⇒ StringIO

Fetch a cluster visualization

Parameters:

Returns:

  • (StringIO)

See Also:



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/telnyx/resources/ai/clusters.rb', line 127

def fetch_graph(task_id, params = {})
  parsed, options = Telnyx::AI::ClusterFetchGraphParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["ai/clusters/%1$s/graph", task_id],
    query: query,
    headers: {"accept" => "image/png"},
    model: StringIO,
    options: options
  )
end

#list(page_number: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Internal::DefaultFlatPagination<Telnyx::Models::AI::ClusterListResponse>

List all clusters

Parameters:

  • page_number (Integer)
  • page_size (Integer)
  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/telnyx/resources/ai/clusters.rb', line 49

def list(params = {})
  parsed, options = Telnyx::AI::ClusterListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "ai/clusters",
    query: query.transform_keys(page_number: "page[number]", page_size: "page[size]"),
    page: Telnyx::Internal::DefaultFlatPagination,
    model: Telnyx::Models::AI::ClusterListResponse,
    options: options
  )
end

#retrieve(task_id, show_subclusters: nil, top_n_nodes: nil, request_options: {}) ⇒ Telnyx::Models::AI::ClusterRetrieveResponse

Some parameter documentations has been truncated, see Models::AI::ClusterRetrieveParams for more details.

Fetch a cluster

Parameters:

  • task_id (String)
  • show_subclusters (Boolean)

    Whether or not to include subclusters and their nodes in the response.

  • top_n_nodes (Integer)

    The number of nodes in the cluster to return in the response. Nodes will be sort

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/telnyx/resources/ai/clusters.rb', line 26

def retrieve(task_id, params = {})
  parsed, options = Telnyx::AI::ClusterRetrieveParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["ai/clusters/%1$s", task_id],
    query: query,
    model: Telnyx::Models::AI::ClusterRetrieveResponse,
    options: options
  )
end