Class: Assistant::TechnicalArticleToolBuilder::SearchTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
app/services/assistant/technical_article_tool_builder.rb

Overview

Search approved Technical Articles and reject any result whose stored
embedding cannot be proven to match its current source content.

Direct Known Subclasses

ProcedureSearchTool

Instance Method Summary collapse

Instance Method Details

#execute(query:, limit: 8) ⇒ String

Runs a semantic search over Technical Articles and returns verified results.

Parameters:

  • query (String)

    detailed symptom, product, installation context, and error code when known.

  • limit (Integer) (defaults to: 8)

    maximum results to return (default 8, max MAX_SEARCH_RESULTS).

Returns:

  • (String)

    JSON string with total results and matching articles, or an error object.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/services/assistant/technical_article_tool_builder.rb', line 49

def execute(query:, limit: 8, **)
  limit = limit.to_i.clamp(1, MAX_SEARCH_RESULTS)
  candidates = search(query, limit:)
  preload_embedding_content(candidates)
  articles = candidates.filter_map { |result| format_result(result) }.first(limit)

  ChatToolBuilder.truncate_result(
    {
      query: query,
      total_results: articles.size,
      articles: articles
    }.to_json
  )
rescue StandardError => e
  Rails.logger.error("[TechnicalArticleToolBuilder] #{} search failed: #{e.class}: #{e.message}")
  { error: "#{} search failed." }.to_json
end

#nameString

Returns the RubyLLM tool name exposed to the assistant.

Returns:

  • (String)

    the RubyLLM tool name exposed to the assistant.



42
# File 'app/services/assistant/technical_article_tool_builder.rb', line 42

def name = 'search_technical_articles'