Class: ElevenlabsClient::Endpoints::AgentsPlatform::KnowledgeBase

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ KnowledgeBase

Returns a new instance of KnowledgeBase.



7
8
9
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#compute_rag_index(documentation_id, model:) ⇒ Hash

POST /v1/convai/knowledge-base/documentation_id/rag-index Trigger or get status of RAG indexing for a document Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/compute-rag-index

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • model (String)

    RAG model to use ("e5_mistral_7b_instruct" or "multilingual_e5_large_instruct")

Returns:

  • (Hash)

    RAG index status and progress



138
139
140
141
142
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 138

def compute_rag_index(documentation_id, model:)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index"
  request_body = { model: model }
  @client.post(endpoint, request_body)
end

#create_from_file(file_io:, filename:, name: nil) ⇒ Hash

POST /v1/convai/knowledge-base/file Create a knowledge base document generated from the uploaded file Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-file

Parameters:

  • file_io (IO)

    File IO object to upload

  • filename (String)

    Original filename

  • name (String) (defaults to: nil)

    Optional custom name for the document

Returns:

  • (Hash)

    Created document with ID and name



120
121
122
123
124
125
126
127
128
129
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 120

def create_from_file(file_io:, filename:, name: nil)
  endpoint = "/v1/convai/knowledge-base/file"
  
  payload = {
    "file" => @client.file_part(file_io, filename)
  }
  payload["name"] = name if name
  
  @client.post_multipart(endpoint, payload)
end

#create_from_text(text, name: nil) ⇒ Hash

POST /v1/convai/knowledge-base/text Create a knowledge base document containing the provided text Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-text

Parameters:

  • text (String)

    Text content to be added to the knowledge base

  • name (String) (defaults to: nil)

    Optional custom name for the document

Returns:

  • (Hash)

    Created document with ID and name



105
106
107
108
109
110
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 105

def create_from_text(text, name: nil)
  endpoint = "/v1/convai/knowledge-base/text"
  request_body = { text: text }
  request_body[:name] = name if name
  @client.post(endpoint, request_body)
end

#create_from_url(url, name: nil) ⇒ Hash

POST /v1/convai/knowledge-base/url Create a knowledge base document generated by scraping the given webpage Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-url

Parameters:

  • url (String)

    URL to a page of documentation

  • name (String) (defaults to: nil)

    Optional custom name for the document

Returns:

  • (Hash)

    Created document with ID and name



91
92
93
94
95
96
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 91

def create_from_url(url, name: nil)
  endpoint = "/v1/convai/knowledge-base/url"
  request_body = { url: url }
  request_body[:name] = name if name
  @client.post(endpoint, request_body)
end

#delete(documentation_id, force: false) ⇒ Hash

DELETE /v1/convai/knowledge-base/documentation_id Delete a document from the knowledge base Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/delete

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • force (Boolean) (defaults to: false)

    Delete regardless of agent dependencies (default: false)

Returns:

  • (Hash)

    Empty response on success



74
75
76
77
78
79
80
81
82
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 74

def delete(documentation_id, force: false)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
  
  if force
    endpoint = "#{endpoint}?force=true"
  end
  
  @client.delete(endpoint)
end

#delete_rag_index(documentation_id, rag_index_id) ⇒ Hash

DELETE /v1/convai/knowledge-base/documentation_id/rag-index/rag_index_id Delete RAG index for the knowledge base document Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/delete-rag-index

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • rag_index_id (String)

    The id of RAG index of document

Returns:

  • (Hash)

    Deleted RAG index information



162
163
164
165
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 162

def delete_rag_index(documentation_id, rag_index_id)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index/#{rag_index_id}"
  @client.delete(endpoint)
end

#get(documentation_id, agent_id: nil) ⇒ Hash

GET /v1/convai/knowledge-base/documentation_id Get details about a specific documentation making up the agent's knowledge base Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • agent_id (String) (defaults to: nil)

    Optional agent ID for context

Returns:

  • (Hash)

    Knowledge base document details



44
45
46
47
48
49
50
51
52
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 44

def get(documentation_id, agent_id: nil)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
  
  if agent_id
    endpoint = "#{endpoint}?agent_id=#{agent_id}"
  end
  
  @client.get(endpoint)
end

#get_agent_knowledge_base_size(agent_id) ⇒ Hash

GET /v1/convai/agent/agent_id/knowledge-base/size Returns the number of pages in the agent's knowledge base Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-size

Parameters:

  • agent_id (String)

    The agent ID

Returns:

  • (Hash)

    Knowledge base size information



227
228
229
230
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 227

def get_agent_knowledge_base_size(agent_id)
  endpoint = "/v1/convai/agent/#{agent_id}/knowledge-base/size"
  @client.get(endpoint)
end

#get_chunk(documentation_id, chunk_id) ⇒ Hash

GET /v1/convai/knowledge-base/documentation_id/chunk/chunk_id Get details about a specific documentation part used by RAG Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-chunk

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • chunk_id (String)

    The id of a document RAG chunk

Returns:

  • (Hash)

    Chunk details with ID, name, and content



216
217
218
219
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 216

def get_chunk(documentation_id, chunk_id)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/chunk/#{chunk_id}"
  @client.get(endpoint)
end

#get_content(documentation_id) ⇒ String

GET /v1/convai/knowledge-base/documentation_id/content Get the entire content of a document from the knowledge base Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-content

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

Returns:

  • (String)

    Streaming document content



204
205
206
207
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 204

def get_content(documentation_id)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/content"
  @client.get(endpoint)
end

#get_dependent_agents(documentation_id, **options) ⇒ Hash

GET /v1/convai/knowledge-base/documentation_id/dependent-agents Get a list of agents depending on this knowledge base document Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-dependent-agents

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • options (Hash)

    Query parameters

Options Hash (**options):

  • :cursor (String)

    Used for fetching next page

  • :page_size (Integer)

    How many agents to return at maximum (1-100, default: 30)

Returns:

  • (Hash)

    List of dependent agents with pagination info



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 186

def get_dependent_agents(documentation_id, **options)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/dependent-agents"
  query_params = options.compact
  
  if query_params.any?
    query_string = URI.encode_www_form(query_params)
    endpoint = "#{endpoint}?#{query_string}"
  end
  
  @client.get(endpoint)
end

#get_rag_index(documentation_id) ⇒ Hash

GET /v1/convai/knowledge-base/documentation_id/rag-index Get information about all RAG indexes of the specified document Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-rag-index

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

Returns:

  • (Hash)

    List of RAG indexes for the document



150
151
152
153
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 150

def get_rag_index(documentation_id)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index"
  @client.get(endpoint)
end

#get_rag_index_overviewHash

GET /v1/convai/knowledge-base/rag-index Get total size and other information of RAG indexes used by knowledge base documents Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-rag-index-overview

Returns:

  • (Hash)

    RAG index overview with usage statistics



172
173
174
175
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 172

def get_rag_index_overview
  endpoint = "/v1/convai/knowledge-base/rag-index"
  @client.get(endpoint)
end

#list(**options) ⇒ Hash

GET /v1/convai/knowledge-base Get a list of available knowledge base documents Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/list

Parameters:

  • options (Hash)

    Query parameters

Options Hash (**options):

  • :page_size (Integer)

    How many documents to return at maximum (1-100, default: 30)

  • :search (String)

    Filter documents whose names start with this string

  • :show_only_owned_documents (Boolean)

    Return only documents owned by you (default: false)

  • :types (Array<String>)

    Filter by document types ("file", "url", "text")

  • :sort_direction (String)

    Sort direction ("asc" or "desc")

  • :sort_by (String)

    Sort field ("name", "created_at", "updated_at", "size")

  • :use_typesense (Boolean)

    Use typesense DB for search (deprecated, default: false)

  • :cursor (String)

    Used for fetching next page

Returns:

  • (Hash)

    List of knowledge base documents with pagination info



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 25

def list(**options)
  endpoint = "/v1/convai/knowledge-base"
  query_params = options.compact
  
  if query_params.any?
    query_string = URI.encode_www_form(query_params)
    endpoint = "#{endpoint}?#{query_string}"
  end
  
  @client.get(endpoint)
end

#update(documentation_id, name:) ⇒ Hash

PATCH /v1/convai/knowledge-base/documentation_id Update the name of a document Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/update

Parameters:

  • documentation_id (String)

    The id of a document from the knowledge base

  • name (String)

    A custom, human-readable name for the document

Returns:

  • (Hash)

    Updated knowledge base document details



61
62
63
64
65
# File 'lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb', line 61

def update(documentation_id, name:)
  endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
  request_body = { name: name }
  @client.patch(endpoint, request_body)
end