Class: Tools::SemanticSearchTool
- Inherits:
-
ApplicationTool
- Object
- MCP::Tool
- ApplicationTool
- Tools::SemanticSearchTool
- Defined in:
- app/mcp/tools/semantic_search_tool.rb
Overview
MCP Tool for performing semantic search across all embedded content.
Uses pgvector embeddings to find content matching natural language queries.
Constant Summary collapse
- SENSITIVE_SEARCH_TYPES =
Recognised sensitive search types.
%w[support_notes support_communications].freeze
Class Method Summary collapse
Class Method Details
.call(query:, types: nil, limit: 10, _server_context: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/mcp/tools/semantic_search_tool.rb', line 54 def call(query:, types: nil, limit: 10, _server_context: nil) limit = limit.to_i.clamp(1, 50) normalized = normalize_types(types) needs_sensitive = Array(types).any? { |t| SENSITIVE_SEARCH_TYPES.include?(t.to_s.downcase) } search_limit = needs_sensitive ? limit * 3.clamp(1, 50) : limit results = SemanticSearchService.search( query, types: normalized, limit: search_limit, exclude_sensitive: !needs_sensitive ) results = (results) if needs_sensitive results = results.first(limit) records = results.pluck(:record) items = records.grep(Item) product_lines = records.grep(ProductLine) all_pls = (items.filter_map(&:primary_product_line) + product_lines).uniq(&:id) if all_pls.any? paths = ProductLine.canonical_paths_for(all_pls) all_pls.each { |pl| pl.instance_variable_set(:@canonical_path, paths[pl.id]) } end json_response( query: query, total_results: results.size, results: results.map { |r| format_result(r) } ) end |