Help us shape the future of Go! Take the 2026 Go Developer Survey

search

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentSimilarity

func ContentSimilarity(a, b string) float64

ContentSimilarity computes bidirectional token overlap between two texts. Returns max(overlap_a_to_b, overlap_b_to_a) for a symmetric measure.

func JaccardSimilarity

func JaccardSimilarity(a, b string) float64

JaccardSimilarity computes token-set Jaccard similarity: |A∩B| / |A∪B|. Used for deduplication — stricter than ContentSimilarity because it penalises texts that share domain vocabulary but differ in the specific facts they state (e.g. same species name, different location).

func Tokenize

func Tokenize(text string) map[string]bool

Tokenize splits text into lowercase tokens with stopword filtering. English words split on whitespace/punctuation; CJK characters generate character bigrams. Common English stopwords are excluded.

Types

type DiffMatch

type DiffMatch struct {
	ID               string         `json:"id"`
	Content          string         `json:"content"`
	TokenSimilarity  float64        `json:"token_similarity"`
	CosineSimilarity float64        `json:"cosine_similarity,omitempty"`
	Similarity       float64        `json:"similarity"`
	Suggestion       DiffSuggestion `json:"suggestion"`
}

DiffMatch represents one existing insight compared against the new content.

type DiffOptions

type DiffOptions struct {
	Limit         int            // max candidates to compare (default 5)
	NewEmbedding  []float64      // pre-computed embedding for new content (optional)
	ExistingEmbed []EmbeddedItem // pre-loaded embeddings (optional, avoids DB call)
}

DiffOptions controls diff behavior.

type DiffResult

type DiffResult struct {
	Suggestion DiffSuggestion `json:"suggestion"`
	Matches    []DiffMatch    `json:"matches"`
}

DiffResult is the output of a diff check.

func Diff

func Diff(insights []*model.Insight, newContent string, opts DiffOptions) DiffResult

Diff compares new content against existing insights and returns a suggestion. It uses token overlap as the baseline, enhanced with cosine similarity when embeddings are available.

type DiffSuggestion

type DiffSuggestion string

DiffSuggestion classifies how a new fact relates to existing content.

const (
	DiffAdd       DiffSuggestion = "ADD"
	DiffDuplicate DiffSuggestion = "DUPLICATE"
	DiffConflict  DiffSuggestion = "CONFLICT"
	DiffUpdate    DiffSuggestion = "UPDATE"
)

type EmbeddedItem

type EmbeddedItem struct {
	ID        string
	Embedding []float64
}

EmbeddedItem pairs an insight ID with its deserialized embedding vector.

type Intent

type Intent string

Intent represents the detected query intent.

const (
	IntentWhy     Intent = "WHY"
	IntentWhen    Intent = "WHEN"
	IntentEntity  Intent = "ENTITY"
	IntentGeneral Intent = "GENERAL"
)

func DetectIntent

func DetectIntent(query string) Intent

DetectIntent analyzes a query string and returns the detected intent.

func IntentFromString

func IntentFromString(s string) (Intent, error)

IntentFromString parses a user-provided intent string into an Intent value.

type IntentWeights

type IntentWeights map[model.EdgeType]float64

IntentWeights maps intent to edge type weights for traversal.

func GetWeights

func GetWeights(intent Intent) IntentWeights

GetWeights returns the edge type weights for the given intent.

type RecallMeta

type RecallMeta struct {
	Intent       Intent `json:"intent"`
	IntentSource string `json:"intent_source"` // "auto" or "override"
	AnchorCount  int    `json:"anchor_count"`
	Traversed    int    `json:"traversed"`
	Hint         string `json:"hint,omitempty"`
}

RecallMeta holds metadata about a smart recall operation.

type RecallResponse

type RecallResponse struct {
	Results []RecallResult `json:"results"`
	Meta    RecallMeta     `json:"meta"`
}

RecallResponse wraps recall results with metadata.

func IntentAwareRecall

func IntentAwareRecall(db *store.DB, query string, queryVec []float64,
	queryEntities []string, limit int, intentOverride *Intent) (RecallResponse, error)

IntentAwareRecall performs MAGMA-aligned intent-aware retrieval: 1. Detect query intent (or use override) 2. Multi-signal anchor selection via RRF (keyword + vector + time) 3. Beam search from anchors with additive transition scoring 4. Multi-factor reranking (keyword + entity + similarity + graph) 5. WHY intent → causal topological sort 6. Sparse hint detection

type RecallResult

type RecallResult struct {
	Insight *model.Insight `json:"insight"`
	Score   float64        `json:"score"`
	Intent  Intent         `json:"intent"`
	Via     string         `json:"via,omitempty"`
	Signals SignalScores   `json:"signals"`
}

RecallResult represents a recalled insight with its relevance score.

type ScoredInsight

type ScoredInsight struct {
	Insight *model.Insight `json:"insight"`
	Score   float64        `json:"score"`
}

ScoredInsight pairs an insight with a relevance score.

func KeywordSearch

func KeywordSearch(insights []*model.Insight, query string, limit int) []ScoredInsight

KeywordSearch scores insights by token overlap with the query. Score = |intersection(query_tokens, content_tokens)| / |query_tokens|

type SignalScores

type SignalScores struct {
	Keyword    float64 `json:"keyword"`
	Entity     float64 `json:"entity"`
	Similarity float64 `json:"similarity"`
	Graph      float64 `json:"graph"`
}

SignalScores holds the individual reranking signal scores for a result.

type TraversalParams

type TraversalParams struct {
	BeamWidth  int // candidates retained per level
	MaxDepth   int // max traversal hops
	MaxVisited int // total node budget
}

TraversalParams holds per-intent adaptive beam search parameters (MAGMA §4.2).

Jump to

Keyboard shortcuts

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