Versions in this module Expand all Collapse all v0 v0.1.0 Aug 9, 2026 Changes in this version + var ErrEdgeSearchUnavailable = errors.New("brain: graph edge search is not available") + var ErrExpandRecipeNameRequired = errors.New("brain: expand recipe name is required") + var ErrExpandRecipeNotFound = errors.New("brain: expand recipe not found") + var ErrGraphEnsure = errors.New("brain: graph ensure object") + var ErrGraphRemove = errors.New("brain: graph remove object") + var ErrGraphRequired = errors.New("brain: graph backend is required") + var ErrGraphWriterRequired = errors.New("brain: graph writer is required for Link") + var ErrLinkArgs = errors.New("brain: from, to, and relation type are required") + var ErrLinkNotFirstClass = errors.New("brain: link endpoint must be a first-class object (not a part)") + var ErrLinkQueryRequired = errors.New("brain: relation type and query are required") + var ErrNotFound = errors.New("brain: object not found") + var ErrObjectIDRequired = errors.New("brain: object id is required") + var ErrObjectSearchUnavailable = errors.New("brain: graph object search is not available") + var ErrQueryRequired = errors.New("brain: query is required") + var ErrResultSetIDRequired = errors.New("brain: result_set_id is required") + var ErrResultSetNotFound = errors.New("brain: result set not found") + var ErrResultSetRequired = errors.New("brain: result set store is required") + var ErrSoftDeletedPut = errors.New("brain: put refuses soft-deleted objects; use SoftDelete") + var ErrWritesUnsupported = errors.New("brain: store does not support object writes") + func EntityIndexText(obj Object) string + func IndexText(obj Object) string + func IndexTextWithParent(obj Object, parentTitle string) string + func IsContainmentRelation(rel string) bool + func LandingIDs(objects []RichObject) []uuid.UUID + func LandingIDsFromPage(page SearchPage) []uuid.UUID + func NormalizeRelationTypes(rels []string) []string + func PersistKinds(ctx context.Context, w KindWriter, specs ...KindSpec) error + func SortRichObjects(objects []RichObject, key string, desc bool) + func SplitRelationTypes(rels []string) (wantContainment bool, graphLabels []string) + func ValidateFilters(f Filters) error + func ValidateFiltersAgainst(f Filters, cat *KindCatalog) error + func ValidateObject(obj Object, cat *KindCatalog) error + type DegradeMode string + const DegradeContainmentOnly + const DegradeLexicalOnly + const DegradeNone + func (m DegradeMode) String() string + type EdgeMeta struct + Confidence float64 + CreatedAt time.Time + EvidenceID *uuid.UUID + Note string + Role string + Status string + UpdatedAt time.Time + func (m EdgeMeta) IsZero() bool + type EdgeSearchHit struct + FromID uuid.UUID + Meta EdgeMeta + RelationType string + Score float64 + ToID uuid.UUID + type Engine struct + func NewEngine(store Store, opts ...EngineOption) (*Engine, error) + func (e *Engine) ApplyKinds(ctx context.Context, specs ...KindSpec) error + func (e *Engine) Catalog() *KindCatalog + func (e *Engine) Continue(ctx context.Context, scope Scope, resultSetID uuid.UUID, limit int, ...) (page SearchPage, err error) + func (e *Engine) Expand(ctx context.Context, scope Scope, req ExpandRequest, results ResultSetStore) (res ExpandResult, err error) + func (e *Engine) ExpandByRecipe(ctx context.Context, scope Scope, objectID uuid.UUID, recipeName string, ...) (ExpandResult, error) + func (e *Engine) ExpandMany(ctx context.Context, scope Scope, req ExpandManyRequest) (res ExpandManyResult, err error) + func (e *Engine) FindExact(ctx context.Context, scope Scope, req SearchRequest, results ResultSetStore) (page SearchPage, err error) + func (e *Engine) FindLinks(ctx context.Context, scope Scope, req FindLinksRequest) (res FindLinksResult, err error) + func (e *Engine) FindObjects(ctx context.Context, scope Scope, req FindObjectsRequest, ...) (page SearchPage, err error) + func (e *Engine) FreezeCatalog() + func (e *Engine) HasEdgeSearch() bool + func (e *Engine) HasGraphWriter() bool + func (e *Engine) HasObjectSearch() bool + func (e *Engine) Link(ctx context.Context, scope Scope, from, to uuid.UUID, relationType string) error + func (e *Engine) LinkWith(ctx context.Context, scope Scope, from, to uuid.UUID, relationType string, ...) error + func (e *Engine) ListChildren(ctx context.Context, scope Scope, parentID uuid.UUID) ([]RichObject, error) + func (e *Engine) LoadKindsFromStore(ctx context.Context) error + func (e *Engine) Put(ctx context.Context, scope Scope, obj Object) (Object, error) + func (e *Engine) Read(ctx context.Context, scope Scope, id uuid.UUID) (RichObject, error) + func (e *Engine) RegisterExpandRecipe(r ExpandRecipe) error + func (e *Engine) RegisterKinds(_ context.Context, specs ...KindSpec) error + func (e *Engine) Schema(ctx context.Context, kind string) (SchemaResult, error) + func (e *Engine) Search(ctx context.Context, scope Scope, req SearchRequest, results ResultSetStore) (page SearchPage, err error) + func (e *Engine) SoftDelete(ctx context.Context, scope Scope, id uuid.UUID) error + func (e *Engine) SyncKindsToStore(ctx context.Context) error + type EngineConfig struct + CandidateK int + DefaultLimit int + EvidenceN int + ExpandInlineMax int + FailOnEmbedderError bool + FailOnGraphError bool + GraphNeighborK int + Lambda *float64 + MaxExpandHops int + MaxGraphExpandRPCs int + MaxLimit int + MaxResultSetSize int + Now func() time.Time + RRFk int + SiblingRadius int + func DefaultEngineConfig() EngineConfig + type EngineOption func(*Engine) + func WithConfig(cfg EngineConfig) EngineOption + func WithEmbedder(e QueryEmbedder) EngineOption + func WithExpandRecipes(recipes ...ExpandRecipe) EngineOption + func WithGraph(g GraphReader) EngineOption + func WithKinds(specs ...KindSpec) EngineOption + func WithObserver(o Observer) EngineOption + func WithReranker(r Reranker) EngineOption + type Evidence struct + PartID uuid.UUID + Position *int + Properties map[string]any + Score float64 + Snippet string + Title string + type ExpandManyRequest struct + Direction string + MaxHops int + NeighborBudget int + ObjectIDs []uuid.UUID + RelationTypes []string + WantContainment bool + type ExpandManyResult struct + Objects []RichObject + type ExpandRecipe struct + Direction string + MaxHops int + Name string + RelationTypes []string + WantContainment bool + type ExpandRequest struct + Direction string + Limit int + MaxHops int + ObjectID uuid.UUID + RelationTypes []string + WantContainment bool + type ExpandResult struct + HasMore bool + Mode string + Objects []RichObject + ResultSetID uuid.UUID + type FieldSpec struct + Description string + Examples []string + Name string + Operators []string + Required bool + Type FieldType + type FieldType string + const FieldTypeBoolean + const FieldTypeDateTime + const FieldTypeNumber + const FieldTypeString + type FilterUsage struct + Note string + Tools []string + func DefaultFilterUsage() FilterUsage + type Filters map[string]any + type FindLinksRequest struct + Limit int + Query string + RelationType string + type FindLinksResult struct + Links []LinkHit + type FindObjectsRequest struct + Filters Filters + Kinds []string + Limit int + Query string + type GraphEdgeSearcher interface + SearchEdgesText func(ctx context.Context, relationType, query string, limit int) ([]EdgeSearchHit, error) + type GraphNeighbor struct + Direction string + Meta EdgeMeta + ObjectID uuid.UUID + RelationType string + type GraphObjectSearcher interface + SearchText func(ctx context.Context, query string, limit int, namespace *uuid.UUID) ([]ScoredID, error) + SearchVector func(ctx context.Context, embedding []float32, limit int, namespace *uuid.UUID) ([]ScoredID, error) + type GraphReader interface + Neighbors func(ctx context.Context, objectID uuid.UUID, relationTypes []string, limit int) ([]GraphNeighbor, error) + type GraphWriter interface + AddEdge func(ctx context.Context, from, to uuid.UUID, relationType string, meta EdgeMeta) error + EnsureObject func(ctx context.Context, obj Object) error + RemoveObject func(ctx context.Context, id uuid.UUID) error + type KindCatalog struct + func (c *KindCatalog) All() []KindSpec + func (c *KindCatalog) Empty() bool + func (c *KindCatalog) Freeze() + func (c *KindCatalog) Get(kind string) (KindSpec, bool) + func (c *KindCatalog) Names() []string + type KindReader interface + GetKind func(ctx context.Context, kind string) (ObjectKind, error) + ListKinds func(ctx context.Context) ([]ObjectKind, error) + type KindRegistry interface + type KindSpec struct + Description string + Fields []FieldSpec + IsParent bool + IsPart bool + Kind string + func KindSpecFromObjectKind(k ObjectKind) (KindSpec, error) + func NormalizeKindSpec(spec KindSpec) (KindSpec, error) + func (s KindSpec) Field(name string) (FieldSpec, bool) + type KindWriter interface + PutKind func(ctx context.Context, k ObjectKind) error + type LinkHit struct + From RichObject + Meta EdgeMeta + RelationType string + Score float64 + To RichObject + type MemoryGraph struct + func NewMemoryGraph() *MemoryGraph + func (g *MemoryGraph) AddEdge(ctx context.Context, from, to uuid.UUID, relationType string, meta EdgeMeta) error + func (g *MemoryGraph) EnsureObject(ctx context.Context, obj Object) error + func (g *MemoryGraph) Neighbors(ctx context.Context, objectID uuid.UUID, relationTypes []string, limit int) ([]GraphNeighbor, error) + func (g *MemoryGraph) RemoveObject(ctx context.Context, id uuid.UUID) error + func (g *MemoryGraph) SearchEdgesText(ctx context.Context, relationType, query string, limit int) ([]EdgeSearchHit, error) + func (g *MemoryGraph) SearchText(ctx context.Context, query string, limit int, namespace *uuid.UUID) ([]ScoredID, error) + func (g *MemoryGraph) SearchVector(ctx context.Context, embedding []float32, limit int, namespace *uuid.UUID) ([]ScoredID, error) + type MemoryStore struct + func NewMemoryStore() *MemoryStore + func (s *MemoryStore) Get(_ context.Context, scope Scope, id uuid.UUID) (Object, error) + func (s *MemoryStore) GetKind(_ context.Context, kind string) (ObjectKind, error) + func (s *MemoryStore) GetMany(_ context.Context, scope Scope, ids []uuid.UUID) ([]Object, error) + func (s *MemoryStore) ListChildren(_ context.Context, scope Scope, parentID uuid.UUID) ([]Object, error) + func (s *MemoryStore) ListKinds(_ context.Context) ([]ObjectKind, error) + func (s *MemoryStore) Put(_ context.Context, obj Object) error + func (s *MemoryStore) PutKind(_ context.Context, k ObjectKind) error + func (s *MemoryStore) SearchLexical(_ context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + func (s *MemoryStore) SearchTrigram(_ context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + func (s *MemoryStore) SearchVector(_ context.Context, scope Scope, embedding []float32, filters Filters, k int) ([]ScoredID, error) + func (s *MemoryStore) SoftDelete(_ context.Context, scope Scope, id uuid.UUID) error + type Object struct + Content string + ContentType string + CreatedAt time.Time + DeletedAt *time.Time + Embedding []float32 + ID uuid.UUID + Kind string + NamespaceID uuid.UUID + ParentID *uuid.UUID + Position *int + Properties map[string]any + Summary string + Title string + UpdatedAt time.Time + func (o Object) IsPart() bool + type ObjectKind struct + Description string + FilterableFields json.RawMessage + IsParent bool + IsPart bool + Kind string + func ObjectKindFromSpec(spec KindSpec) (ObjectKind, error) + type ObjectKindInfo struct + Description string + FilterableFields json.RawMessage + IsParent bool + IsPart bool + Kind string + func KindInfoFrom(k ObjectKind) ObjectKindInfo + func KindInfoFromSpec(spec KindSpec) ObjectKindInfo + type ObjectReader interface + Get func(ctx context.Context, scope Scope, id uuid.UUID) (Object, error) + GetMany func(ctx context.Context, scope Scope, ids []uuid.UUID) ([]Object, error) + ListChildren func(ctx context.Context, scope Scope, parentID uuid.UUID) ([]Object, error) + type ObjectWriter interface + Put func(ctx context.Context, obj Object) error + SoftDelete func(ctx context.Context, scope Scope, id uuid.UUID) error + type Observer interface + StartOp func(ctx context.Context, op Op) (context.Context, OpSpan) + type Op string + const OpContinue + const OpExpand + const OpExpandMany + const OpFindExact + const OpFindLinks + const OpFindObjects + const OpSearch + type OpSpan interface + End func(hits int, degrade DegradeMode, err error) + type PartSearcher interface + SearchLexical func(ctx context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + SearchTrigram func(ctx context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + SearchVector func(ctx context.Context, scope Scope, embedding []float32, filters Filters, k int) ([]ScoredID, error) + type PgxDB interface + Exec func(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error) + Query func(ctx context.Context, sql string, args ...any) (pgx.Rows, error) + QueryRow func(ctx context.Context, sql string, args ...any) pgx.Row + type PostgresStore struct + func NewPostgresStore(db PgxDB) (*PostgresStore, error) + func (s *PostgresStore) Get(ctx context.Context, scope Scope, id uuid.UUID) (Object, error) + func (s *PostgresStore) GetKind(ctx context.Context, kind string) (ObjectKind, error) + func (s *PostgresStore) GetMany(ctx context.Context, scope Scope, ids []uuid.UUID) ([]Object, error) + func (s *PostgresStore) ListChildren(ctx context.Context, scope Scope, parentID uuid.UUID) ([]Object, error) + func (s *PostgresStore) ListKinds(ctx context.Context) ([]ObjectKind, error) + func (s *PostgresStore) Put(ctx context.Context, obj Object) error + func (s *PostgresStore) PutKind(ctx context.Context, k ObjectKind) error + func (s *PostgresStore) SearchLexical(ctx context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + func (s *PostgresStore) SearchTrigram(ctx context.Context, scope Scope, query string, filters Filters, k int) ([]ScoredID, error) + func (s *PostgresStore) SearchVector(ctx context.Context, scope Scope, embedding []float32, filters Filters, k int) ([]ScoredID, error) + func (s *PostgresStore) SoftDelete(ctx context.Context, scope Scope, id uuid.UUID) error + type QueryEmbedder interface + Embed func(ctx context.Context, text string) ([]float32, error) + type Relation struct + Depth int + Direction string + SourceID *uuid.UUID + Type string + func RelationFromNeighbor(n GraphNeighbor) Relation + type Reranker interface + Rerank func(ctx context.Context, objects []RichObject) ([]RichObject, error) + type ResultSet struct + CreatedAt time.Time + ID uuid.UUID + ObjectIDs []uuid.UUID + Offset int + Relations map[uuid.UUID]Relation + type ResultSetStore interface + Get func(ctx context.Context, id uuid.UUID) (ResultSet, error) + Put func(ctx context.Context, set ResultSet) error + type RichObject struct + Content string + ContentType string + CreatedAt time.Time + Evidence []Evidence + ID uuid.UUID + Kind string + ParentID *uuid.UUID + Position *int + Properties map[string]any + Relation *Relation + Score *float64 + Summary string + Title string + UpdatedAt time.Time + func RichFromObject(o Object, includeContent bool) RichObject + type SchemaResult struct + FilterUsage FilterUsage + Kinds []ObjectKindInfo + type Scope struct + Namespace *uuid.UUID + type ScoredID struct + Content string + ID uuid.UUID + ParentID *uuid.UUID + Position *int + Score float64 + Title string + UpdatedAt time.Time + type SearchContext struct + func NewSearchContext() *SearchContext + func (c *SearchContext) ClearNamespace() + func (c *SearchContext) Export() ([]byte, error) + func (c *SearchContext) Get(_ context.Context, id uuid.UUID) (ResultSet, error) + func (c *SearchContext) Namespace() (uuid.UUID, bool) + func (c *SearchContext) Put(_ context.Context, set ResultSet) error + func (c *SearchContext) Restore(raw []byte) error + func (c *SearchContext) Scope() Scope + func (c *SearchContext) SetNamespace(id uuid.UUID) + type SearchPage struct + HasMore bool + Objects []RichObject + ResultSetID uuid.UUID + type SearchRequest struct + Filters Filters + Limit int + Query string + ScopeIDs []uuid.UUID + type Store interface + type WriteKinds struct + Discovery string + Fact string + Memory string