Documentation
¶
Index ¶
- func ContentSimilarity(a, b string) float64
- func JaccardSimilarity(a, b string) float64
- func Tokenize(text string) map[string]bool
- type DiffMatch
- type DiffOptions
- type DiffResult
- type DiffSuggestion
- type EmbeddedItem
- type Intent
- type IntentWeights
- type RecallMeta
- type RecallResponse
- type RecallResult
- type ScoredInsight
- type SignalScores
- type TraversalParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentSimilarity ¶
ContentSimilarity computes bidirectional token overlap between two texts. Returns max(overlap_a_to_b, overlap_b_to_a) for a symmetric measure.
func JaccardSimilarity ¶
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).
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 ¶
EmbeddedItem pairs an insight ID with its deserialized embedding vector.
type Intent ¶
type Intent string
Intent represents the detected query intent.
func DetectIntent ¶
DetectIntent analyzes a query string and returns the detected intent.
func IntentFromString ¶
IntentFromString parses a user-provided intent string into an Intent value.
type IntentWeights ¶
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 ¶
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).