Prd/components/backend/wiki/build_index.rb
Lucy Doupalů be9f14ce34 Helpdesk - operator console + patched GrapheneOS Dialer for call handling
A small helpdesk system: an office Pixel running a patched GrapheneOS Dialer
answers technician calls, records both call legs as separate channels, and a
Ruby backend transcribes them through Whisper and files an AI summary against
the caller.

Squashed to a single commit for sharing. No credentials are included; secrets
live outside the repo in /etc/helpdesk/env on the server or a gitignored
.claude/env.local locally. See .claude/env.local.example for the shape.

Start at README.md, then docs/architecture.md.
2026-07-27 18:50:32 +02:00

31 lines
1.3 KiB
Ruby

# frozen_string_literal: true
# Build the wiki RAG index: fetch knowledge pages (Wiki.js GraphQL) -> chunk -> embed (OpenRouter)
# -> save. Run: WIKI_JWT=… OPENROUTER_API_KEY=… ruby build_index.rb [out.json]
# Keys can also be read from the standard local key files (the paths in the defaults below).
require_relative "wiki_client"
require_relative "embedder"
require_relative "wiki_index"
def key_from(file, pattern)
return nil unless File.exist?(file)
File.readlines(file).map(&:strip).find { |l| l =~ pattern }
end
jwt = ENV["WIKI_JWT"] || key_from("/home/lucy/Downloads/apikeyvodafonewiki", /\Aey[A-Za-z0-9_-]/)
orkey = ENV["OPENROUTER_API_KEY"] || key_from("/home/lucy/Downloads/openrouterApiKlic2", /\Ask-or-v1-/)
abort "no WIKI_JWT" if jwt.to_s.empty?
abort "no OPENROUTER_API_KEY" if orkey.to_s.empty?
out = ARGV[0] || File.join(__dir__, "wiki_index.json")
warn "fetching knowledge pages from the wiki…"
pages = Helpdesk::WikiClient.new(jwt: jwt).knowledge_pages
chars = pages.sum { |p| p[:text].length }
warn " #{pages.size} pages, #{chars} chars (~#{chars / 4} tokens) to index"
warn "embedding chunks via OpenRouter…"
idx = Helpdesk::WikiIndex.new(embedder: Helpdesk::Embedder.new(api_key: orkey))
idx.build(pages)
idx.save(out)
warn "DONE: #{idx.size} chunks -> #{out}"