Documentation
¶
Overview ¶
@facet: navigation/retrieval/registry-index @facet-role: related
Package rag turns a FACET registry into something a question can be asked of by meaning rather than by exact id.
@facet: navigation/retrieval/semantic-search @facet-role: primary
Index ¶
Constants ¶
const ConfigHint = facet.ConfigName
ConfigHint names the configuration file in error messages.
const DefaultBatch = 64
DefaultBatch is how many chunks one request carries.
const DefaultProvider = "local"
DefaultProvider is what a project gets when it configures nothing.
const DefaultTimeout = 60 * time.Second
DefaultTimeout bounds one embedding request.
const LocalDim = 512
LocalDim is the width of the built-in embedder's vectors.
const MaxChunkChars = 1400
MaxChunkChars is the soft size budget for one chunk.
Variables ¶
var RecordFacets = []string{
"intent",
"contract",
"verification",
"observation",
"observability",
"knowledge",
"lineage",
"flags",
"variants",
"metadata",
}
RecordFacets are the top-level facets chunked out of a record, in the order they are indexed.
Functions ¶
Types ¶
type Chunk ¶
type Chunk struct {
// ID is stable across rebuilds: same registry, same feature, same facet,
// same part number yields the same id. That is what lets an index be
// rebuilt incrementally later without renumbering everything.
ID string `json:"id"`
// Registry is the declaring registry's name, empty in a single-registry
// project.
Registry string `json:"registry,omitempty"`
// Feature is the feature id this text belongs to, empty for a generated
// document that names no feature.
Feature string `json:"feature,omitempty"`
// Kind is "record" for text taken from a FACET record, "doc" for text taken
// from a generated article. A reader is entitled to know which it got.
Kind string `json:"kind"`
// Facet is the record facet the text came from — intent, contract,
// verification, observation, knowledge, lineage — or "article" for a doc.
Facet string `json:"facet"`
// Path is repository-relative, so a hit names a file that is really there.
Path string `json:"path"`
// Part is the slice number when one facet was too long for a single chunk.
Part int `json:"part,omitempty"`
// Title is the one-line headline shown above a hit.
Title string `json:"title,omitempty"`
// Text is what was embedded, verbatim. Stored so a hit can be quoted rather
// than summarised — the same discipline the rest of this toolchain applies
// to generated prose.
Text string `json:"text"`
}
Chunk is one embeddable unit of text and where it came from.
type Embedder ¶
type Embedder interface {
// Embed returns one vector per input, in order. Implementations batch as
// they see fit; the contract is only that the order is preserved.
Embed(ctx context.Context, texts []string) ([][]float32, error)
// Describe names what produced the vectors, as "provider" and "model".
// The pair is written into the index so a query embedded by something else
// is refused rather than answered wrongly.
Describe() (provider, model string)
}
Embedder turns text into vectors.
@facet: navigation/retrieval/embedding-configuration @facet-role: primary
type HTTPEmbedder ¶
type HTTPEmbedder struct {
BaseURL string
Model string
// APIKey is the bearer token. Empty is valid and normal: a local Ollama
// wants no key at all.
APIKey string
// Dimensions is passed through when non-zero, for the providers that let a
// caller shorten the vector. Providers that do not understand it ignore it.
Dimensions int
// Batch is how many texts go in one request. Zero means the default.
Batch int
Client *http.Client
}
HTTPEmbedder calls an OpenAI-compatible /embeddings endpoint.
func (*HTTPEmbedder) Describe ¶
func (e *HTTPEmbedder) Describe() (string, string)
Describe names the provider kind and the model, so an index says what produced its vectors without carrying a key or a URL.
type Hit ¶
type Hit struct {
Chunk
// Score is cosine similarity in [-1, 1]. Vectors are stored normalised, so
// this is a plain dot product and needs no division at query time.
Score float32 `json:"score"`
}
Hit is one search result.
type LocalEmbedder ¶
type LocalEmbedder struct {
// Dim is the vector width. Zero uses LocalDim.
Dim int
}
LocalEmbedder is a lexical embedder that runs in this process.
@facet: navigation/retrieval/embedding-configuration @facet-role: related
func (*LocalEmbedder) Describe ¶
func (l *LocalEmbedder) Describe() (string, string)
Describe names this embedder in the index, so a store built with it is visibly not a store built with a neural model.
type Progress ¶
Progress reports one step of a build. It is called from the goroutine doing the work, so a slow implementation slows the build.
type Store ¶
type Store struct {
// Provider and Model identify what produced the vectors. A query embedded
// by a different model than the index is meaningless, and this is how that
// is caught rather than silently returning nonsense.
Provider string `json:"provider"`
Model string `json:"model"`
Dim int `json:"dim"`
BuiltAt string `json:"builtAt"`
// contains filtered or unexported fields
}
Store is an index held entirely in memory and searched by brute force.
func Build ¶
func Build(ctx context.Context, registries []facet.Registry, embedder Embedder, report Progress) (*Store, error)
Build reads every registry into chunks, embeds them, and returns a store.
@facet: navigation/retrieval/registry-index @facet-role: related
func NewStore ¶
NewStore builds a store from chunks and their vectors, normalising as it goes so that search never has to.