Class: HotwireClub::MCP::Database::DocsRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire_club/mcp/database/repositories/docs_repo.rb

Instance Method Summary collapse

Instance Method Details

#allArray

Get all documents

Returns:

  • (Array)

    Array of all documents



10
11
12
# File 'lib/hotwire_club/mcp/database/repositories/docs_repo.rb', line 10

def all
  container.relations[:docs].to_a
end

#by_id(id) ⇒ Hash, ...

Get a document by ID

Parameters:

  • id (String)

    Document ID

Returns:

  • (Hash, ROM::Struct::Doc, nil)

    Document or nil if not found



18
19
20
21
22
# File 'lib/hotwire_club/mcp/database/repositories/docs_repo.rb', line 18

def by_id(id)
  return nil if id.nil? || id.empty?

  container.relations[:docs].where(id: id).one
end

#categoriesArray<String>

Get all unique categories

Returns:

  • (Array<String>)

    Array of unique category names



41
42
43
44
45
46
47
48
# File 'lib/hotwire_club/mcp/database/repositories/docs_repo.rb', line 41

def categories
  container.relations[:docs]
           .select(:category)
           .distinct
           .where { category.not(nil) }
           .map { |r| r[:category] }
           .compact
end

#list(category: nil, tags: [], limit: 20, offset: 0) ⇒ Array

List documents with optional filters

Parameters:

  • category (String, nil) (defaults to: nil)

    Filter by category

  • tags (Array<String>) (defaults to: [])

    Filter by tags (documents must have all tags)

  • limit (Integer) (defaults to: 20)

    Maximum number of results (default: 20)

  • offset (Integer) (defaults to: 0)

    Number of results to skip (default: 0)

Returns:

  • (Array)

    Array of documents



31
32
33
34
35
36
# File 'lib/hotwire_club/mcp/database/repositories/docs_repo.rb', line 31

def list(category: nil, tags: [], limit: 20, offset: 0)
  relation = container.relations[:docs]
  relation = relation.where(category: category) if category
  relation = apply_tags_filter(relation, tags) if tags.any?
  relation.limit(limit).offset(offset).to_a
end

Find related documents based on category and tag overlap

Parameters:

  • doc_id (String, nil) (defaults to: nil)

    Document ID to find related docs for

  • chunk_id (String, nil) (defaults to: nil)

    Chunk ID to find related docs for (will use chunk's doc_id)

  • limit (Integer)

    Maximum number of results

Returns:

  • (Array)

    Array of related documents



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hotwire_club/mcp/database/repositories/docs_repo.rb', line 56

def related_docs(limit:, doc_id: nil, chunk_id: nil)
  source_doc_id = resolve_source_doc_id(doc_id, chunk_id)
  return [] unless source_doc_id

  source_info = get_source_doc_info(source_doc_id)
  return [] unless source_info

  matching_doc_ids = find_matching_doc_ids(source_doc_id, source_info[:tags])
  return [] if matching_doc_ids.empty?

  container.relations[:docs]
           .where(category: source_info[:category])
           .where(id: matching_doc_ids)
           .limit(limit)
           .to_a
end