|
- <#
- .SYNOPSIS
- Load reference knowledge (one JSON object per line) into the Foundry Knowledge Engine as global entries.
- .DESCRIPTION
- Each line needs: title, content, source; optional tags[], confidence. Entries are stored as global,
- verified (source = the cited book and page) technical facts through Add-FoundryKnowledge, so every
- rule of the module applies. Re-running is safe: an entry whose title already exists is skipped.
- The embedding-similarity duplicate check is switched off (threshold 1.0) because reference tables
- legitimately contain near-identical entries (for example the registers of SID voices 1, 2 and 3).
- .EXAMPLE
- pwsh -File scripts/Import-ReferenceKnowledge.ps1 -Path import/extracted/c64-reference.jsonl
- #>
- [CmdletBinding()]
- param(
- [Parameter(Mandatory)][string]$Path,
- [int]$Skip = 0,
- [int]$Limit = 0,
- [string[]]$ExtraTags = @()
- )
- $ErrorActionPreference = 'Stop'
- Import-Module (Join-Path $PSScriptRoot '../powershell/Foundry.Knowledge/Foundry.Knowledge.psd1') -Force
- $health = Test-FoundryKnowledge
- if (-not $health.Ready) { throw 'Knowledge engine is not ready. Run scripts/Start-Foundry.ps1 first.' }
- if (-not $health.EmbeddingsReady) { Write-Warning 'Embeddings unavailable: entries will be stored without them (keyword search only).' }
-
- $lines = @(Get-Content -LiteralPath $Path -Encoding UTF8 | Where-Object { $_.Trim() })
- if ($Skip) { $lines = $lines | Select-Object -Skip $Skip }
- if ($Limit) { $lines = $lines | Select-Object -First $Limit }
- $added = 0; $existing = 0; $failed = 0; $n = 0; $clock = [Diagnostics.Stopwatch]::StartNew()
- foreach ($line in $lines) {
- $n++
- $e = $line | ConvertFrom-Json
- try {
- $r = Add-FoundryKnowledge -Global -Type technical-fact -Status verified -DuplicateThreshold 1 `
- -Title $e.title -Content $e.content -Source $e.source `
- -Tags (@($e.tags) + $ExtraTags) -Confidence ([double]$e.confidence) -WarningAction SilentlyContinue
- if ($r.created) { $added++ } else { $existing++ }
- } catch {
- $failed++
- Write-Warning "Skipped '$($e.title)': $($_.Exception.Message)"
- }
- if ($n % 50 -eq 0) { Write-Host ("{0}/{1} added={2} existing={3} failed={4} ({5:n0}s)" -f $n, $lines.Count, $added, $existing, $failed, $clock.Elapsed.TotalSeconds) }
- }
- Write-Host ("Done: added={0} already-present={1} failed={2} of {3}" -f $added, $existing, $failed, $lines.Count)
|