brainresearch

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SynthesisSchemaVersion  = "research_synthesis.v1"
	SynthesisPromptVersion  = "brain-research-synthesis-v3"
	DefaultMaxEvidenceChars = 24000
)
View Source
const (
	SchemaVersion = "research_pack.v1"
)

Variables

View Source
var ErrSynthesisUnavailable = errors.New("synthesis model is not configured")

Functions

func EvidenceMatchesAnyProtectedAnchor added in v0.3.0

func EvidenceMatchesAnyProtectedAnchor(row ask.Evidence, anchors []ProtectedAnchor) bool

func EvidenceMatchesProtectedAnchor added in v0.3.0

func EvidenceMatchesProtectedAnchor(row ask.Evidence, anchor ProtectedAnchor) bool

func HasCurrentProtectedAnchor added in v0.3.0

func HasCurrentProtectedAnchor(raw string) bool

func MergeRetryPack added in v0.3.0

func MergeRetryPack(initial Pack, retry Pack, opts MergeRetryOptions) (Pack, MergeRetryDecision)

Types

type AnchorResolver added in v0.3.0

type AnchorResolver interface {
	ResolveAnchors(ctx context.Context, anchors []ProtectedAnchor) ([]ProtectedAnchor, error)
}

type AnchorSynthesisAnchorStatus added in v0.3.0

type AnchorSynthesisAnchorStatus struct {
	Anchor                     string   `json:"anchor"`
	SupportedSourceKeys        []string `json:"supported_source_keys,omitempty"`
	CitationSourceKeys         []string `json:"citation_source_keys,omitempty"`
	DroppedSourceKeys          []string `json:"dropped_source_keys,omitempty"`
	PartiallyTrimmedSourceKeys []string `json:"partially_trimmed_source_keys,omitempty"`
	Reasons                    []string `json:"reasons,omitempty"`
}

type AnchorSynthesisContextStatus added in v0.3.0

type AnchorSynthesisContextStatus struct {
	Anchors []AnchorSynthesisAnchorStatus `json:"anchors,omitempty"`
}

type AttemptPlannerInputObserver added in v0.3.0

type AttemptPlannerInputObserver interface {
	PlannerInputAttempt(attempt string, input string)
}

type AttemptPlannerOutputObserver added in v0.3.0

type AttemptPlannerOutputObserver interface {
	PlannerOutputAttempt(attempt string, output string)
}

type Bucket

type Bucket struct {
	Key   string `json:"key"`
	Count int    `json:"count"`
}

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(cfg config.Config, st *store.Store) *Builder

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, opts Options) (Pack, error)

type Citation

type Citation struct {
	SourceKey string `json:"source_key"`
	Title     string `json:"title,omitempty"`
	URL       string `json:"url,omitempty"`
	NotePath  string `json:"note_path,omitempty"`
	Kind      string `json:"kind,omitempty"`
}

type Coverage

type Coverage struct {
	EvidenceCount     int      `json:"evidence_count"`
	ByKind            []Bucket `json:"by_kind"`
	BySourceType      []Bucket `json:"by_source_type"`
	TopUserTags       []Bucket `json:"top_user_tags,omitempty"`
	ExactTagMatches   []Bucket `json:"exact_tag_matches,omitempty"`
	ItemTextMatches   int      `json:"item_text_matches,omitempty"`
	SourceTextMatches int      `json:"source_text_matches,omitempty"`
	TopicNodeCount    int      `json:"topic_node_count,omitempty"`
	TopicEdgeCount    int      `json:"topic_edge_count,omitempty"`
	DisplayedLimit    int      `json:"displayed_limit"`
	RelatedLimit      int      `json:"related_limit,omitempty"`
	RecallNote        string   `json:"recall_note,omitempty"`
}

type MergeRetryDecision added in v0.3.0

type MergeRetryDecision struct {
	PreservedInitialSourceKeys []string `json:"preserved_initial_source_keys,omitempty"`
	AcceptedRetrySourceKeys    []string `json:"accepted_retry_source_keys,omitempty"`
	RejectedRetrySourceKeys    []string `json:"rejected_retry_source_keys,omitempty"`
	FinalSourceKeys            []string `json:"final_source_keys,omitempty"`
	Reason                     string   `json:"reason,omitempty"`
}

type MergeRetryOptions added in v0.3.0

type MergeRetryOptions struct {
	MissingConcepts []string
	RetryAction     string
	RetryQuestion   string
}

type Observer added in v0.2.12

type Observer interface {
	Event(name string, data map[string]interface{})
	PlannerInput(input string)
	PlannerOutput(output string)
}

type Options

type Options struct {
	Question          string
	RawQuestion       string
	Topic             string
	Limit             int
	SourceTypes       []string
	IncludeRelated    bool
	RelatedLimit      int
	SeedLimit         int
	IncludeTopic      *bool
	MaxCharsPerDoc    int
	PlannerModel      string
	PlannerTimeout    time.Duration
	PlannerBinary     string
	UseModelPlanner   bool
	DisablePlanner    bool
	UseSemantic       bool
	DisableSemantic   bool
	ContinuityAnchors []ProtectedAnchor
	Attempt           string
	AnchorResolver    AnchorResolver
	Observer          Observer
}

type Pack

type Pack struct {
	SchemaVersion    string            `json:"schema_version"`
	Question         string            `json:"question"`
	Mode             string            `json:"mode"`
	QueryPlan        QueryPlan         `json:"query_plan"`
	Coverage         Coverage          `json:"coverage"`
	Topic            string            `json:"topic,omitempty"`
	UsedTopicBrief   bool              `json:"used_topic_brief"`
	Evidence         []ask.Evidence    `json:"evidence"`
	ExactTagEvidence []ask.Evidence    `json:"exact_tag_evidence,omitempty"`
	TopicBrief       *TopicBrief       `json:"topic_brief,omitempty"`
	NextSteps        []SuggestedAction `json:"next_steps,omitempty"`
}

func Build

func Build(ctx context.Context, cfg config.Config, st *store.Store, opts Options) (Pack, error)

type PreparedSynthesis

type PreparedSynthesis struct {
	SchemaVersion string                       `json:"schema_version"`
	Question      string                       `json:"question"`
	Model         string                       `json:"model"`
	PromptVersion string                       `json:"prompt_version"`
	Input         string                       `json:"-"`
	Truncation    TruncationMetadata           `json:"truncation"`
	Citations     []Citation                   `json:"citations,omitempty"`
	AnchorContext AnchorSynthesisContextStatus `json:"anchor_context,omitempty"`
	Warnings      []string                     `json:"answer_warnings,omitempty"`
	Status        string                       `json:"answer_status"`
}

func PrepareSynthesis

func PrepareSynthesis(cfg config.Config, opts SynthesisOptions) (PreparedSynthesis, error)

type ProtectedAnchor added in v0.3.0

type ProtectedAnchor struct {
	Kind           string   `json:"kind"`
	Relation       string   `json:"relation,omitempty"`
	Raw            string   `json:"raw"`
	Canonical      string   `json:"canonical,omitempty"`
	ResolvedID     string   `json:"resolved_id,omitempty"`
	Source         string   `json:"source,omitempty"`
	Confidence     string   `json:"confidence,omitempty"`
	ExactTerms     []string `json:"exact_terms,omitempty"`
	PhraseTerms    []string `json:"phrase_terms,omitempty"`
	ExpansionTerms []string `json:"expansion_terms,omitempty"`
}

type QueryConcept

type QueryConcept struct {
	Key       string   `json:"key"`
	Preferred string   `json:"preferred,omitempty"`
	Terms     []string `json:"terms"`
	Required  bool     `json:"required"`
	Role      string   `json:"role,omitempty"`
}

type QueryPlan

type QueryPlan struct {
	TextQuery         string                    `json:"text_query"`
	QueryFamily       string                    `json:"query_family,omitempty"`
	QueryTerms        []string                  `json:"query_terms"`
	TagQueries        []string                  `json:"tag_queries"`
	QueryVariants     []QueryVariant            `json:"query_variants,omitempty"`
	Concepts          []QueryConcept            `json:"concepts,omitempty"`
	ProtectedAnchors  []ProtectedAnchor         `json:"protected_anchors,omitempty"`
	Planner           string                    `json:"planner,omitempty"`
	PlannerModel      string                    `json:"planner_model,omitempty"`
	PlannerError      string                    `json:"planner_error,omitempty"`
	SourceTypes       []string                  `json:"source_types,omitempty"`
	RetrievalLanes    []retrieval.RetrievalLane `json:"retrieval_lanes,omitempty"`
	Limit             int                       `json:"limit"`
	MaxCharsPerDoc    int                       `json:"max_chars_per_doc"`
	IncludeRelated    bool                      `json:"include_related"`
	RelatedLimit      int                       `json:"related_limit,omitempty"`
	Topic             string                    `json:"topic,omitempty"`
	TopicSource       string                    `json:"topic_source,omitempty"`
	IncludeTopicBrief bool                      `json:"include_topic_brief"`
}

type QueryVariant

type QueryVariant struct {
	Query  string `json:"query"`
	Reason string `json:"reason,omitempty"`
}

type SuggestedAction

type SuggestedAction struct {
	Action string                 `json:"action"`
	Label  string                 `json:"label"`
	Reason string                 `json:"reason,omitempty"`
	Params map[string]interface{} `json:"params,omitempty"`
}

type SynthesisOptions

type SynthesisOptions struct {
	Question         string
	Pack             Pack
	Model            string
	CLI              string
	Length           string
	Timeout          time.Duration
	MaxEvidenceChars int
	Binary           string
}

type SynthesisResult

type SynthesisResult struct {
	SchemaVersion string                       `json:"schema_version"`
	Question      string                       `json:"question"`
	Answer        string                       `json:"answer"`
	AnswerStatus  string                       `json:"answer_status"`
	Warnings      []string                     `json:"answer_warnings,omitempty"`
	Truncation    TruncationMetadata           `json:"truncation"`
	Citations     []Citation                   `json:"citations,omitempty"`
	AnchorContext AnchorSynthesisContextStatus `json:"anchor_context,omitempty"`
	PromptVersion string                       `json:"prompt_version"`
	Model         string                       `json:"model"`
	Tool          string                       `json:"tool"`
	ToolVersion   string                       `json:"tool_version"`
}

func RunPreparedSynthesis

func RunPreparedSynthesis(ctx context.Context, cfg config.Config, prepared PreparedSynthesis, opts SynthesisOptions) (SynthesisResult, error)

func Synthesize

func Synthesize(ctx context.Context, cfg config.Config, opts SynthesisOptions) (SynthesisResult, error)

type TopicBrief

type TopicBrief struct {
	Topic        string                `json:"topic"`
	SourceTypes  []string              `json:"source_types,omitempty"`
	SeedLimit    int                   `json:"seed_limit"`
	RelatedLimit int                   `json:"related_limit"`
	Summary      string                `json:"summary"`
	Pivots       topics.TopicPivots    `json:"pivots,omitempty"`
	Entities     []topics.TopicEntity  `json:"entities,omitempty"`
	Nodes        []topics.TopicMapNode `json:"nodes"`
	Edges        []topics.TopicMapEdge `json:"edges"`
}

type TruncationMetadata

type TruncationMetadata struct {
	EvidenceBudgetChars       int      `json:"evidence_budget_chars"`
	EvidenceCharsUsed         int      `json:"evidence_chars_used"`
	DroppedSourceKeys         []string `json:"dropped_source_keys,omitempty"`
	PartiallyTrimmedSourceKey string   `json:"partially_trimmed_source_key,omitempty"`
}

Jump to

Keyboard shortcuts

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