No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

45 líneas
2.4KB

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

Powered by TurnKey Linux.