artifact

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package artifact defines lore's portable corpus format: a single, versioned, self-contained byte stream holding one collection — its embedding-space and chunker pins, metadata, documents, chunks, and vectors — so a collection can be exported to a file and reconstructed elsewhere with its invariants intact.

The stream is framed: an 8-byte magic, a 4-byte big-endian format version, then a gob-encoded Bundle. Framing the version lets an importer reject a newer format with a clear error instead of a gob failure. The wire types are deliberately decoupled from the domain types (their own plain structs) so the format stays stable across domain refactors; the export/import use cases map between the two.

Index

Constants

View Source
const (
	// Magic prefixes every artifact, distinguishing it from random bytes and from
	// an age-encrypted stream (which carries its own header).
	Magic = "LORECORP"
	// FormatVersion is the current frame version. Bump it when the Bundle wire
	// shape changes incompatibly; Read rejects anything newer.
	FormatVersion uint32 = 1
)

Variables

View Source
var (
	// ErrBadFormat means the stream is not a lore artifact (wrong or short magic).
	ErrBadFormat = errors.New("not a lore artifact")
	// ErrUnsupportedVersion means the artifact's format version is newer than this
	// binary understands.
	ErrUnsupportedVersion = errors.New("unsupported artifact format version")
)

Functions

func Write

func Write(w io.Writer, b Bundle) error

Write frames and writes b: the magic, the format version, then a gob-encoded Bundle.

Types

type Bundle

type Bundle struct {
	Collection Collection
	Documents  []Document
}

Bundle is a whole exported collection.

func Read

func Read(r io.Reader) (Bundle, error)

Read verifies the magic and version, then decodes the Bundle. A wrong or short magic is ErrBadFormat; a version newer than FormatVersion is ErrUnsupportedVersion (nothing is decoded); a decode failure on a well-framed stream is a wrapped gob error.

type Chunk

type Chunk struct {
	Seq         int
	Text        string
	HeadingPath string
	Vector      []float32
}

Chunk is one stored chunk with its embedding vector. The chunk and document IDs are not stored — they are deterministically re-derived from the (target collection, source URI, seq) on import, which keeps the artifact rename-safe.

type Chunker

type Chunker struct {
	Strategy      string
	Version       int
	Size          int
	Overlap       int
	Tokenizer     string
	ContextPrefix bool
}

Chunker is the serialized chunker pin (mirrors domain.ChunkerSpec).

type Collection

type Collection struct {
	Name       string
	Model      string
	Dimensions int
	CreatedAt  time.Time
	Sources    []string
	Chunker    Chunker
}

Collection carries the collection's identity, metadata, and the pins that must travel with it so the reconstructed collection enforces the same invariants. A zero Chunker means the source collection predated chunker pinning.

type Document

type Document struct {
	SourceURI   string
	Hash        string
	IngestedAt  time.Time
	Fingerprint string
	Metadata    map[string]string
	Chunks      []Chunk
}

Document is one source document and its chunks (with their vectors), enough to reconstruct the document, its chunks, and its index entries on import. Metadata is an additive field: gob ignores it when read by a binary that predates it, and it decodes to nil from an artifact written without it, so no format-version bump is required (the version gates only incompatible shape changes).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL