search

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 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

Overview

Package search keeps an in-memory BM25 index (bleve) over a vault snapshot and a FAQ fast path for question-style lookups.

Index

Constants

View Source
const (
	Threshold   = 0.6  // minimum Dice overlap between query and FAQ question terms
	MinCoverage = 0.75 // minimum share of the query's terms found in the FAQ question
)

Thresholds for a confident FAQ answer (see vault/faq/how-does-kb-ask-decide.md).

Variables

This section is empty.

Functions

func Facets

func Facets(s *vault.Snapshot) (types, tags map[string]int)

Facets summarises types and tags in the snapshot.

func HasTerms added in v0.2.0

func HasTerms(s string) bool

HasTerms reports whether s has any content terms once stop words are dropped.

func IsFAQ

func IsFAQ(c *okf.Concept) bool

IsFAQ reports whether a concept is a question/answer entry.

func Normalize added in v0.2.0

func Normalize(s string) string

Normalize lower-cases s and keeps only letters and digits, single-spaced: the form kb_ask compares FAQ titles and aliases in.

func Similarity added in v0.2.0

func Similarity(a, b string) float64

Similarity is the Dice overlap of the analysed terms of a and b (0..1), the measure kb_ask matches questions with.

func Snippet

func Snippet(body, q string, max int) string

Snippet returns the line of body that best matches the query terms.

func TopKeys

func TopKeys(m map[string]int) []string

TopKeys returns map keys sorted by count desc then name.

Types

type Answer

type Answer struct {
	Confident  bool    `json:"confident"`
	Confidence float64 `json:"confidence"`
	Path       string  `json:"path,omitempty"`
	Question   string  `json:"matched_question,omitempty"`
	Answer     string  `json:"answer,omitempty"`
	Related    []Hit   `json:"related,omitempty"`
}

Answer is the result of the FAQ fast path.

type Hit

type Hit struct {
	Path        string   `json:"path"`
	Title       string   `json:"title"`
	Type        string   `json:"type"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Tickets     []string `json:"tickets,omitempty"`
	Snippet     string   `json:"snippet,omitempty"`
	Score       float64  `json:"score"`
}

Hit is a compact search result.

type Index

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

Index is a swappable in-memory search index.

func Build

func Build(s *vault.Snapshot) (*Index, error)

Build creates an index over a snapshot.

func (*Index) Ask

func (ix *Index) Ask(question string) (*Answer, error)

Ask answers a question from FAQ entries when it is confident; otherwise it returns the best search hits so the agent can read further.

Confident means: the normalised question equals an FAQ title or alias, or the Dice overlap of analysed terms is >= Threshold AND the FAQ question covers >= MinCoverage of the query's terms. Coverage stops a one-keyword FAQ ("What is okvault?") from capturing "what is the okvault license?".

func (*Index) Rebuild

func (ix *Index) Rebuild(s *vault.Snapshot) error

Rebuild replaces the index contents with a new snapshot.

func (*Index) Search

func (ix *Index) Search(q Query) ([]Hit, error)

Search runs a BM25 query with optional type/tag/dir filters.

type Query

type Query struct {
	Text           string
	Type           string
	Tags           []string
	Dir            string
	Ticket         string // only notes linked to or mentioning this ticket key
	Owner          string // only notes owned by this person or group
	Limit          int
	WithDeprecated bool
	// NearTickets ranks notes about these ticket keys, and notes one link
	// from them, a little higher. Ticket keys in Text count too.
	NearTickets []string
}

Query is a search request.

Jump to

Keyboard shortcuts

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