Files
knox/internal/ingest/ingest.go
T
david 84f30f293b
build / test (push) Has been cancelled
build / image (push) Has been cancelled
feat: index reasoning, and close the two-minute freshness gap (#19)
feat: index reasoning, and close the session freshness gap (#19)

Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-11-05 03:39:16 +00:00

68 lines
1.6 KiB
Go

package ingest
import (
"crypto/sha256"
"encoding/json"
"fmt"
)
type IngestResult struct {
Fingerprint string
SourceID string
SourcePath string
Project string
ContentType string
Title string
Summary string
CreatedAt string
LineStart int
LineEnd int
Confidence float64
IngesterVersion string
Provenance map[string]any
// ContentHash is an optional stable hash of the result's *meaningful*
// content. When set, the index treats an unchanged hash as "same knowledge"
// even if the source grew (e.g. a log with the same error set).
ContentHash string
// Content is the full searchable body. Summary stays a short preview; this
// is what full-text search matches against.
Content string
// SourceUpdated is the source's own modification time in Unix milliseconds
// when it has one. Incremental ingesters use it as a watermark.
SourceUpdated int64
}
type Ingester interface {
SourceID() string
Ingest(path string) (*IngestResult, error)
}
func Fingerprint(data []byte) string {
h := sha256.Sum256(data)
return fmt.Sprintf("%x", h[:16])
}
func FingerprintWithMeta(data []byte, meta map[string]string) string {
h := sha256.New()
h.Write(data)
enc := json.NewEncoder(h)
_ = enc.Encode(meta)
return fmt.Sprintf("%x", h.Sum(nil)[:16])
}
func ProvenanceJSON(m map[string]any) string {
b, err := json.Marshal(m)
if err != nil {
return "{}"
}
return string(b)
}
func truncate(s string, n int) string {
runes := []rune(s)
if len(runes) <= n {
return s
}
return string(runes[:n]) + "..."
}